Compare commits

..

3 Commits

Author SHA1 Message Date
57a21010a8 优化 fix bug 2023-03-17 19:51:53 +08:00
14aad9e15b 优化代码 2023-03-17 18:26:08 +08:00
3f96c09d36 fix bug 优化 2023-03-17 13:35:22 +08:00
16 changed files with 193 additions and 196 deletions

View File

@ -1,15 +1,22 @@
package actions
import (
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
"github.com/fthvgb1/wp-go/internal/theme"
"github.com/fthvgb1/wp-go/internal/theme/wp"
"github.com/gin-gonic/gin"
)
func ThemeHook(scene int) func(*gin.Context) {
return func(ctx *gin.Context) {
return func(c *gin.Context) {
s := scene
if scene == constraints.Home {
if _, ok := c.GetQuery("s"); ok {
s = constraints.Search
}
}
t := theme.GetCurrentTemplateName()
h := wp.NewHandle(ctx, scene, t)
h := wp.NewHandle(c, s, t)
h.Index = wp.NewIndexHandle(h)
h.Detail = wp.NewDetailHandle(h)
theme.Hook(t, h)

View File

@ -7,4 +7,6 @@ const (
Archive = "archives"
Categories = "categories"
Meta = "meta"
Widget = "widget"
)

View File

@ -34,14 +34,13 @@ func Init(fs embed.FS) {
logs.ErrPrintln(err, "解析colorscheme失败")
}
var pipe = wp.HandlePipe(wp.Render, widget.MiddleWare(dispatch)...)
var pipe = wp.HandlePipe(wp.Render, widget.MiddleWare(ready)...)
func Hook(h *wp.Handle) {
pipe(h)
}
func dispatch(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
components.WidgetArea(h)
func ready(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
h.GetPassword()
h.PushComponentFilterFn(widgets.Search, func(h *wp.Handle, s string) string {
return strings.ReplaceAll(s, `class="search-submit"`, `class="search-submit screen-reader-text"`)
@ -49,19 +48,9 @@ func dispatch(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
wphandle.RegisterPlugins(h, config.GetConfig().Plugins...)
h.PushCacheGroupHeadScript("CalCustomBackGround", 10, CalCustomBackGround, colorSchemeCss)
h.PushHandleFn(constraints.Ok, wp.NewHandleFn(components.WidgetArea, 20))
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(customHeader, 10))
switch h.Scene() {
case constraints.Detail:
detail(next, h.Detail)
default:
index(next, h.Index)
}
}
func index(next wp.HandleFn[*wp.Handle], i *wp.IndexHandle) {
i.Indexs()
}
func detail(fn wp.HandleFn[*wp.Handle], d *wp.DetailHandle) {
d.Details()
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(wp.Indexs, 100))
h.PushHandleFn(constraints.Detail, wp.NewHandleFn(wp.Details, 100))
next(h)
}

View File

@ -43,34 +43,29 @@ var paginate = func() plugins.PageEle {
return p
}()
var pipe = wp.HandlePipe(wp.Render, widget.MiddleWare(ready, dispatch)...)
var pipe = wp.HandlePipe(wp.Render, widget.MiddleWare(ready)...)
func Hook(h *wp.Handle) {
pipe(h)
}
func ready(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
components.WidgetArea(h)
h.GetPassword()
wphandle.RegisterPlugins(h, config.GetConfig().Plugins...)
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(calClass, 20))
errHandle := wp.NewHandleFn(errorsHandle, 100)
h.PushHandleFn(constraints.Error404, errHandle)
h.PushHandleFn(constraints.ParamError, errHandle)
h.PushHandleFn(constraints.InternalErr, errHandle)
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(index, 100))
h.PushHandleFn(constraints.Detail, wp.NewHandleFn(detail, 100))
h.PushGroupHandleFn(constraints.AllStats, 99, wp.PreCodeAndStats, wp.PreTemplate, errorsHandle)
h.PushCacheGroupHeadScript("colorScheme-customHeader", 10, colorScheme, customHeader)
h.PushHandleFn(constraints.Ok, wp.NewHandleFn(components.WidgetArea, 20))
pushScripts(h)
h.SetData("HeaderImage", getHeaderImage(h))
h.SetData("scene", h.Scene())
for _, s := range []string{widgets.Meta, widgets.Categories, widgets.Archive, widgets.Search, widgets.RecentComments, widgets.RecentPosts} {
ss := strings.ReplaceAll(s, "-", "_")
if s == widgets.RecentPosts {
ss = "recent_entries"
}
wp.SetComponentsArgsForMap(h, s, "{$before_widget}", fmt.Sprintf(`<section id="%s-2" class="widget widget_%s">`, s, ss))
wp.SetComponentsArgsForMap(h, s, "{$after_widget}", "</section>")
}
h.SetComponentsArgs(widgets.Widget, map[string]string{
"{$before_widget}": `<section id="%s" class="widget widget_%s">`,
"{$after_widget}": `</section>`,
})
wp.SetComponentsArgsForMap(h, widgets.Search, "{$form}", searchForm)
next(h)
}
@ -85,15 +80,6 @@ var searchForm = `<form role="search" method="get" class="search-form" action="/
</button>
</form>`
func dispatch(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
switch h.Scene() {
case constraints.Detail:
detail(next, h.Detail)
default:
index(next, h.Index)
}
}
var listPostsPlugins = func() map[string]wp.Plugin[models.Posts, *wp.Handle] {
return maps.Merge(wp.ListPostPlugins(), map[string]wp.Plugin[models.Posts, *wp.Handle]{
"twentyseventeen_postThumbnail": postThumbnail,
@ -101,24 +87,29 @@ var listPostsPlugins = func() map[string]wp.Plugin[models.Posts, *wp.Handle] {
}()
func errorsHandle(h *wp.Handle) {
h.SetTempl("twentyseventeen/posts/error.gohtml")
switch h.Stats {
case constraints.Error404, constraints.InternalErr:
case constraints.Error404, constraints.InternalErr, constraints.ParamError:
logs.ErrPrintln(h.Err(), "报错:")
h.SetTempl("twentyseventeen/posts/error.gohtml")
}
}
func index(next wp.HandleFn[*wp.Handle], i *wp.IndexHandle) {
func index(h *wp.Handle) {
if h.Scene() == constraints.Detail {
return
}
i := h.Index
err := i.BuildIndexData(wp.NewIndexParams(i.C))
if err != nil {
i.SetErr(err)
}
h.SetData("scene", h.Scene())
i.SetPageEle(paginate)
i.SetPostsPlugins(listPostsPlugins)
next(i.Handle)
}
func detail(next wp.HandleFn[*wp.Handle], d *wp.DetailHandle) {
func detail(h *wp.Handle) {
d := h.Detail
err := d.BuildDetailData()
if err != nil {
d.SetErr(err)
@ -129,10 +120,7 @@ func detail(next wp.HandleFn[*wp.Handle], d *wp.DetailHandle) {
img.Srcset = fmt.Sprintf("%s %dw, %s", img.Path, img.Width, img.Srcset)
d.Post.Thumbnail = img
}
d.CommentRender = commentFormat
next(d.Handle)
}
var commentFormat = comment{}

View File

@ -11,7 +11,7 @@ import (
"strings"
)
func (h *Handle) CalBodyClass() {
func CalBodyClass(h *Handle) {
h.ginH["bodyClass"] = h.BodyClass(h.class...)
}

View File

@ -10,18 +10,19 @@ import (
"github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/fthvgb1/wp-go/internal/theme/wp"
"github.com/fthvgb1/wp-go/internal/wpconfig"
"github.com/fthvgb1/wp-go/safety"
"strings"
)
var archivesConfig = func() safety.Var[map[any]any] {
v := safety.Var[map[any]any]{}
v.Store(map[any]any{
"count": int64(0),
"dropdown": int64(0),
"title": "归档",
})
archiveArgs.Store(map[string]string{
var archiveTemplate = `{$before_widget}
{$title}
{$nav}
{$html}
{$navCloser}
{$after_widget}
`
func archiveArgs() map[string]string {
return map[string]string{
"{$before_widget}": `<aside id="archives-2" class="widget widget_archive">`,
"{$after_widget}": "</aside>",
"{$before_title}": `<h2 class="widget-title">`,
@ -34,24 +35,23 @@ var archivesConfig = func() safety.Var[map[any]any] {
"{$dropdown_id}": "archives-dropdown-2",
"{$dropdown_type}": "monthly",
"{$dropdown_label}": "选择月份",
})
return v
}()
}
}
var archiveArgs = safety.Var[map[string]string]{}
var archiveTemplate = `{$before_widget}
{$title}
{$nav}
{$html}
{$navCloser}
{$after_widget}
`
func archivesConfig() map[any]any {
return map[any]any{
"count": int64(0),
"dropdown": int64(0),
"title": "归档",
}
}
func Archive(h *wp.Handle) string {
args := wp.GetComponentsArgs(h, widgets.Archive, archiveArgs.Load())
args = maps.FilterZeroMerge(archiveArgs.Load(), args)
conf := wpconfig.GetPHPArrayVal("widget_archives", archivesConfig.Load(), int64(2))
archiveArgs := archiveArgs()
archivesConfig := archivesConfig()
args := wp.GetComponentsArgs(h, widgets.Archive, archiveArgs)
args = maps.FilterZeroMerge(archiveArgs, args)
conf := wpconfig.GetPHPArrayVal("widget_archives", archivesConfig, int64(2))
args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"])
if id, ok := args["{$id}"]; ok && id != "" {
args["{$before_widget}"] = strings.ReplaceAll(args["{$before_widget}"], "2", args["{$id}"])

View File

@ -0,0 +1,10 @@
package widget
func commonArgs() map[string]string {
return map[string]string{
"{$before_widget}": `<aside id="%s" class="widget widget_%s">`,
"{$after_widget}": "</aside>",
"{$before_title}": `<h2 class="widget-title">`,
"{$after_title}": "</h2>",
}
}

View File

@ -12,21 +12,29 @@ import (
"github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/fthvgb1/wp-go/internal/theme/wp"
"github.com/fthvgb1/wp-go/internal/wpconfig"
"github.com/fthvgb1/wp-go/safety"
"net/http"
"strings"
)
var categoryArgs safety.Var[map[string]string]
var categoryConfig = func() safety.Var[map[any]any] {
v := safety.Var[map[any]any]{}
v.Store(map[any]any{
var categoryTemplate = `{$before_widget}
{$title}
{$nav}
{$html}
{$navCloser}
{$after_widget}
`
func categoryConfig() map[any]any {
return map[any]any{
"count": int64(0),
"dropdown": int64(0),
"hierarchical": int64(0),
"title": "分类",
})
categoryArgs.Store(map[string]string{
}
}
func categoryArgs() map[string]string {
return map[string]string{
"{$before_widget}": `<aside id="categories-2" class="widget widget_categories">`,
"{$after_widget}": "</aside>",
"{$before_title}": `<h2 class="widget-title">`,
@ -44,23 +52,14 @@ var categoryConfig = func() safety.Var[map[any]any] {
"{$dropdown_id}": "archives-dropdown-2",
"{$dropdown_type}": "monthly",
"{$dropdown_label}": "选择月份",
})
return v
}()
var categoryTemplate = `{$before_widget}
{$title}
{$nav}
{$html}
{$navCloser}
{$after_widget}
`
}
}
func Category(h *wp.Handle) string {
args := wp.GetComponentsArgs(h, widgets.Categories, categoryArgs.Load())
args = maps.FilterZeroMerge(categoryArgs.Load(), args)
conf := wpconfig.GetPHPArrayVal("widget_categories", categoryConfig.Load(), int64(2))
conf = maps.FilterZeroMerge(categoryConfig.Load(), conf)
args := wp.GetComponentsArgs(h, widgets.Categories, categoryArgs())
args = maps.FilterZeroMerge(categoryArgs(), args)
conf := wpconfig.GetPHPArrayVal("widget_categories", categoryConfig(), int64(2))
conf = maps.FilterZeroMerge(categoryConfig(), conf)
args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"])
t := categoryTemplate
dropdown := conf["dropdown"].(int64)
@ -240,7 +239,7 @@ func IsCategory(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
}
func parseDropdownCate(h *wp.Handle) (cateName string, r bool) {
cate := wp.GetComponentsArgs[map[string]string](h, widgets.Categories, categoryArgs.Load())
cate := wp.GetComponentsArgs[map[string]string](h, widgets.Categories, categoryArgs())
name, ok := cate["{$name}"]
if !ok || name == "" {
return

View File

@ -8,7 +8,6 @@ import (
"github.com/fthvgb1/wp-go/internal/pkg/constraints/widgets"
"github.com/fthvgb1/wp-go/internal/theme/wp"
"github.com/fthvgb1/wp-go/internal/wpconfig"
"github.com/fthvgb1/wp-go/safety"
"strings"
)
@ -21,9 +20,8 @@ var metaTemplate = `{$before_widget}
{$navCloser}
{$after_widget}`
var metaArgs = func() safety.Var[map[string]string] {
v := safety.Var[map[string]string]{}
v.Store(map[string]string{
func metaArgs() map[string]string {
return map[string]string{
"{$before_widget}": `<aside id="meta-2" class="widget widget_meta">`,
"{$after_widget}": `</aside>`,
"{$aria_label}": "",
@ -31,13 +29,13 @@ var metaArgs = func() safety.Var[map[string]string] {
"": "",
"{$before_title}": `<h2 class="widget-title">`,
"{$after_title}": `</h2>`,
})
return v
}()
}
}
func Meta(h *wp.Handle) string {
args := wp.GetComponentsArgs(h, widgets.Meta, metaArgs.Load())
args = maps.FilterZeroMerge(metaArgs.Load(), args)
metaArgs := metaArgs()
args := wp.GetComponentsArgs(h, widgets.Meta, metaArgs)
args = maps.FilterZeroMerge(metaArgs, args)
args["{$title}"] = wpconfig.GetPHPArrayVal("widget_meta", "其它操作", int64(2), "title")
if id, ok := args["{$id}"]; ok && id != "" {
args["{$before_widget}"] = strings.ReplaceAll(args["{$before_widget}"], "2", args["{$id}"])

View File

@ -10,13 +10,11 @@ import (
"github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/fthvgb1/wp-go/internal/theme/wp"
"github.com/fthvgb1/wp-go/internal/wpconfig"
"github.com/fthvgb1/wp-go/safety"
"strings"
)
var recentCommentsArgs = func() safety.Var[map[string]string] {
v := safety.Var[map[string]string]{}
v.Store(map[string]string{
func recentCommentsArgs() map[string]string {
return map[string]string{
"{$before_widget}": `<aside id="recent-comments-2" class="widget widget_recent_comments">`,
"{$after_widget}": "</aside>",
"{$before_title}": `<h2 class="widget-title">`,
@ -27,15 +25,15 @@ var recentCommentsArgs = func() safety.Var[map[string]string] {
"{$navCloser}": "",
"{$title}": "",
"{$recent_comments_id}": "recentcomments",
})
recentCommentConf.Store(map[any]any{
}
}
func recentCommentConf() map[any]any {
return map[any]any{
"number": int64(5),
"title": "近期评论",
})
return v
}()
var recentCommentConf = safety.Var[map[any]any]{}
}
}
var recentCommentsTemplate = `{$before_widget}
{$nav}
@ -48,10 +46,12 @@ var recentCommentsTemplate = `{$before_widget}
`
func RecentComments(h *wp.Handle) string {
args := wp.GetComponentsArgs(h, widgets.RecentComments, recentCommentsArgs.Load())
args = maps.FilterZeroMerge(recentCommentsArgs.Load(), args)
conf := wpconfig.GetPHPArrayVal("widget_recent-comments", recentCommentConf.Load(), int64(2))
conf = maps.FilterZeroMerge(recentCommentConf.Load(), conf)
recentCommentsArgs := recentCommentsArgs()
recentCommentConf := recentCommentConf()
args := wp.GetComponentsArgs(h, widgets.RecentComments, recentCommentsArgs)
args = maps.FilterZeroMerge(recentCommentsArgs, args)
conf := wpconfig.GetPHPArrayVal("widget_recent-comments", recentCommentConf, int64(2))
conf = maps.FilterZeroMerge(recentCommentConf, conf)
args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"])
if id, ok := args["{$id}"]; ok && id != "" {
args["{$before_widget}"] = strings.ReplaceAll(args["{$before_widget}"], "2", args["{$id}"])

View File

@ -11,12 +11,9 @@ import (
"github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/fthvgb1/wp-go/internal/theme/wp"
"github.com/fthvgb1/wp-go/internal/wpconfig"
"github.com/fthvgb1/wp-go/safety"
"strings"
)
var recentPostsArgs = safety.Var[map[string]string]{}
var recentPostsTemplate = `{$before_widget}
{$nav}
{$title}
@ -27,9 +24,8 @@ var recentPostsTemplate = `{$before_widget}
{$after_widget}
`
var recentConf = func() safety.Var[map[any]any] {
recentPostsArgs.Store(map[string]string{
func recentPostsArgs() map[string]string {
return map[string]string{
"{$before_widget}": `<aside id="recent-posts-2" class="widget widget_recent_entries">`,
"{$after_widget}": "</aside>",
"{$before_title}": `<h2 class="widget-title">`,
@ -39,21 +35,24 @@ var recentConf = func() safety.Var[map[any]any] {
"{$nav}": "",
"{$navCloser}": "",
"{$title}": "",
})
v := safety.Var[map[any]any]{}
v.Store(map[any]any{
}
}
func recentConf() map[any]any {
return map[any]any{
"number": int64(5),
"show_date": false,
"title": "近期文章",
})
return v
}()
}
}
func RecentPosts(h *wp.Handle) string {
args := wp.GetComponentsArgs(h, widgets.RecentPosts, recentPostsArgs.Load())
args = maps.FilterZeroMerge(recentPostsArgs.Load(), args)
conf := wpconfig.GetPHPArrayVal[map[any]any]("widget_recent-posts", recentConf.Load(), int64(2))
conf = maps.FilterZeroMerge(recentConf.Load(), conf)
recentPostsArgs := recentPostsArgs()
recentConf := recentConf()
args := wp.GetComponentsArgs(h, widgets.RecentPosts, recentPostsArgs)
args = maps.FilterZeroMerge(recentPostsArgs, args)
conf := wpconfig.GetPHPArrayVal[map[any]any]("widget_recent-posts", recentConf, int64(2))
conf = maps.FilterZeroMerge(recentConf, conf)
if id, ok := args["{$id}"]; ok && id != "" {
args["{$before_widget}"] = strings.ReplaceAll(args["{$before_widget}"], "2", args["{$id}"])
}

View File

@ -9,7 +9,6 @@ import (
"github.com/fthvgb1/wp-go/internal/pkg/constraints/widgets"
"github.com/fthvgb1/wp-go/internal/theme/wp"
"github.com/fthvgb1/wp-go/internal/wpconfig"
"github.com/fthvgb1/wp-go/safety"
"strings"
)
@ -18,24 +17,6 @@ var searchTemplate = `{$before_widget}
{$form}
{$after_widget}`
var searchArgs = func() safety.Var[map[string]string] {
v := safety.Var[map[string]string]{}
v.Store(map[string]string{
"{$id}": "2",
"{$before_widget}": `<aside id="search-2" class="widget widget_search">`,
"{$after_widget}": `</aside>`,
"{$aria_label}": "",
"{$title}": "",
"{$before_title}": `<h2 class="widget-title">`,
"{$after_title}": `</h2>`,
"{$form}": "",
"{$button}": "搜索",
"{$placeholder}": "搜索&hellip;",
"{$label}": "搜索:",
})
return v
}()
var html5SearchForm = `<form role="search" {$aria_label} method="get" class="search-form" action="/">
<label>
<span class="screen-reader-text">{$label}</span>
@ -51,9 +32,26 @@ var xmlSearchForm = `<form role="search" {$aria_label} method="get" id="searchfo
</div>
</form>`
func SearchForm(h *wp.Handle) string {
args := wp.GetComponentsArgs(h, widgets.Search, searchArgs.Load())
args = maps.FilterZeroMerge(searchArgs.Load(), args)
func searchArgs() map[string]string {
return map[string]string{
"{$id}": "2",
"{$before_widget}": `<aside id="search-2" class="widget widget_search">`,
"{$after_widget}": `</aside>`,
"{$aria_label}": "",
"{$title}": "",
"{$before_title}": `<h2 class="widget-title">`,
"{$after_title}": `</h2>`,
"{$form}": "",
"{$button}": "搜索",
"{$placeholder}": "搜索&hellip;",
"{$label}": "搜索:",
}
}
func Search(h *wp.Handle) string {
searchArgs := searchArgs()
args := wp.GetComponentsArgs(h, widgets.Search, searchArgs)
args = maps.FilterZeroMerge(searchArgs, args)
if args["{$title}"] == "" {
args["{$title}"] = wpconfig.GetPHPArrayVal("widget_search", "", int64(2), "title")
}

View File

@ -1,17 +1,19 @@
package components
import (
"fmt"
"github.com/fthvgb1/wp-go/helper/slice"
"github.com/fthvgb1/wp-go/internal/pkg/cache"
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
"github.com/fthvgb1/wp-go/internal/pkg/constraints/widgets"
"github.com/fthvgb1/wp-go/internal/theme/wp"
"github.com/fthvgb1/wp-go/internal/theme/wp/components/widget"
"github.com/fthvgb1/wp-go/internal/wpconfig"
"strings"
)
var widgets = map[string]func(*wp.Handle) string{
"search": widget.SearchForm,
var widgetFn = map[string]func(*wp.Handle) string{
"search": widget.Search,
"recent-posts": widget.RecentPosts,
"recent-comments": widget.RecentComments,
"archives": widget.Archive,
@ -20,23 +22,40 @@ var widgets = map[string]func(*wp.Handle) string{
}
func WidgetArea(h *wp.Handle) {
args := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
beforeWidget, ok := args["{$before_widget}"]
if !ok {
beforeWidget = ""
} else {
delete(args, "{$before_widget}")
}
v := wpconfig.GetPHPArrayVal("sidebars_widgets", []any{}, "sidebar-1")
sidebar := slice.FilterAndMap(v, func(t any) (func(*wp.Handle) string, bool) {
vv := t.(string)
ss := strings.Split(vv, "-")
id := ss[len(ss)-1]
name := strings.Join(ss[0:len(ss)-1], "-")
fn, ok := widgets[name]
fn, ok := widgetFn[name]
if ok {
if id != "2" {
wp.SetComponentsArgsForMap(h, name, "{$id}", id)
}
if beforeWidget != "" {
n := strings.ReplaceAll(name, "-", "_")
if name == "recent-posts" {
n = "recent_entries"
}
wp.SetComponentsArgsForMap(h, name, "{$before_widget}", fmt.Sprintf(beforeWidget, vv, n))
}
if len(args) > 0 {
for k, val := range args {
wp.SetComponentsArgsForMap(h, name, k, val)
}
}
return fn, true
}
return nil, false
})
h.PushHandleFn(constraints.Ok, wp.NewHandleFn(func(h *wp.Handle) {
h.PushGroupComponentFns(constraints.SidebarsWidgets, 10, sidebar...)
}, 30))
h.PushGroupComponentFns(constraints.SidebarsWidgets, 10, sidebar...)
h.SetData("categories", cache.CategoriesTags(h.C, constraints.Category))
}

View File

@ -101,8 +101,6 @@ func (d *DetailHandle) ContextPost() {
}
func (d *DetailHandle) Render() {
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>`
@ -118,7 +116,8 @@ func (d *DetailHandle) Render() {
d.Handle.Render()
}
func (d *DetailHandle) Details() {
_ = d.BuildDetailData()
d.Render()
func Details(h *Handle) {
_ = h.Detail.BuildDetailData()
PreCodeAndStats(h)
PreTemplate(h)
}

View File

@ -47,11 +47,7 @@ func NewIndexHandle(handle *Handle) *IndexHandle {
func (i *IndexHandle) ParseIndex(parm *IndexParams) (err error) {
i.Param = parm
switch i.scene {
case constraints.Home, constraints.Search:
s := i.C.Query("s")
if s != "" && strings.Replace(s, " ", "", -1) != "" {
i.scene = constraints.Search
}
case constraints.Search:
i.Param.ParseSearch()
case constraints.Category:
err = i.Param.ParseCategory()
@ -148,8 +144,6 @@ func (i *IndexHandle) ExecPostsPlugin(calls ...func(*models.Posts)) {
}
func (i *IndexHandle) Render() {
PreCodeAndStats(i.Handle)
PreTemplate(i.Handle)
i.PushHandleFn(constraints.Ok, NewHandleFn(func(h *Handle) {
i.ExecPostsPlugin()
i.Pagination()
@ -159,7 +153,12 @@ func (i *IndexHandle) Render() {
i.Handle.Render()
}
func (i *IndexHandle) Indexs() {
func Indexs(h *Handle) {
if h.Scene() == constraints.Detail {
return
}
i := h.Index
_ = i.BuildIndexData(NewIndexParams(i.C))
i.Render()
PreCodeAndStats(h)
PreTemplate(h)
}

View File

@ -1,7 +1,6 @@
package wp
import (
"fmt"
"github.com/fthvgb1/wp-go/helper/maps"
"github.com/fthvgb1/wp-go/helper/slice"
str "github.com/fthvgb1/wp-go/helper/strings"
@ -229,10 +228,6 @@ func (h *Handle) PushGroupFooterScript(order int, fns ...string) {
h.PushGroupComponentStrs(constraints.FooterScript, order, fns...)
}
func (h *Handle) componentKey(name string) string {
return fmt.Sprintf("theme_%d_%s", h.scene, name)
}
func (h *Handle) PushCacheGroupFooterScript(key string, order int, fns ...func(*Handle) string) {
h.PushGroupCacheComponentFn(constraints.FooterScript, key, order, fns...)
}
@ -303,17 +298,14 @@ func (h *Handle) Render() {
func (h *Handle) CommonComponents() {
h.AddCacheComponent("customLogo", CalCustomLogo)
h.PushCacheGroupHeadScript("siteIconAndCustomCss", 0, CalSiteIcon, CalCustomCss)
h.PushGroupHandleFn(constraints.AllStats, 10, CalMultipleComponents, CalBodyClass)
h.PushHandleFn(constraints.AllStats, NewHandleFn(func(h *Handle) {
h.CalMultipleComponents()
h.CalBodyClass()
}, 10), NewHandleFn(func(h *Handle) {
h.C.HTML(h.Code, h.templ, h.ginH)
}, 0))
}
func (h *Handle) PushComponents(name string, components ...Components) {
k := h.componentKey(name)
h.components[k] = append(h.components[k], components...)
h.components[name] = append(h.components[name], components...)
}
func (h *Handle) PushGroupComponentStrs(name string, order int, fns ...string) {
@ -324,8 +316,7 @@ func (h *Handle) PushGroupComponentStrs(name string, order int, fns ...string) {
Order: order,
})
}
k := h.componentKey(name)
h.components[k] = append(h.components[k], calls...)
h.components[name] = append(h.components[name], calls...)
}
func (h *Handle) PushGroupComponentFns(name string, order int, fns ...func(*Handle) string) {
var calls []Components
@ -335,11 +326,10 @@ func (h *Handle) PushGroupComponentFns(name string, order int, fns ...func(*Hand
Order: order,
})
}
k := h.componentKey(name)
h.components[k] = append(h.components[k], calls...)
h.components[name] = append(h.components[name], calls...)
}
func (h *Handle) CalMultipleComponents() {
func CalMultipleComponents(h *Handle) {
for k, ss := range h.components {
slice.Sort(ss, func(i, j Components) bool {
return i.Order > j.Order