diff --git a/controllers/blog.go b/controllers/blog.go index 048cc35..7f2037f 100644 --- a/controllers/blog.go +++ b/controllers/blog.go @@ -121,13 +121,10 @@ func PostSearch(c *gin.Context) { Posts["url"] = post.Url() Posts["tags"] = post.GetTagsArray() Posts["title"] = post.Title - Posts["content"] = models.GetContent(int(post.ID)) + Posts["content"] = post.Content ret = append(ret,Posts) - } - c.JSON(http.StatusOK,ret) - } func PostPage(c *gin.Context) { diff --git a/controllers/comment.go b/controllers/comment.go index 50f6eef..a01a39e 100644 --- a/controllers/comment.go +++ b/controllers/comment.go @@ -22,11 +22,11 @@ func CreateComment(c *gin.Context) { comment := models.Comment{ GitHubID:gid.(int64), PostID:postID, + Content:content, RefID:0, } _ = models.CommentCreatAndGetID(&comment) - models.SetCommentContent(int64(comment.ID), content) - commentHTML,_ := utils.RenderSingleCommnet(&comment) + commentHTML,_ := utils.RenderSingleComment(&comment) c.JSON(http.StatusOK,gin.H{ "r":0, "html":commentHTML, @@ -77,13 +77,6 @@ func Comments(c *gin.Context) { "r":0, "html":commentsHTML, }) - - //c.JSON(http.StatusOK,gin.H{ - // "r": 0, - // "comments":comments, - // "githubuser":gitHubUser, - // "post":post, - //}) } func CommentMarkdown(c *gin.Context) { diff --git a/controllers/post.go b/controllers/post.go index f446855..44cc1f5 100644 --- a/controllers/post.go +++ b/controllers/post.go @@ -100,13 +100,11 @@ func GetEditPost(c *gin.Context) { if post == nil { c.Redirect(http.StatusMovedPermanently,"/admin/users") } - content := models.GetContent(int(postID)) c.HTML(http.StatusOK, "admin/post.html",gin.H{ "post":post, "users":users, "allTags":allTags, "postTags":postTags, - "content": content, }) } @@ -134,11 +132,11 @@ func AddPost(c *gin.Context){ Slug:slug, Summary:summary, AuthorID:int(authorID), + Content:content, CanComment:canComment, Published:publish, } _ = models.PostCreatAndGetID(post) - models.SetContent(int(post.ID), content) models.UpdateMultiTags([]string{}, tags, int(post.ID)) posts, _ := models.ListPosts() for _, post := range posts { @@ -169,12 +167,12 @@ func UpdatePost(c *gin.Context) { Slug:slug, Summary:summary, AuthorID:int(authorID), + Content:content, CanComment:canComment, Published:publish, } post.ID = uint64(pID) post.Update() - models.SetContent(int(pID), content) originPostTags,_ := models.ListTagByPostID(post.ID) originPostTagNames := models.GetTagNames(originPostTags) models.UpdateMultiTags(originPostTagNames, tags, int(post.ID)) @@ -217,7 +215,7 @@ func getPost(c *gin.Context, isPublish bool) { } tags ,_ := models.ListTagByPostID(post.ID) post.Tags = tags - content := models.GetContent(int(postID)) + content := post.Content comments, _ := models.ListCommentsByPostID(int(postID)) gitHubUser, _ := c.Get(models.CONTEXT_GIT_USER_KEY) policy := bluemonday.UGCPolicy() diff --git a/models/comment.go b/models/comment.go index 436f062..e26896f 100644 --- a/models/comment.go +++ b/models/comment.go @@ -1,7 +1,6 @@ package models import ( - "fmt" "github.com/microcosm-cc/bluemonday" "github.com/russross/blackfriday" "html/template" @@ -13,6 +12,7 @@ type Comment struct { BaseModel GitHubID int64 PostID int64 + Content string `gorm:"type:longtext"` RefID int64 } @@ -24,7 +24,6 @@ func (comment *Comment) Insert()error{ func ListCommentsByPostID(postid int)([]*Comment, error){ var comments []*Comment err := DB.Model(&Comment{}).Order("id desc").Find(&comments,"post_id=?",postid).Error - fmt.Println(comments) return comments,err } @@ -33,9 +32,9 @@ func (comment *Comment) GitUser() *GitHubUser{ return gitUser } -func (comment *Comment) CommentHTML(content string) template.HTML { +func (comment *Comment) CommentHTML() template.HTML { policy := bluemonday.UGCPolicy() - unsafe := blackfriday.MarkdownCommon([]byte(content)) + unsafe := blackfriday.MarkdownCommon([]byte(comment.Content)) contentHtml:=template.HTML(string(policy.SanitizeBytes(unsafe))) return contentHtml } diff --git a/models/post.go b/models/post.go index 7d45ae2..03e6884 100644 --- a/models/post.go +++ b/models/post.go @@ -19,6 +19,7 @@ type Post struct { AuthorID int Slug string Summary string + Content string `gorm:"type:longtext"` CanComment bool Published bool Tags []*Tag `gorm:"-"` @@ -52,9 +53,9 @@ func (post *Post) GetUserName(userID int)string { } func (post *Post) Excerpt() template.HTML { - content :=GetContent(int(post.ID)) + //content :=GetContent(int(post.ID)) policy := bluemonday.StrictPolicy() //remove all html tags - sanitized := policy.Sanitize(string(blackfriday.MarkdownCommon([]byte(content)))) + sanitized := policy.Sanitize(string(blackfriday.MarkdownCommon([]byte(post.Content)))) runes := []rune(sanitized) if len(runes) > 300 { sanitized = string(runes[:300]) diff --git a/request.token b/request.token index d85c3f5..76a4c7e 100644 --- a/request.token +++ b/request.token @@ -1 +1 @@ -{"AccessToken":"14734960e993c5a7f70fa5f5a1f2dcd4d9aade9e","RefreshToken":"","Expiry":"0001-01-01T00:00:00Z","Extra":null} +{"AccessToken":"07f3f0fad19f0c1bccec6c3d7864d44846b4e02a","RefreshToken":"","Expiry":"0001-01-01T00:00:00Z","Extra":null} diff --git a/static/css/main.css b/static/css/main.css index 3af0044..8cae2d2 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -1246,7 +1246,7 @@ img { .post-container .toc-container .toc-article { display: block; position: fixed; - margin-left: -15px; + margin-left: 80px; width: 200px; top: 25%; z-index: 1; @@ -1335,7 +1335,7 @@ img { .post-container .toc-container .toc-article { display: block; position: fixed; - margin-left: -15px; + margin-left: 80px; width: 200px; top: 25%; z-index: 1; diff --git a/utils/template.go b/utils/template.go index 9ce40f0..37e48e9 100644 --- a/utils/template.go +++ b/utils/template.go @@ -60,7 +60,7 @@ func RenderAllComment(hh HH) (string,error) { return AllCommentHTML,nil } -func RenderSingleCommnet(comment *models.Comment)(string,error){ +func RenderSingleComment(comment *models.Comment)(string,error){ var ( commentHTML string err error diff --git a/utils/utils_test.go b/utils/utils_test.go index ac19555..1ef6498 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -1,10 +1,14 @@ package utils -import "testing" +import ( + "fmt" + "testing" +) func TestMd5(t *testing.T) { username := "admin" password := "123456" md5_res := Md5(username + password) - t.Log(md5_res) + fmt.Println(md5_res) + //t.Log(md5_res) } \ No newline at end of file diff --git a/views/admin/post.html b/views/admin/post.html index e0a2855..d095d22 100644 --- a/views/admin/post.html +++ b/views/admin/post.html @@ -42,7 +42,7 @@