From 00c16c03a4b3c8dade4da820364cf32baa4e1aa7 Mon Sep 17 00:00:00 2001 From: xing Date: Sat, 18 Mar 2023 22:26:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../theme/wp/components/widgetareadata.go | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/internal/theme/wp/components/widgetareadata.go b/internal/theme/wp/components/widgetareadata.go index ef42ad8..8e162ab 100644 --- a/internal/theme/wp/components/widgetareadata.go +++ b/internal/theme/wp/components/widgetareadata.go @@ -22,11 +22,6 @@ var widgetFn = map[string]wp.Components[string]{ "meta": {Fn: widget.Meta, CacheKey: "widgetMeta"}, } -type Widget struct { - Fn func(*wp.Handle) string - CacheKey string -} - func WidgetArea(h *wp.Handle) { sidebar := reload.GetAnyValBys("sidebarWidgets", h, sidebars) h.PushComponents(constraints.SidebarsWidgets, sidebar...) @@ -48,23 +43,23 @@ func sidebars(h *wp.Handle) []wp.Components[string] { id := ss[len(ss)-1] name := strings.Join(ss[0:len(ss)-1], "-") components, 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)) - } - for k, val := range args { - wp.SetComponentsArgsForMap(h, name, k, val) - } - components.Order = 10 - return components, true + if !ok { + return components, false } - return components, false + 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)) + } + for k, val := range args { + wp.SetComponentsArgsForMap(h, name, k, val) + } + components.Order = 10 + return components, true }) }