From 471a58658f92599dcb8e78388ab8b010b5568919 Mon Sep 17 00:00:00 2001 From: xing Date: Tue, 9 May 2023 00:44:56 +0800 Subject: [PATCH] fix bug --- app/theme/twentyfifteen/themesupport.go | 66 +++++++++++++++++++++++ app/theme/twentyseventeen/themesupport.go | 63 ++++++++++++++++++++++ app/theme/wp/pipe.go | 12 ++--- app/wpconfig/thememods.go | 22 ++++---- 4 files changed, 147 insertions(+), 16 deletions(-) diff --git a/app/theme/twentyfifteen/themesupport.go b/app/theme/twentyfifteen/themesupport.go index d731874..4f1d425 100644 --- a/app/theme/twentyfifteen/themesupport.go +++ b/app/theme/twentyfifteen/themesupport.go @@ -1,5 +1,7 @@ package twentyfifteen +import "github.com/fthvgb1/wp-go/app/wpconfig" + type themeSupport struct { CustomBackground customBackground `json:"custom-background"` EditorColorPalette []EditorColorPalette `json:"editor-color-palette"` @@ -227,3 +229,67 @@ var colorscheme = map[string]ColorScheme{ }, }, } + +var _ = func() struct{} { + v := wpconfig.ThemeSupport{ + CoreBlockPatterns: true, + WidgetsBlockEditor: true, + AutomaticFeedLinks: true, + TitleTag: true, + PostThumbnails: true, + Menus: true, + HTML5: []string{ + "search-form", + "comment-form", + "comment-list", + "gallery", + "caption", + "script", + "style", + "navigation-widgets", + }, + PostFormats: []string{ + "aside", + "image", + "video", + "quote", + "link", + "gallery", + "status", + "audio", + "chat", + }, + CustomLogo: wpconfig.CustomLogo{ + Width: 248, + Height: 248, + FlexWidth: false, + FlexHeight: true, + HeaderText: "", + UnlinkHomepageLogo: false, + }, + CustomizeSelectiveRefreshWidgets: true, + EditorStyle: true, + EditorStyles: true, + WpBlockStyles: true, + ResponsiveEmbeds: true, + CustomHeader: wpconfig.CustomHeader{ + DefaultImage: "", + RandomDefault: false, + Width: 954, + Height: 1300, + FlexHeight: false, + FlexWidth: false, + DefaultTextColor: "333333", + HeaderText: true, + Uploads: true, + WpHeadCallback: "twentyfifteen_header_style", + AdminHeadCallback: "", + AdminPreviewCallback: "", + Video: false, + VideoActiveCallback: "is_front_page", + }, + Widgets: true, + } + wpconfig.SetThemeSupport(ThemeName, v) + return struct{}{} +}() diff --git a/app/theme/twentyseventeen/themesupport.go b/app/theme/twentyseventeen/themesupport.go index 50aab9b..d0ee1eb 100644 --- a/app/theme/twentyseventeen/themesupport.go +++ b/app/theme/twentyseventeen/themesupport.go @@ -1,5 +1,7 @@ package twentyseventeen +import "github.com/fthvgb1/wp-go/app/wpconfig" + type themeSupport struct { CustomLineHeight bool `json:"custom-line-height"` StarterContent StarterContent `json:"starter-content"` @@ -147,3 +149,64 @@ var themesupport = themeSupport{ }, }, } + +var _ = func() struct{} { + v := wpconfig.ThemeSupport{ + CoreBlockPatterns: true, + WidgetsBlockEditor: true, + AutomaticFeedLinks: true, + TitleTag: true, + PostThumbnails: true, + Menus: true, + HTML5: []string{ + "comment-form", + "comment-list", + "gallery", + "caption", + "script", + "style", + "navigation-widgets", + }, + PostFormats: []string{ + "aside", + "image", + "video", + "quote", + "link", + "gallery", + "audio", + }, + CustomLogo: wpconfig.CustomLogo{ + Width: 250, + Height: 250, + FlexWidth: true, + FlexHeight: false, + HeaderText: "", + UnlinkHomepageLogo: false, + }, + CustomizeSelectiveRefreshWidgets: true, + EditorStyle: true, + EditorStyles: true, + WpBlockStyles: true, + ResponsiveEmbeds: true, + CustomHeader: wpconfig.CustomHeader{ + DefaultImage: "http://wp.test/wp-content/themes/twentyseventeen/assets/images/header.jpg", + RandomDefault: false, + Width: 2000, + Height: 1200, + FlexHeight: true, + FlexWidth: false, + DefaultTextColor: "", + HeaderText: true, + Uploads: true, + WpHeadCallback: "twentyseventeen_header_style", + AdminHeadCallback: "", + AdminPreviewCallback: "", + Video: true, + VideoActiveCallback: "is_front_page", + }, + Widgets: true, + } + wpconfig.SetThemeSupport(ThemeName, v) + return struct{}{} +}() diff --git a/app/theme/wp/pipe.go b/app/theme/wp/pipe.go index ec2237e..af94943 100644 --- a/app/theme/wp/pipe.go +++ b/app/theme/wp/pipe.go @@ -139,14 +139,14 @@ func MiddlewareKey(h *Handle, pipScene string) string { func PipeMiddlewareHandle(h *Handle, middlewares map[string][]HandleCall, key string) (handlers []HandleCall) { handlers = append(handlers, middlewares[h.scene]...) handlers = append(handlers, middlewares[constraints.AllScene]...) - handlers = h.PipeHandleHook("PipeMiddlewareHandle", handlers, key) + handlers = *h.PipeHandleHook("PipeMiddlewareHandle", &handlers, key) return } func PipeDataHandle(h *Handle, dataHandlers map[string][]HandleCall, key string) (handlers []HandleCall) { handlers = append(handlers, dataHandlers[h.scene]...) handlers = append(handlers, dataHandlers[constraints.AllScene]...) - handlers = h.PipeHandleHook("PipeDataHandle", handlers, key) + handlers = *h.PipeHandleHook("PipeDataHandle", &handlers, key) return } @@ -155,7 +155,7 @@ func PipeRender(h *Handle, renders map[string][]HandleCall, key string) (handler handlers = append(handlers, renders[h.scene]...) handlers = append(handlers, renders[constraints.AllStats]...) handlers = append(handlers, renders[constraints.AllScene]...) - handlers = h.PipeHandleHook("PipeRender", handlers, key) + handlers = *h.PipeHandleHook("PipeRender", &handlers, key) return } @@ -185,9 +185,9 @@ func (h *Handle) PushPipeHandleHook(name string, fn ...func([]HandleCall) []Hand return PushFnHook("pipeHandleHook", name, fn...) } -func (h *Handle) PipeHandleHook(name string, calls []HandleCall, key string) []HandleCall { - fn := GetFnHook[func(*Handle, []HandleCall, string) []HandleCall]("pipeHandleHook", name) - return slice.Reduce(fn, func(t func(*Handle, []HandleCall, string) []HandleCall, r []HandleCall) []HandleCall { +func (h *Handle) PipeHandleHook(name string, calls *[]HandleCall, key string) *[]HandleCall { + fn := GetFnHook[func(*Handle, *[]HandleCall, string) *[]HandleCall]("pipeHandleHook", name) + return slice.Reduce(fn, func(t func(*Handle, *[]HandleCall, string) *[]HandleCall, r *[]HandleCall) *[]HandleCall { return t(h, r, key) }, calls) } diff --git a/app/wpconfig/thememods.go b/app/wpconfig/thememods.go index ac0dc55..90c0db8 100644 --- a/app/wpconfig/thememods.go +++ b/app/wpconfig/thememods.go @@ -2,7 +2,6 @@ package wpconfig import ( "embed" - "encoding/json" "fmt" "github.com/fthvgb1/wp-go/app/cmd/reload" "github.com/fthvgb1/wp-go/app/phphelper" @@ -122,6 +121,12 @@ var themeModes = func() *safety.Map[string, ThemeMods] { var themeModsRaw *safety.Map[string, map[string]any] +var themeSupport = map[string]ThemeSupport{} + +func SetThemeSupport(theme string, support ThemeSupport) { + themeSupport[theme] = support +} + func GetThemeModsVal[T any](theme, k string, defaults T) (r T) { m, ok := themeModsRaw.Load(theme) if !ok { @@ -170,14 +175,11 @@ func IsCustomBackground(theme string) bool { } func (m *ThemeMods) setThemeSupport(themeName string) { - bytes, err := templateFs.ReadFile(filepath.Join(themeName, "themesupport.json")) - if err != nil { - return + var v ThemeSupport + vv, ok := themeSupport[themeName] + if ok { + m.ThemeSupport = vv + } else { + m.ThemeSupport = v } - var themeSupport ThemeSupport - err = json.Unmarshal(bytes, &themeSupport) - if err != nil { - return - } - m.ThemeSupport = themeSupport }