diff --git a/internal/theme/common/common.go b/internal/theme/common/common.go
index a9c6aba..9b41975 100644
--- a/internal/theme/common/common.go
+++ b/internal/theme/common/common.go
@@ -42,10 +42,14 @@ func NewHandle(c *gin.Context, scene int, theme string) *Handle {
}
}
-func (h *Handle) AutoCal(name string, fn func() string) {
+func (h *Handle) PushHandleFn(fns ...func(*Handle)) {
+ h.HandleFns = append(h.HandleFns, fns...)
+}
+
+func (h *Handle) AutoCal(name string, fn func(*Handle) string) {
v, ok := reload.GetStr(name)
if !ok {
- v = fn()
+ v = fn(h)
reload.SetStr(name, v)
}
h.GinH[name] = v
@@ -72,9 +76,9 @@ func (h *Handle) Render() {
for _, fn := range h.HandleFns {
fn(h)
}
- h.AutoCal("siteIcon", h.CalSiteIcon)
- h.AutoCal("customLogo", h.CalCustomLogo)
- h.AutoCal("customCss", h.CalCustomCss)
+ h.AutoCal("siteIcon", CalSiteIcon)
+ h.AutoCal("customLogo", CalCustomLogo)
+ h.AutoCal("customCss", CalCustomCss)
h.CalBodyClass()
h.C.HTML(h.Code, h.Templ, h.GinH)
diff --git a/internal/theme/common/customcss.go b/internal/theme/common/customcss.go
index 3dce6ed..226e156 100644
--- a/internal/theme/common/customcss.go
+++ b/internal/theme/common/customcss.go
@@ -6,7 +6,7 @@ import (
"github.com/fthvgb1/wp-go/internal/pkg/cache"
)
-func (h *Handle) CalCustomCss() (r string) {
+func CalCustomCss(h *Handle) (r string) {
if h.ThemeMods.CustomCssPostId < 1 {
return
}
diff --git a/internal/theme/common/customlogo.go b/internal/theme/common/customlogo.go
index b731c04..a0d66b7 100644
--- a/internal/theme/common/customlogo.go
+++ b/internal/theme/common/customlogo.go
@@ -8,7 +8,7 @@ import (
"github.com/fthvgb1/wp-go/internal/wpconfig"
)
-func (h *Handle) CalCustomLogo() (r string) {
+func CalCustomLogo(h *Handle) (r string) {
id := uint64(h.ThemeMods.CustomLogo)
if id < 1 {
id = str.ToInteger[uint64](wpconfig.GetOption("site_logo"), 0)
diff --git a/internal/theme/common/siteicon.go b/internal/theme/common/siteicon.go
index 46e79e3..0e77b22 100644
--- a/internal/theme/common/siteicon.go
+++ b/internal/theme/common/siteicon.go
@@ -11,7 +11,7 @@ import (
var sizes = []string{"site_icon-270", "site_icon-32", "site_icon-192", "site_icon-180"}
-func (h *Handle) CalSiteIcon() (r string) {
+func CalSiteIcon(h *Handle) (r string) {
id := str.ToInteger[uint64](wpconfig.GetOption("site_icon"), 0)
if id < 1 {
return
diff --git a/internal/theme/twentyfifteen/colorschemecss.go b/internal/theme/twentyfifteen/colorschemecss.go
index 5b3057c..d63416c 100644
--- a/internal/theme/twentyfifteen/colorschemecss.go
+++ b/internal/theme/twentyfifteen/colorschemecss.go
@@ -3,12 +3,13 @@ package twentyfifteen
import (
"fmt"
"github.com/fthvgb1/wp-go/helper/slice"
+ "github.com/fthvgb1/wp-go/internal/theme/common"
"strconv"
"strings"
)
-func (h *handle) colorSchemeCss() string {
- s := slice.Filter([]string{h.calColorSchemeCss(), h.calSidebarTextColorCss(), h.calHeaderBackgroundColorCss()}, func(s string) bool {
+func colorSchemeCss(h *common.Handle) string {
+ s := slice.Filter([]string{calColorSchemeCss(h), calSidebarTextColorCss(h), calHeaderBackgroundColorCss(h)}, func(s string) bool {
return s != ""
})
if len(s) < 1 {
@@ -16,9 +17,9 @@ func (h *handle) colorSchemeCss() string {
}
return fmt.Sprintf(``, "twentyfifteen-style", "", strings.Join(s, "\n"))
}
-func (h *handle) calColorSchemeCss() (r string) {
- color := h.getColorScheme()
- if "default" == h.IndexHandle.ThemeMods.ColorScheme || len(color) < 1 {
+func calColorSchemeCss(h *common.Handle) (r string) {
+ color := getColorScheme(h)
+ if "default" == h.ThemeMods.ColorScheme || len(color) < 1 {
return
}
textColorRgb := slice.ToAnySlice(Hex2RgbUint8(color[3]))
@@ -45,31 +46,31 @@ func (h *handle) calColorSchemeCss() (r string) {
return
}
-func (h *handle) calSidebarTextColorCss() (r string) {
- colors := h.getColorScheme()
- if h.IndexHandle.ThemeMods.SidebarTextcolor == "" || h.IndexHandle.ThemeMods.SidebarTextcolor == colors[4] {
+func calSidebarTextColorCss(h *common.Handle) (r string) {
+ colors := getColorScheme(h)
+ if h.ThemeMods.SidebarTextcolor == "" || h.ThemeMods.SidebarTextcolor == colors[4] {
return
}
- linkColorRgb := Hex2RgbUint8(h.IndexHandle.ThemeMods.SidebarTextcolor)
+ linkColorRgb := Hex2RgbUint8(h.ThemeMods.SidebarTextcolor)
color := slice.ToAnySlice(linkColorRgb)
textColor := fmt.Sprintf(`rgba( %[1]v, %[2]v, %[3]v, 0.7)`, color...)
borderColor := fmt.Sprintf(`rgba( %[1]v, %[2]v, %[3]v, 0.1)`, color...)
borderFocusColor := fmt.Sprintf(`rgba( %[1]v, %[2]v, %[3]v, 0.3)`, color...)
- r = fmt.Sprintf(sidebarTextColorTemplate, h.IndexHandle.ThemeMods.SidebarTextcolor, textColor, borderColor, borderFocusColor)
+ r = fmt.Sprintf(sidebarTextColorTemplate, h.ThemeMods.SidebarTextcolor, textColor, borderColor, borderFocusColor)
return
}
-func (h *handle) calHeaderBackgroundColorCss() (r string) {
- colors := h.getColorScheme()
- if h.IndexHandle.ThemeMods.HeaderBackgroundColor == "" || h.IndexHandle.ThemeMods.HeaderBackgroundColor == colors[1] {
+func calHeaderBackgroundColorCss(h *common.Handle) (r string) {
+ colors := getColorScheme(h)
+ if h.ThemeMods.HeaderBackgroundColor == "" || h.ThemeMods.HeaderBackgroundColor == colors[1] {
return
}
- r = fmt.Sprintf(headerBackgroundColorCssTemplate, h.IndexHandle.ThemeMods.HeaderBackgroundColor, h.IndexHandle.ThemeMods.HeaderBackgroundColor)
+ r = fmt.Sprintf(headerBackgroundColorCssTemplate, h.ThemeMods.HeaderBackgroundColor, h.ThemeMods.HeaderBackgroundColor)
return
}
-func (h *handle) getColorScheme() (r []string) {
- x, ok := colorscheme[h.IndexHandle.ThemeMods.ColorScheme]
+func getColorScheme(h *common.Handle) (r []string) {
+ x, ok := colorscheme[h.ThemeMods.ColorScheme]
if ok {
r = x.Colors
}
diff --git a/internal/theme/twentyfifteen/custombackground.go b/internal/theme/twentyfifteen/custombackground.go
index 68a141e..62216a3 100644
--- a/internal/theme/twentyfifteen/custombackground.go
+++ b/internal/theme/twentyfifteen/custombackground.go
@@ -5,6 +5,7 @@ import (
"github.com/fthvgb1/wp-go/helper"
"github.com/fthvgb1/wp-go/helper/maps"
str "github.com/fthvgb1/wp-go/helper/strings"
+ "github.com/fthvgb1/wp-go/internal/theme/common"
)
var postx = map[string]string{
@@ -29,30 +30,30 @@ var repeat = map[string]string{
"no-repeat": "no-repeat",
}
-func (h *handle) CalCustomBackGround() (r string) {
- if h.IndexHandle.ThemeMods.BackgroundImage == "" && h.IndexHandle.ThemeMods.BackgroundColor == themesupport.CustomBackground.DefaultColor {
+func CalCustomBackGround(h *common.Handle) (r string) {
+ if h.ThemeMods.BackgroundImage == "" && h.ThemeMods.BackgroundColor == themesupport.CustomBackground.DefaultColor {
return
}
s := str.NewBuilder()
- if h.IndexHandle.ThemeMods.BackgroundImage != "" {
- s.Sprintf(` background-image: url("%s");`, helper.CutUrlHost(h.IndexHandle.ThemeMods.BackgroundImage))
+ if h.ThemeMods.BackgroundImage != "" {
+ s.Sprintf(` background-image: url("%s");`, helper.CutUrlHost(h.ThemeMods.BackgroundImage))
}
- backgroundPositionX := helper.Defaults(h.IndexHandle.ThemeMods.BackgroundPositionX, themesupport.CustomBackground.DefaultPositionX)
+ backgroundPositionX := helper.Defaults(h.ThemeMods.BackgroundPositionX, themesupport.CustomBackground.DefaultPositionX)
backgroundPositionX = maps.WithDefaultVal(postx, backgroundPositionX, "left")
- backgroundPositionY := helper.Defaults(h.IndexHandle.ThemeMods.BackgroundPositionY, themesupport.CustomBackground.DefaultPositionY)
+ backgroundPositionY := helper.Defaults(h.ThemeMods.BackgroundPositionY, themesupport.CustomBackground.DefaultPositionY)
backgroundPositionY = maps.WithDefaultVal(posty, backgroundPositionY, "top")
positon := fmt.Sprintf(" background-position: %s %s;", backgroundPositionX, backgroundPositionY)
- siz := helper.DefaultVal(h.IndexHandle.ThemeMods.BackgroundSize, themesupport.CustomBackground.DefaultSize)
+ siz := helper.DefaultVal(h.ThemeMods.BackgroundSize, themesupport.CustomBackground.DefaultSize)
siz = maps.WithDefaultVal(size, siz, "auto")
siz = fmt.Sprintf(" background-size: %s;", siz)
- repeats := helper.Defaults(h.IndexHandle.ThemeMods.BackgroundRepeat, themesupport.CustomBackground.DefaultRepeat)
+ repeats := helper.Defaults(h.ThemeMods.BackgroundRepeat, themesupport.CustomBackground.DefaultRepeat)
repeats = maps.WithDefaultVal(repeat, repeats, "repeat")
repeats = fmt.Sprintf(" background-repeat: %s;", repeats)
- attachment := helper.Defaults(h.IndexHandle.ThemeMods.BackgroundAttachment, themesupport.CustomBackground.DefaultAttachment)
+ attachment := helper.Defaults(h.ThemeMods.BackgroundAttachment, themesupport.CustomBackground.DefaultAttachment)
attachment = helper.Or(attachment == "fixed", "fixed", "scroll")
attachment = fmt.Sprintf(" background-attachment: %s;", attachment)
s.WriteString(positon, siz, repeats, attachment)
diff --git a/internal/theme/twentyfifteen/customheader.go b/internal/theme/twentyfifteen/customheader.go
index 6543022..3ee0560 100644
--- a/internal/theme/twentyfifteen/customheader.go
+++ b/internal/theme/twentyfifteen/customheader.go
@@ -4,6 +4,7 @@ import (
str "github.com/fthvgb1/wp-go/helper/strings"
"github.com/fthvgb1/wp-go/internal/cmd/reload"
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
+ "github.com/fthvgb1/wp-go/internal/theme/common"
)
var style = `