From 2ca1f10bfc013274ce2769ba03b47efcf2d5160b Mon Sep 17 00:00:00 2001 From: xing Date: Wed, 1 Mar 2023 23:01:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper/strings/strings.go | 7 +++++++ internal/theme/twentyseventeen/colorscheme.go | 8 ++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/helper/strings/strings.go b/helper/strings/strings.go index 38781c1..0d6a680 100644 --- a/helper/strings/strings.go +++ b/helper/strings/strings.go @@ -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 diff --git a/internal/theme/twentyseventeen/colorscheme.go b/internal/theme/twentyseventeen/colorscheme.go index 300087a..1d8aaf5 100644 --- a/internal/theme/twentyseventeen/colorscheme.go +++ b/internal/theme/twentyseventeen/colorscheme.go @@ -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(``, css) r = s.String() return