From 8af755651183a23cc88d00e912dff13ebc25fdc8 Mon Sep 17 00:00:00 2001 From: xing Date: Mon, 30 Jan 2023 20:16:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.example.yaml | 4 +++- internal/cmd/route/route.go | 17 ++++++++++++----- internal/pkg/config/config.go | 1 + internal/pkg/dao/posts.go | 4 ++-- internal/static/static.go | 2 +- .../theme/twentyseventeen/layout/head.gohtml | 6 +++--- .../theme/twentyseventeen/twentyseventeen.go | 8 +++++--- 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/config.example.yaml b/config.example.yaml index c0c07cf..c39c68d 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -78,4 +78,6 @@ port: 8082 # 主题 为空值为option template,没有就默认为twentyfifteen theme: "twentyfifteen" # 文档排序默认升序还是降序 -postOrder: "desc" \ No newline at end of file +postOrder: "desc" +# 上传的目录 +uploadDir: "" \ No newline at end of file diff --git a/internal/cmd/route/route.go b/internal/cmd/route/route.go index 7eda3d0..9da364f 100644 --- a/internal/cmd/route/route.go +++ b/internal/cmd/route/route.go @@ -44,13 +44,20 @@ func SetupRouter() (*gin.Engine, func()) { }))) } - f := static.Fs{FS: static.FsEx, Path: "wp-includes"} - r.StaticFileFS("/favicon.ico", "favicon.ico", http.FS(static.FsEx)) + f := static.Fs{FS: static.FsDir, Path: "wp-includes"} + r.StaticFileFS("/favicon.ico", "favicon.ico", http.FS(static.FsDir)) r.StaticFS("/wp-includes", http.FS(f)) - r.StaticFS("/wp-content", http.FS(static.Fs{ - FS: static.FsEx, - Path: "wp-content", + r.StaticFS("/wp-content/plugins", http.FS(static.Fs{ + FS: static.FsDir, + 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")) r.Use(sessions.Sessions("go-wp", store)) sl, slRload := middleware.SearchLimit(c.SingleIpSearchNum) diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index 8302f16..b957ec5 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -40,6 +40,7 @@ type Config struct { TrustServerNames []string `yaml:"trustServerNames"` Theme string `yaml:"theme"` PostOrder string `yaml:"postOrder"` + UploadDir string `yaml:"uploadDir"` } type Ssl struct { diff --git a/internal/pkg/dao/posts.go b/internal/pkg/dao/posts.go index 92a4e4f..b92df99 100644 --- a/internal/pkg/dao/posts.go +++ b/internal/pkg/dao/posts.go @@ -7,7 +7,6 @@ import ( "github.com/fthvgb1/wp-go/helper/slice" "github.com/fthvgb1/wp-go/internal/pkg/models" "github.com/fthvgb1/wp-go/internal/plugins" - "github.com/fthvgb1/wp-go/internal/wpconfig" "github.com/fthvgb1/wp-go/model" "strings" "sync/atomic" @@ -44,7 +43,8 @@ func GetPostsByIds(ids ...any) (m map[uint64]models.Posts, err error) { } postsMap[post.Id] = v } - host, _ := wpconfig.Options.Load("siteurl") + //host, _ := wpconfig.Options.Load("siteurl") + host := "" meta, _ := GetPostMetaByPostIds(ctx, id) for k, pp := range postsMap { if len(pp.Categories) > 0 { diff --git a/internal/static/static.go b/internal/static/static.go index ab12fb2..1c1013c 100644 --- a/internal/static/static.go +++ b/internal/static/static.go @@ -9,7 +9,7 @@ import ( ) //go:embed wp-content wp-includes favicon.ico -var FsEx embed.FS +var FsDir embed.FS type Fs struct { embed.FS diff --git a/internal/theme/twentyseventeen/layout/head.gohtml b/internal/theme/twentyseventeen/layout/head.gohtml index 94a4c28..bf5a312 100644 --- a/internal/theme/twentyseventeen/layout/head.gohtml +++ b/internal/theme/twentyseventeen/layout/head.gohtml @@ -50,11 +50,11 @@ - + diff --git a/internal/theme/twentyseventeen/twentyseventeen.go b/internal/theme/twentyseventeen/twentyseventeen.go index 728d44a..b93f6ac 100644 --- a/internal/theme/twentyseventeen/twentyseventeen.go +++ b/internal/theme/twentyseventeen/twentyseventeen.go @@ -88,7 +88,8 @@ func Hook(status int, c *gin.Context, h gin.H, scene, stats int) { h["HeaderImage"] = getHeaderImage(c) post := h["post"].(models.Posts) 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.Width = img.OriginAttachmentData.Width img.Height = img.OriginAttachmentData.Height @@ -149,12 +150,13 @@ func getHeaderImage(c *gin.Context) (r models.PostThumbnail) { logs.ErrPrintln(err, "获取主题背景图信息错误") 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") if m.Thumbnail.Path != "" { r = m.Thumbnail if len(m.AttachmentMetadata.Sizes) > 0 { - r.Srcset = str.Join(r.Path, " 2000vw, ", r.Srcset) + r.Srcset = str.Join(r.Path, " 2000w, ", r.Srcset) } } }