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
}
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 {
i, _ := fmt.Fprintf(b, format, a...)
return i

View File

@ -6,7 +6,6 @@ import (
str "github.com/fthvgb1/wp-go/helper/strings"
"github.com/fthvgb1/wp-go/internal/theme/wp"
"github.com/fthvgb1/wp-go/internal/wpconfig"
"strings"
)
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))
reducedSaturation := fmt.Sprintf("%d%%", int(.8*50))
saturation := fmt.Sprintf("%d%%", 50)
css := customCss
for k, v := range map[string]string{
css := str.Replace(customCss, map[string]string{
"' . $hue . '": hue,
"' . esc_attr( $hue ) . '": hue,
"' . $saturation . '": saturation,
"' . esc_attr( $saturation ) .' ": saturation,
"' . $reduced_saturation . '": reducedSaturation,
} {
css = strings.ReplaceAll(css, k, v)
}
})
s.Sprintf(`<style type="text/css" id="custom-theme-colors">%s</style>`, css)
r = s.String()
return