From 2a87ebdfd6e6fa19b772fc3c06f9ecfff46a3d64 Mon Sep 17 00:00:00 2001 From: xing Date: Thu, 23 Feb 2023 18:21:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/theme/common/bodyclass.go | 6 +- internal/theme/common/common.go | 7 +- internal/theme/common/detail.go | 26 +++---- .../theme/twentyseventeen/layout/base.gohtml | 2 +- .../theme/twentyseventeen/posts/detail.gohtml | 2 +- .../theme/twentyseventeen/twentyseventeen.go | 71 ++++--------------- 6 files changed, 34 insertions(+), 80 deletions(-) diff --git a/internal/theme/common/bodyclass.go b/internal/theme/common/bodyclass.go index 0751ccf..c911eb0 100644 --- a/internal/theme/common/bodyclass.go +++ b/internal/theme/common/bodyclass.go @@ -12,11 +12,11 @@ import ( ) var commonClass = map[int]string{ - constraints.Home: "home blog", - constraints.Archive: "archive date", + constraints.Home: "home blog ", + constraints.Archive: "archive date ", constraints.Category: "archive category ", constraints.Tag: "archive category ", - constraints.Search: "search", + constraints.Search: "search ", constraints.Detail: "post-template-default single single-post ", } diff --git a/internal/theme/common/common.go b/internal/theme/common/common.go index e0acc30..e9e2073 100644 --- a/internal/theme/common/common.go +++ b/internal/theme/common/common.go @@ -69,13 +69,14 @@ func (h *Handle) Render() { h.Templ = str.Join(h.Theme, "/posts/detail.gohtml") } } + for _, fn := range h.HandleFns { + fn(h) + } h.AutoCal("siteIcon", h.CalSiteIcon) h.AutoCal("customLogo", h.CalCustomLogo) h.AutoCal("customCss", h.CalCustomCss) h.CalBodyClass() - for _, fn := range h.HandleFns { - fn(h) - } + h.C.HTML(h.Code, h.Templ, h.GinH) } diff --git a/internal/theme/common/detail.go b/internal/theme/common/detail.go index 0052ac2..918b20a 100644 --- a/internal/theme/common/detail.go +++ b/internal/theme/common/detail.go @@ -17,20 +17,25 @@ type DetailHandle struct { CommentRender plugins.CommentHtml Comments []models.Comments Post models.Posts + Pipes []HandlePipeFn[*DetailHandle] } func NewDetailHandle(handle *Handle) *DetailHandle { return &DetailHandle{Handle: handle} } +func (d *DetailHandle) Pipe(calls ...HandlePipeFn[*DetailHandle]) { + HandlePipe[*DetailHandle](append(calls, d.Pipes...), func(d *DetailHandle) { + d.Render() + })(d) +} + func (d *DetailHandle) BuildDetailData() (err error) { d.GinH["title"] = wpconfig.GetOption("blogname") err = d.CheckAndGetPost() if err != nil { return } - d.WidgetAreaData() - d.GetPassword() d.Comment() d.ContextPost() return @@ -73,6 +78,9 @@ func (d *DetailHandle) Comment() { } func (d *DetailHandle) RenderComment() { + if d.CommentRender == nil { + d.CommentRender = plugins.CommentRender() + } ableComment := true if d.Post.CommentStatus != "open" || (d.Post.PostPassword != "" && d.Password != d.Post.PostPassword) { @@ -94,19 +102,8 @@ func (d *DetailHandle) ContextPost() { func (d *DetailHandle) Render() { d.PasswordProject() - if d.CommentRender == nil { - d.CommentRender = plugins.CommentRender() - } - d.CalBodyClass() - d.AutoCal("siteIcon", d.CalSiteIcon) - d.AutoCal("customLogo", d.CalCustomLogo) - d.AutoCal("customCss", d.CalCustomCss) d.RenderComment() - d.CalBodyClass() - if d.Templ == "" { - d.Templ = fmt.Sprintf("%s/posts/detail.gohtml", d.Theme) - } - d.C.HTML(d.Code, d.Templ, d.GinH) + d.Handle.Render() } func (d *DetailHandle) Details() { @@ -117,6 +114,5 @@ func (d *DetailHandle) Details() { d.C.HTML(d.Code, d.Templ, d.GinH) return } - d.ExecHandlePlugin() d.Render() } diff --git a/internal/theme/twentyseventeen/layout/base.gohtml b/internal/theme/twentyseventeen/layout/base.gohtml index 6fd5deb..c698b8f 100644 --- a/internal/theme/twentyseventeen/layout/base.gohtml +++ b/internal/theme/twentyseventeen/layout/base.gohtml @@ -6,7 +6,7 @@ {{block "head" .}} {{end}} - + {{template "svg"}}
diff --git a/internal/theme/twentyseventeen/posts/detail.gohtml b/internal/theme/twentyseventeen/posts/detail.gohtml index 7eb8a97..fa2d5b1 100644 --- a/internal/theme/twentyseventeen/posts/detail.gohtml +++ b/internal/theme/twentyseventeen/posts/detail.gohtml @@ -1,7 +1,7 @@ {{template "layout/base" .}} {{define "content"}} - {{ if .post.PostContent}} + {{ if gt .post.Id 0}} {{if .post.Thumbnail.Path}}