优化
This commit is contained in:
parent
8d398016ac
commit
e03194b768
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
9
internal/theme/wp/components/widget/middleware.go
Normal file
9
internal/theme/wp/components/widget/middleware.go
Normal 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...)
|
||||
}
|
|
@ -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>`
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user