列表页评论

This commit is contained in:
xing 2022-09-19 21:31:46 +08:00
parent 3636c3952a
commit 75f6afcddc
3 changed files with 93 additions and 91 deletions

View File

@ -50,22 +50,20 @@ func Detail(c *gin.Context) {
} }
} }
pw := sessions.Default(c).Get("post_password") pw := sessions.Default(c).Get("post_password")
showComment := true showComment := false
if post.CommentCount > 0 || post.CommentStatus == "open" {
showComment = true
}
common.PasswordProjectTitle(&post) common.PasswordProjectTitle(&post)
if post.PostPassword != "" && pw != post.PostPassword { if post.PostPassword != "" && pw != post.PostPassword {
common.PasswdProjectContent(&post) common.PasswdProjectContent(&post)
showComment = false showComment = false
} }
canComment := false
if post.CommentStatus == "open" {
canComment = true
}
prev, next, err := common.GetContextPost(post.Id, post.PostDate) prev, next, err := common.GetContextPost(post.Id, post.PostDate)
h["title"] = fmt.Sprintf("%s-%s", post.PostTitle, models.Options["blogname"]) h["title"] = fmt.Sprintf("%s-%s", post.PostTitle, models.Options["blogname"])
h["post"] = post h["post"] = post
h["comment"] = showComment h["showComment"] = showComment
h["canComment"] = canComment
h["prev"] = prev h["prev"] = prev
h["next"] = next h["next"] = next
} }

View File

@ -40,12 +40,10 @@
</article><!-- #post-1 --> </article><!-- #post-1 -->
{{ if .showComment}}
<div id="comments" class="comments-area"> <div id="comments" class="comments-area">
{{ if gt .post.CommentCount 0}}
<h2 class="comments-title"> <h2 class="comments-title">《{{.post.PostTitle}}》上有{{.post.CommentCount}}条评论 </h2>
《{{.post.PostTitle}}》上有1条评论 </h2>
<ol class="comment-list"> <ol class="comment-list">
<li id="comment-1" class="comment even thread-even depth-1"> <li id="comment-1" class="comment even thread-even depth-1">
<article id="div-comment-1" class="comment-body"> <article id="div-comment-1" class="comment-body">
@ -83,8 +81,8 @@
</article><!-- .comment-body --> </article><!-- .comment-body -->
</li><!-- #comment-## --> </li><!-- #comment-## -->
</ol><!-- .comment-list --> </ol><!-- .comment-list -->
{{end}}
{{if .canComment}} {{if eq .post.CommentStatus "open"}}
<div id="respond" class="comment-respond"> <div id="respond" class="comment-respond">
<h3 id="reply-title" class="comment-reply-title">发表回复 <h3 id="reply-title" class="comment-reply-title">发表回复
<small> <small>
@ -122,8 +120,12 @@
</p> </p>
</form> </form>
</div><!-- #respond --> </div><!-- #respond -->
{{else}}
<p class="no-comments">评论已关闭。</p>
{{end}} {{end}}
</div><!-- .comments-area --> </div><!-- .comments-area -->
{{end}}
<nav class="navigation post-navigation" aria-label="文章"> <nav class="navigation post-navigation" aria-label="文章">
<h2 class="screen-reader-text">文章导航</h2> <h2 class="screen-reader-text">文章导航</h2>

View File

@ -49,12 +49,14 @@
{{$v.TagsHtml|unescaped}} {{$v.TagsHtml|unescaped}}
</span> </span>
{{end}} {{end}}
{{if gt $v.CommentCount 0}}
<span class="comments-link"> <span class="comments-link">
<a href="/p/1#comments"> <a href="/p/{{$v.Id}}#comments">
<span class="screen-reader-text">{{$v.PostTitle}}</span>有1条评论 <span class="screen-reader-text">{{$v.PostTitle}}</span>有{{$v.CommentCount}}条评论
</a> </a>
</span> </span>
{{end}}
</footer><!-- .entry-footer --> </footer><!-- .entry-footer -->
</article><!-- #post-{{$v.Id}} --> </article><!-- #post-{{$v.Id}} -->