From e1d8c0098fb2eaaaa2f869b684592a5f6d1ba581 Mon Sep 17 00:00:00 2001 From: xing Date: Tue, 28 Feb 2023 19:44:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84seventeen=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0customheader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/theme/common/common.go | 1 + .../theme/twentyseventeen/customheader.go | 47 +++++++++++++++++++ .../theme/twentyseventeen/twentyseventeen.go | 10 +++- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 internal/theme/twentyseventeen/customheader.go diff --git a/internal/theme/common/common.go b/internal/theme/common/common.go index 9dd934b..fd238c9 100644 --- a/internal/theme/common/common.go +++ b/internal/theme/common/common.go @@ -43,6 +43,7 @@ func NewHandle(c *gin.Context, scene int, theme string) *Handle { Stats: constraints.Ok, ThemeMods: mods, Components: make(map[string][]Components), + HandleFns: make(map[int][]HandleFn[*Handle]), } } diff --git a/internal/theme/twentyseventeen/customheader.go b/internal/theme/twentyseventeen/customheader.go new file mode 100644 index 0000000..366afb4 --- /dev/null +++ b/internal/theme/twentyseventeen/customheader.go @@ -0,0 +1,47 @@ +package twentyseventeen + +import ( + "fmt" + "github.com/fthvgb1/wp-go/internal/theme/common" +) + +func customHeader(h *common.Handle) (r string) { + headerTextColor := h.ThemeMods.HeaderTextcolor + if headerTextColor == "" || headerTextColor == h.ThemeMods.ThemeSupport.CustomHeader.DefaultTextColor { + return + } + css := ` + .site-title, + .site-description { + position: absolute; + clip: rect(1px, 1px, 1px, 1px); + }` + if headerTextColor != "blank" { + css = fmt.Sprintf(customHeaderCss, headerTextColor) + } + r = fmt.Sprintf(``, css) + return +} + +var customHeaderCss = ` + .site-title a, + .colors-dark .site-title a, + .colors-custom .site-title a, + body.has-header-image .site-title a, + body.has-header-video .site-title a, + body.has-header-image.colors-dark .site-title a, + body.has-header-video.colors-dark .site-title a, + body.has-header-image.colors-custom .site-title a, + body.has-header-video.colors-custom .site-title a, + .site-description, + .colors-dark .site-description, + .colors-custom .site-description, + body.has-header-image .site-description, + body.has-header-video .site-description, + body.has-header-image.colors-dark .site-description, + body.has-header-video.colors-dark .site-description, + body.has-header-image.colors-custom .site-description, + body.has-header-video.colors-custom .site-description { + color: #%s; + } +` diff --git a/internal/theme/twentyseventeen/twentyseventeen.go b/internal/theme/twentyseventeen/twentyseventeen.go index c11d50e..46e18d9 100644 --- a/internal/theme/twentyseventeen/twentyseventeen.go +++ b/internal/theme/twentyseventeen/twentyseventeen.go @@ -27,20 +27,26 @@ var paginate = func() plugins.PageEle { return p }() -var pipe = common.HandlePipe(common.Render, dispatch) +var pipe = common.HandlePipe(common.Render, ready, dispatch) func Hook(h *common.Handle) { pipe(h) } -func dispatch(next common.HandleFn[*common.Handle], h *common.Handle) { +func ready(next common.HandleFn[*common.Handle], h *common.Handle) { h.WidgetAreaData() h.GetPassword() h.PushHandleFn(constraints.AllStats, calClass) h.PushHeadScript( common.NewComponents(colorScheme, 10), + common.NewComponents(customHeader, 10), ) h.GinH["HeaderImage"] = getHeaderImage(h) + h.GinH["scene"] = h.Scene + next(h) +} + +func dispatch(next common.HandleFn[*common.Handle], h *common.Handle) { switch h.Scene { case constraints.Detail: detail(next, h.Detail)