From 7d95109e786b1916ede9b2b9fba520fc1a2a08ed Mon Sep 17 00:00:00 2001 From: xing Date: Fri, 17 Feb 2023 00:20:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84twenty=20seventeen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/theme/common/customlogo.go | 6 +- internal/theme/common/template.gohtml | 21 +++ internal/theme/fs.go | 2 +- .../theme/twentyfifteen/layout/base.gohtml | 4 +- .../theme/twentyfifteen/layout/head.gohtml | 14 +- internal/theme/twentyfifteen/twentyfifteen.go | 29 ---- .../theme/twentyseventeen/layout/base.gohtml | 1 + .../theme/twentyseventeen/layout/head.gohtml | 3 + .../theme/twentyseventeen/themesupport.json | 134 ++++++++++++++++++ .../theme/twentyseventeen/twentyseventeen.go | 23 +-- internal/wpconfig/thememods.go | 12 +- internal/wpconfig/themesupport.go | 83 ++++++++++- 12 files changed, 257 insertions(+), 75 deletions(-) create mode 100644 internal/theme/common/template.gohtml create mode 100644 internal/theme/twentyseventeen/themesupport.json diff --git a/internal/theme/common/customlogo.go b/internal/theme/common/customlogo.go index b2f6831..5702cd3 100644 --- a/internal/theme/common/customlogo.go +++ b/internal/theme/common/customlogo.go @@ -3,6 +3,7 @@ package common import ( "fmt" "github.com/fthvgb1/wp-go/helper/maps" + str "github.com/fthvgb1/wp-go/helper/strings" "github.com/fthvgb1/wp-go/internal/pkg/cache" "github.com/fthvgb1/wp-go/internal/wpconfig" "github.com/fthvgb1/wp-go/safety" @@ -17,7 +18,10 @@ func (h *Handle) CalCustomLogo() (r string) { } id := uint64(mods.CustomLogo) if id < 1 { - return + id = str.ToInteger[uint64](wpconfig.Options.Value("site_logo"), 0) + if id < 1 { + return + } } logo, err := cache.GetPostById(h.C, id) if err != nil || logo.AttachmentMetadata.File == "" { diff --git a/internal/theme/common/template.gohtml b/internal/theme/common/template.gohtml new file mode 100644 index 0000000..be79074 --- /dev/null +++ b/internal/theme/common/template.gohtml @@ -0,0 +1,21 @@ +{{define "common/head"}} + {{if .customBackground}} + {{.customBackground|unescaped}} + {{end}} + {{if .customHeader}} + {{.customHeader|unescaped}} + {{end}} + + {{if .siteIcon}} + {{.siteIcon|unescaped}} + {{end}} + {{if .customCss}} + {{.customCss|unescaped}} + {{end}} +{{end}} + +{{define "common/customLogo"}} + {{if .customLogo}} + {{.customLogo|unescaped}} + {{end}} +{{end}} \ No newline at end of file diff --git a/internal/theme/fs.go b/internal/theme/fs.go index b84499a..55ba6bb 100644 --- a/internal/theme/fs.go +++ b/internal/theme/fs.go @@ -33,7 +33,7 @@ func commonTemplate(t *multipTemplate.MultipleFsTemplate) { for _, main := range m { file := filepath.Base(main) dir := strings.Split(main, "/")[0] - templ := template.Must(template.New(file).Funcs(t.FuncMap).ParseFS(t.Fs, main, filepath.Join(dir, "layout/*.gohtml"))) + templ := template.Must(template.New(file).Funcs(t.FuncMap).ParseFS(t.Fs, main, filepath.Join(dir, "layout/*.gohtml"), "common/template.gohtml")) t.SetTemplate(main, templ) } } diff --git a/internal/theme/twentyfifteen/layout/base.gohtml b/internal/theme/twentyfifteen/layout/base.gohtml index 3e9531e..9c5558f 100644 --- a/internal/theme/twentyfifteen/layout/base.gohtml +++ b/internal/theme/twentyfifteen/layout/base.gohtml @@ -16,9 +16,7 @@