This commit is contained in:
xing 2023-03-01 23:01:38 +08:00
parent ae20829209
commit 2ca1f10bfc
2 changed files with 9 additions and 6 deletions

View File

@ -78,6 +78,13 @@ func (b *Builder) WriteString(s ...string) (count int) {
} }
return return
} }
func Replace(s string, replace map[string]string) string {
for k, v := range replace {
s = strings.ReplaceAll(s, k, v)
}
return s
}
func (b *Builder) Sprintf(format string, a ...any) int { func (b *Builder) Sprintf(format string, a ...any) int {
i, _ := fmt.Fprintf(b, format, a...) i, _ := fmt.Fprintf(b, format, a...)
return i return i

View File

@ -6,7 +6,6 @@ import (
str "github.com/fthvgb1/wp-go/helper/strings" str "github.com/fthvgb1/wp-go/helper/strings"
"github.com/fthvgb1/wp-go/internal/theme/wp" "github.com/fthvgb1/wp-go/internal/theme/wp"
"github.com/fthvgb1/wp-go/internal/wpconfig" "github.com/fthvgb1/wp-go/internal/wpconfig"
"strings"
) )
func colorScheme(h *wp.Handle) (r string) { func colorScheme(h *wp.Handle) (r string) {
@ -17,16 +16,13 @@ func colorScheme(h *wp.Handle) (r string) {
hue := number.ToString(wpconfig.GetThemeModsVal[int64](ThemeName, "colorscheme_hue", 250)) hue := number.ToString(wpconfig.GetThemeModsVal[int64](ThemeName, "colorscheme_hue", 250))
reducedSaturation := fmt.Sprintf("%d%%", int(.8*50)) reducedSaturation := fmt.Sprintf("%d%%", int(.8*50))
saturation := fmt.Sprintf("%d%%", 50) saturation := fmt.Sprintf("%d%%", 50)
css := customCss css := str.Replace(customCss, map[string]string{
for k, v := range map[string]string{
"' . $hue . '": hue, "' . $hue . '": hue,
"' . esc_attr( $hue ) . '": hue, "' . esc_attr( $hue ) . '": hue,
"' . $saturation . '": saturation, "' . $saturation . '": saturation,
"' . esc_attr( $saturation ) .' ": saturation, "' . esc_attr( $saturation ) .' ": saturation,
"' . $reduced_saturation . '": reducedSaturation, "' . $reduced_saturation . '": reducedSaturation,
} { })
css = strings.ReplaceAll(css, k, v)
}
s.Sprintf(`<style type="text/css" id="custom-theme-colors">%s</style>`, css) s.Sprintf(`<style type="text/css" id="custom-theme-colors">%s</style>`, css)
r = s.String() r = s.String()
return return