From 14aad9e15b4ed0e9af9b68ea62f55e70a1fa26ab Mon Sep 17 00:00:00 2001 From: xing Date: Fri, 17 Mar 2023 18:26:08 +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/actions/themehook.go | 11 +++- .../pkg/constraints/widgets/constraints.go | 2 + internal/theme/twentyfifteen/twentyfifteen.go | 2 +- .../theme/twentyseventeen/twentyseventeen.go | 52 +++++++------------ internal/theme/wp/bodyclass.go | 2 +- .../theme/wp/components/widgetareadata.go | 29 +++++++++-- internal/theme/wp/index.go | 17 +++--- internal/theme/wp/wp.go | 6 +-- 8 files changed, 66 insertions(+), 55 deletions(-) diff --git a/internal/actions/themehook.go b/internal/actions/themehook.go index 89e9c98..244351b 100644 --- a/internal/actions/themehook.go +++ b/internal/actions/themehook.go @@ -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) diff --git a/internal/pkg/constraints/widgets/constraints.go b/internal/pkg/constraints/widgets/constraints.go index 93f67e7..bba37e4 100644 --- a/internal/pkg/constraints/widgets/constraints.go +++ b/internal/pkg/constraints/widgets/constraints.go @@ -7,4 +7,6 @@ const ( Archive = "archives" Categories = "categories" Meta = "meta" + + Widget = "widget" ) diff --git a/internal/theme/twentyfifteen/twentyfifteen.go b/internal/theme/twentyfifteen/twentyfifteen.go index ed17583..7247f8d 100644 --- a/internal/theme/twentyfifteen/twentyfifteen.go +++ b/internal/theme/twentyfifteen/twentyfifteen.go @@ -41,7 +41,6 @@ func Hook(h *wp.Handle) { } func ready(next wp.HandleFn[*wp.Handle], h *wp.Handle) { - components.WidgetArea(h) 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,6 +48,7 @@ func ready(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)) h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(wp.Indexs, 100)) h.PushHandleFn(constraints.Detail, wp.NewHandleFn(wp.Details, 100)) diff --git a/internal/theme/twentyseventeen/twentyseventeen.go b/internal/theme/twentyseventeen/twentyseventeen.go index 27dc739..ce2cb68 100644 --- a/internal/theme/twentyseventeen/twentyseventeen.go +++ b/internal/theme/twentyseventeen/twentyseventeen.go @@ -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(`
`, s, ss)) - wp.SetComponentsArgsForMap(h, s, "{$after_widget}", "
") - } + h.SetComponentsArgs(widgets.Widget, map[string]string{ + "{$before_widget}": `
`, + "{$after_widget}": `
`, + }) wp.SetComponentsArgsForMap(h, widgets.Search, "{$form}", searchForm) + next(h) } @@ -85,15 +80,6 @@ var searchForm = `