commit
0c0fafedec
|
@ -79,3 +79,5 @@ port: 8082
|
||||||
theme: "twentyfifteen"
|
theme: "twentyfifteen"
|
||||||
# 文档排序默认升序还是降序
|
# 文档排序默认升序还是降序
|
||||||
postOrder: "desc"
|
postOrder: "desc"
|
||||||
|
# 上传的目录
|
||||||
|
uploadDir: ""
|
|
@ -44,13 +44,20 @@ func SetupRouter() (*gin.Engine, func()) {
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
f := static.Fs{FS: static.FsEx, Path: "wp-includes"}
|
f := static.Fs{FS: static.FsDir, Path: "wp-includes"}
|
||||||
r.StaticFileFS("/favicon.ico", "favicon.ico", http.FS(static.FsEx))
|
r.StaticFileFS("/favicon.ico", "favicon.ico", http.FS(static.FsDir))
|
||||||
r.StaticFS("/wp-includes", http.FS(f))
|
r.StaticFS("/wp-includes", http.FS(f))
|
||||||
r.StaticFS("/wp-content", http.FS(static.Fs{
|
r.StaticFS("/wp-content/plugins", http.FS(static.Fs{
|
||||||
FS: static.FsEx,
|
FS: static.FsDir,
|
||||||
Path: "wp-content",
|
Path: "wp-content/plugins",
|
||||||
}))
|
}))
|
||||||
|
r.StaticFS("/wp-content/themes", http.FS(static.Fs{
|
||||||
|
FS: static.FsDir,
|
||||||
|
Path: "wp-content/themes",
|
||||||
|
}))
|
||||||
|
if c.UploadDir != "" {
|
||||||
|
r.Static("/wp-content/uploads", c.UploadDir)
|
||||||
|
}
|
||||||
store := cookie.NewStore([]byte("secret"))
|
store := cookie.NewStore([]byte("secret"))
|
||||||
r.Use(sessions.Sessions("go-wp", store))
|
r.Use(sessions.Sessions("go-wp", store))
|
||||||
sl, slRload := middleware.SearchLimit(c.SingleIpSearchNum)
|
sl, slRload := middleware.SearchLimit(c.SingleIpSearchNum)
|
||||||
|
|
|
@ -40,6 +40,7 @@ type Config struct {
|
||||||
TrustServerNames []string `yaml:"trustServerNames"`
|
TrustServerNames []string `yaml:"trustServerNames"`
|
||||||
Theme string `yaml:"theme"`
|
Theme string `yaml:"theme"`
|
||||||
PostOrder string `yaml:"postOrder"`
|
PostOrder string `yaml:"postOrder"`
|
||||||
|
UploadDir string `yaml:"uploadDir"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Ssl struct {
|
type Ssl struct {
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"github.com/fthvgb1/wp-go/helper/slice"
|
"github.com/fthvgb1/wp-go/helper/slice"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
||||||
"github.com/fthvgb1/wp-go/internal/plugins"
|
"github.com/fthvgb1/wp-go/internal/plugins"
|
||||||
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
|
||||||
"github.com/fthvgb1/wp-go/model"
|
"github.com/fthvgb1/wp-go/model"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -44,7 +43,8 @@ func GetPostsByIds(ids ...any) (m map[uint64]models.Posts, err error) {
|
||||||
}
|
}
|
||||||
postsMap[post.Id] = v
|
postsMap[post.Id] = v
|
||||||
}
|
}
|
||||||
host, _ := wpconfig.Options.Load("siteurl")
|
//host, _ := wpconfig.Options.Load("siteurl")
|
||||||
|
host := ""
|
||||||
meta, _ := GetPostMetaByPostIds(ctx, id)
|
meta, _ := GetPostMetaByPostIds(ctx, id)
|
||||||
for k, pp := range postsMap {
|
for k, pp := range postsMap {
|
||||||
if len(pp.Categories) > 0 {
|
if len(pp.Categories) > 0 {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/fthvgb1/wp-go/helper/slice"
|
"github.com/fthvgb1/wp-go/helper/slice"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -13,6 +14,7 @@ type CommentHandler struct {
|
||||||
comments []*Comments
|
comments []*Comments
|
||||||
maxDepth int
|
maxDepth int
|
||||||
depth int
|
depth int
|
||||||
|
isTls bool
|
||||||
i CommentHtml
|
i CommentHtml
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,16 +25,25 @@ type Comments struct {
|
||||||
|
|
||||||
type CommentHtml interface {
|
type CommentHtml interface {
|
||||||
Sort(i, j *Comments) bool
|
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 {
|
func FormatComments(c *gin.Context, i CommentHtml, comments []models.Comments, maxDepth int) string {
|
||||||
tree := treeComments(comments)
|
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{
|
h := CommentHandler{
|
||||||
Context: c,
|
Context: c,
|
||||||
comments: tree,
|
comments: tree,
|
||||||
maxDepth: maxDepth,
|
maxDepth: maxDepth,
|
||||||
depth: 1,
|
depth: 1,
|
||||||
|
isTls: isTls,
|
||||||
i: i,
|
i: i,
|
||||||
}
|
}
|
||||||
return h.formatComment(h.comments, true)
|
return h.formatComment(h.comments, true)
|
||||||
|
@ -55,7 +66,7 @@ func (d CommentHandler) formatComment(comments []*Comments, isTop bool) (html st
|
||||||
parent = "parent"
|
parent = "parent"
|
||||||
fl = true
|
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 {
|
if fl {
|
||||||
d.depth++
|
d.depth++
|
||||||
s.WriteString(`<ol class="children">`)
|
s.WriteString(`<ol class="children">`)
|
||||||
|
@ -130,8 +141,8 @@ func (c CommonCommentFormat) Sort(i, j *Comments) bool {
|
||||||
return i.CommentDate.UnixNano() < j.CommentDate.UnixNano()
|
return i.CommentDate.UnixNano() < j.CommentDate.UnixNano()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c CommonCommentFormat) FormatLi(ctx *gin.Context, m models.Comments, depth int, eo, parent string) string {
|
func (c CommonCommentFormat) FormatLi(ctx *gin.Context, m models.Comments, depth int, isTls bool, eo, parent string) string {
|
||||||
return FormatLi(CommonLi(), ctx, m, depth, eo, parent)
|
return FormatLi(CommonLi(), ctx, m, depth, isTls, eo, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
var li = `
|
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{
|
for k, v := range map[string]string{
|
||||||
"{{CommentId}}": strconv.FormatUint(comments.CommentId, 10),
|
"{{CommentId}}": strconv.FormatUint(comments.CommentId, 10),
|
||||||
"{{Depth}}": strconv.Itoa(depth),
|
"{{Depth}}": strconv.Itoa(depth),
|
||||||
"{{Gravatar}}": Gravatar(comments.CommentAuthorEmail, c.Request.TLS != nil),
|
"{{Gravatar}}": Gravatar(comments.CommentAuthorEmail, isTls),
|
||||||
"{{CommentAuthorUrl}}": comments.CommentAuthorUrl,
|
"{{CommentAuthorUrl}}": comments.CommentAuthorUrl,
|
||||||
"{{CommentAuthor}}": comments.CommentAuthor,
|
"{{CommentAuthor}}": comments.CommentAuthor,
|
||||||
"{{PostId}}": strconv.FormatUint(comments.CommentPostId, 10),
|
"{{PostId}}": strconv.FormatUint(comments.CommentPostId, 10),
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed wp-content wp-includes favicon.ico
|
//go:embed wp-content wp-includes favicon.ico
|
||||||
var FsEx embed.FS
|
var FsDir embed.FS
|
||||||
|
|
||||||
type Fs struct {
|
type Fs struct {
|
||||||
embed.FS
|
embed.FS
|
||||||
|
|
|
@ -50,11 +50,11 @@
|
||||||
<link rel='stylesheet' id='twentyseventeen-style-css' href='/wp-content/themes/twentyseventeen/style.css?ver=20221101' media='all' />
|
<link rel='stylesheet' id='twentyseventeen-style-css' href='/wp-content/themes/twentyseventeen/style.css?ver=20221101' media='all' />
|
||||||
<link rel='stylesheet' id='twentyseventeen-block-style-css' href='/wp-content/themes/twentyseventeen/assets/css/blocks.css?ver=20220912' media='all' />
|
<link rel='stylesheet' id='twentyseventeen-block-style-css' href='/wp-content/themes/twentyseventeen/assets/css/blocks.css?ver=20220912' media='all' />
|
||||||
<!--[if lt IE 9]>
|
<!--[if lt IE 9]>
|
||||||
<link rel='stylesheet' id='twentyseventeen-ie8-css' href='http://wp.test/wp-content/themes/twentyseventeen/assets/css/ie8.css?ver=20161202' media='all' />
|
<link rel='stylesheet' id='twentyseventeen-ie8-css' href='/wp-content/themes/twentyseventeen/assets/css/ie8.css?ver=20161202' media='all' />
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
<link rel='stylesheet' id='enlighterjs-css' href='http://wp.test/wp-content/plugins/enlighter/cache/enlighterjs.min.css?ver=0A0B0C' media='all' />
|
<link rel='stylesheet' id='enlighterjs-css' href='/wp-content/plugins/enlighter/cache/enlighterjs.min.css?ver=0A0B0C' media='all' />
|
||||||
<!--[if lt IE 9]>
|
<!--[if lt IE 9]>
|
||||||
<script src='http://wp.test/wp-content/themes/twentyseventeen/assets/js/html5.js?ver=20161020' id='html5-js'></script>
|
<script src='/wp-content/themes/twentyseventeen/assets/js/html5.js?ver=20161020' id='html5-js'></script>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,8 @@ func Hook(status int, c *gin.Context, h gin.H, scene, stats int) {
|
||||||
h["HeaderImage"] = getHeaderImage(c)
|
h["HeaderImage"] = getHeaderImage(c)
|
||||||
post := h["post"].(models.Posts)
|
post := h["post"].(models.Posts)
|
||||||
h["bodyClass"] = bodyClass(scene, int(post.Id))
|
h["bodyClass"] = bodyClass(scene, int(post.Id))
|
||||||
host, _ := wpconfig.Options.Load("siteurl")
|
//host, _ := wpconfig.Options.Load("siteurl")
|
||||||
|
host := ""
|
||||||
img := plugins.Thumbnail(post.Thumbnail.OriginAttachmentData, "thumbnail", host, "thumbnail", "post-thumbnail")
|
img := plugins.Thumbnail(post.Thumbnail.OriginAttachmentData, "thumbnail", host, "thumbnail", "post-thumbnail")
|
||||||
img.Width = img.OriginAttachmentData.Width
|
img.Width = img.OriginAttachmentData.Width
|
||||||
img.Height = img.OriginAttachmentData.Height
|
img.Height = img.OriginAttachmentData.Height
|
||||||
|
@ -109,7 +110,7 @@ type comment struct {
|
||||||
plugins.CommonCommentFormat
|
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 := plugins.CommonLi()
|
||||||
templ = strings.ReplaceAll(templ, `<a rel="nofollow" class="comment-reply-link"
|
templ = strings.ReplaceAll(templ, `<a rel="nofollow" class="comment-reply-link"
|
||||||
href="/p/{{PostId}}?replytocom={{CommentId}}#respond" data-commentid="{{CommentId}}" data-postid="{{PostId}}"
|
href="/p/{{PostId}}?replytocom={{CommentId}}#respond" data-commentid="{{CommentId}}" data-postid="{{PostId}}"
|
||||||
|
@ -120,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-belowelement="div-comment-{{CommentId}}" data-respondelement="respond"
|
||||||
data-replyto="回复给{{CommentAuthor}}"
|
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>`)
|
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 {
|
func postThumbnail(posts []models.Posts, scene int) []models.Posts {
|
||||||
|
@ -149,12 +150,13 @@ func getHeaderImage(c *gin.Context) (r models.PostThumbnail) {
|
||||||
logs.ErrPrintln(err, "获取主题背景图信息错误")
|
logs.ErrPrintln(err, "获取主题背景图信息错误")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
host, _ := wpconfig.Options.Load("siteurl")
|
//host, _ := wpconfig.Options.Load("siteurl")
|
||||||
|
host := ""
|
||||||
m.Thumbnail = plugins.Thumbnail(m.AttachmentMetadata, "thumbnail", host, "thumbnail", "post-thumbnail", "twentyseventeen-thumbnail-avatar")
|
m.Thumbnail = plugins.Thumbnail(m.AttachmentMetadata, "thumbnail", host, "thumbnail", "post-thumbnail", "twentyseventeen-thumbnail-avatar")
|
||||||
if m.Thumbnail.Path != "" {
|
if m.Thumbnail.Path != "" {
|
||||||
r = m.Thumbnail
|
r = m.Thumbnail
|
||||||
if len(m.AttachmentMetadata.Sizes) > 0 {
|
if len(m.AttachmentMetadata.Sizes) > 0 {
|
||||||
r.Srcset = str.Join(r.Path, " 2000vw, ", r.Srcset)
|
r.Srcset = str.Join(r.Path, " 2000w, ", r.Srcset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user