This commit is contained in:
xing 2023-03-14 19:21:00 +08:00
parent 8d398016ac
commit e03194b768
6 changed files with 18 additions and 8 deletions

View File

@ -34,7 +34,7 @@ func Init(fs embed.FS) {
logs.ErrPrintln(err, "解析colorscheme失败")
}
var pipe = wp.HandlePipe(wp.Render, widget.IsCategory, dispatch)
var pipe = wp.HandlePipe(wp.Render, widget.MiddleWare(dispatch)...)
func Hook(h *wp.Handle) {
pipe(h)

View File

@ -16,6 +16,7 @@ import (
"github.com/fthvgb1/wp-go/internal/plugins/wphandle"
"github.com/fthvgb1/wp-go/internal/theme/wp"
"github.com/fthvgb1/wp-go/internal/theme/wp/components"
"github.com/fthvgb1/wp-go/internal/theme/wp/components/widget"
"github.com/fthvgb1/wp-go/internal/wpconfig"
"github.com/gin-gonic/gin"
"strings"
@ -41,7 +42,7 @@ var paginate = func() plugins.PageEle {
return p
}()
var pipe = wp.HandlePipe(wp.Render, ready, dispatch)
var pipe = wp.HandlePipe(wp.Render, widget.MiddleWare(ready, dispatch)...)
func Hook(h *wp.Handle) {
pipe(h)

View File

@ -0,0 +1,9 @@
package widget
import "github.com/fthvgb1/wp-go/internal/theme/wp"
func MiddleWare(call ...wp.HandlePipeFn[*wp.Handle]) []wp.HandlePipeFn[*wp.Handle] {
return append([]wp.HandlePipeFn[*wp.Handle]{
IsCategory,
}, call...)
}

View File

@ -101,8 +101,8 @@ func (d *DetailHandle) ContextPost() {
}
func (d *DetailHandle) Render() {
d.PreCodeAndStats()
d.PreTemplate()
PreCodeAndStats(d.Handle)
PreTemplate(d.Handle)
reply := ""
if d.Post.CommentStatus == "open" && wpconfig.GetOption("thread_comments") == "1" {
reply = `<script src='/wp-includes/js/comment-reply.min.js' id='comment-reply-js'></script>`

View File

@ -148,8 +148,8 @@ func (i *IndexHandle) ExecPostsPlugin(calls ...func(*models.Posts)) {
}
func (i *IndexHandle) Render() {
i.PreCodeAndStats()
i.PreTemplate()
PreCodeAndStats(i.Handle)
PreTemplate(i.Handle)
i.PushHandleFn(constraints.Ok, NewHandleFn(func(h *Handle) {
i.ExecPostsPlugin()
i.Pagination()

View File

@ -273,7 +273,7 @@ func (h *Handle) ExecHandleFns() {
}
}
func (h *Handle) PreTemplate() {
func PreTemplate(h *Handle) {
if h.templ == "" {
h.templ = str.Join(h.theme, "/posts/index.gohtml")
if h.scene == constraints.Detail {
@ -281,7 +281,7 @@ func (h *Handle) PreTemplate() {
}
}
}
func (h *Handle) PreCodeAndStats() {
func PreCodeAndStats(h *Handle) {
if h.Stats != 0 && h.Code != 0 {
return
}