This commit is contained in:
xing 2023-05-09 00:44:56 +08:00
parent 68c345f928
commit 471a58658f
4 changed files with 147 additions and 16 deletions

View File

@ -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{}{}
}()

View File

@ -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{}{}
}()

View File

@ -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)
}

View File

@ -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
}