头像是否使用https

This commit is contained in:
xing 2023-01-30 20:48:30 +08:00
parent 8af7556511
commit ae0a4f0731
2 changed files with 19 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import (
"github.com/fthvgb1/wp-go/helper/slice"
"github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/gin-gonic/gin"
"net/url"
"strconv"
"strings"
)
@ -13,6 +14,7 @@ type CommentHandler struct {
comments []*Comments
maxDepth int
depth int
isTls bool
i CommentHtml
}
@ -23,16 +25,25 @@ type Comments struct {
type CommentHtml interface {
Sort(i, j *Comments) bool
FormatLi(c *gin.Context, m models.Comments, depth int, eo, parent string) string
FormatLi(c *gin.Context, m models.Comments, depth int, isTls bool, eo, parent string) string
}
func FormatComments(c *gin.Context, i CommentHtml, comments []models.Comments, maxDepth int) string {
tree := treeComments(comments)
u := c.Request.Header.Get("Referer")
var isTls bool
if u != "" {
uu, _ := url.Parse(u)
if uu.Scheme == "https" {
isTls = true
}
}
h := CommentHandler{
Context: c,
comments: tree,
maxDepth: maxDepth,
depth: 1,
isTls: isTls,
i: i,
}
return h.formatComment(h.comments, true)
@ -55,7 +66,7 @@ func (d CommentHandler) formatComment(comments []*Comments, isTop bool) (html st
parent = "parent"
fl = true
}
s.WriteString(d.i.FormatLi(d.Context, comment.Comments, d.depth, eo, parent))
s.WriteString(d.i.FormatLi(d.Context, comment.Comments, d.depth, d.isTls, eo, parent))
if fl {
d.depth++
s.WriteString(`<ol class="children">`)
@ -130,8 +141,8 @@ func (c CommonCommentFormat) Sort(i, j *Comments) bool {
return i.CommentDate.UnixNano() < j.CommentDate.UnixNano()
}
func (c CommonCommentFormat) FormatLi(ctx *gin.Context, m models.Comments, depth int, eo, parent string) string {
return FormatLi(CommonLi(), ctx, m, depth, eo, parent)
func (c CommonCommentFormat) FormatLi(ctx *gin.Context, m models.Comments, depth int, isTls bool, eo, parent string) string {
return FormatLi(CommonLi(), ctx, m, depth, isTls, eo, parent)
}
var li = `
@ -171,11 +182,11 @@ var li = `
`
func FormatLi(li string, c *gin.Context, comments models.Comments, depth int, eo, parent string) string {
func FormatLi(li string, c *gin.Context, comments models.Comments, depth int, isTls bool, eo, parent string) string {
for k, v := range map[string]string{
"{{CommentId}}": strconv.FormatUint(comments.CommentId, 10),
"{{Depth}}": strconv.Itoa(depth),
"{{Gravatar}}": Gravatar(comments.CommentAuthorEmail, c.Request.TLS != nil),
"{{Gravatar}}": Gravatar(comments.CommentAuthorEmail, isTls),
"{{CommentAuthorUrl}}": comments.CommentAuthorUrl,
"{{CommentAuthor}}": comments.CommentAuthor,
"{{PostId}}": strconv.FormatUint(comments.CommentPostId, 10),

View File

@ -110,7 +110,7 @@ type comment struct {
plugins.CommonCommentFormat
}
func (c comment) FormatLi(ctx *gin.Context, m models.Comments, depth int, eo, parent string) string {
func (c comment) FormatLi(ctx *gin.Context, m models.Comments, depth int, isTls bool, eo, parent string) string {
templ := plugins.CommonLi()
templ = strings.ReplaceAll(templ, `<a rel="nofollow" class="comment-reply-link"
href="/p/{{PostId}}?replytocom={{CommentId}}#respond" data-commentid="{{CommentId}}" data-postid="{{PostId}}"
@ -121,7 +121,7 @@ func (c comment) FormatLi(ctx *gin.Context, m models.Comments, depth int, eo, pa
data-belowelement="div-comment-{{CommentId}}" data-respondelement="respond"
data-replyto="回复给{{CommentAuthor}}"
aria-label="回复给{{CommentAuthor}}"><svg class="icon icon-mail-reply" aria-hidden="true" role="img"> <use href="#icon-mail-reply" xlink:href="#icon-mail-reply"></use> </svg>回复</a>`)
return plugins.FormatLi(templ, ctx, m, depth, eo, parent)
return plugins.FormatLi(templ, ctx, m, depth, isTls, eo, parent)
}
func postThumbnail(posts []models.Posts, scene int) []models.Posts {