diff --git a/internal/cmd/main.go b/internal/cmd/main.go index 3f1f339..9afcb3c 100644 --- a/internal/cmd/main.go +++ b/internal/cmd/main.go @@ -11,7 +11,6 @@ import ( "github.com/fthvgb1/wp-go/internal/pkg/logs" "github.com/fthvgb1/wp-go/internal/plugins" "github.com/fthvgb1/wp-go/internal/theme" - "github.com/fthvgb1/wp-go/internal/theme/common" "github.com/fthvgb1/wp-go/internal/wpconfig" "github.com/fthvgb1/wp-go/model" "log" @@ -107,7 +106,7 @@ func reload() { logs.ErrPrintln(err, "获取网站设置WpOption失败") err = wpconfig.InitTerms() wpconfig.FlushModes() - common.Reload() + theme.Reload() logs.ErrPrintln(err, "获取WpTerms表失败") if middleWareReloadFn != nil { middleWareReloadFn() diff --git a/internal/theme/common/customheader.go b/internal/theme/common/customheader.go new file mode 100644 index 0000000..62ea0a4 --- /dev/null +++ b/internal/theme/common/customheader.go @@ -0,0 +1,33 @@ +package common + +import ( + "github.com/fthvgb1/wp-go/helper/slice" + "github.com/fthvgb1/wp-go/internal/pkg/cache" + "github.com/fthvgb1/wp-go/internal/pkg/logs" + "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/internal/wpconfig" +) + +func (h *Handle) DisplayHeaderText() bool { + mods, err := wpconfig.GetThemeMods(h.Theme) + if err != nil { + return false + } + return mods.ThemeSupport.CustomHeader.HeaderText && "blank" != mods.HeaderTextcolor +} + +func (h *Handle) GetCustomHeader() (r models.PostThumbnail, isRand bool) { + hs, err := cache.GetHeaderImages(h.C, h.Theme) + if err != nil { + logs.ErrPrintln(err, "获取页眉背景图失败") + return + } + if len(hs) < 1 { + return + } + if len(hs) > 1 { + isRand = true + } + r, _ = slice.RandPop(&hs) + return +} diff --git a/internal/theme/common/reload.go b/internal/theme/common/reload.go index ea008b4..93eb97a 100644 --- a/internal/theme/common/reload.go +++ b/internal/theme/common/reload.go @@ -1,5 +1,5 @@ package common func Reload() { - backgroud.Flush() + backgroud.Store("default") } diff --git a/internal/theme/theme.go b/internal/theme/theme.go index 8f7cb1d..0f3b5b3 100644 --- a/internal/theme/theme.go +++ b/internal/theme/theme.go @@ -14,6 +14,11 @@ func InitTheme() { common.AddThemeSupport(twentyfifteen.ThemeName, twentyfifteen.ThemeSupport()) } +func Reload() { + twentyfifteen.Reload() + common.Reload() +} + func GetTemplateName() string { tmlp := config.GetConfig().Theme if tmlp == "" { diff --git a/internal/theme/twentyfifteen/customheader.go b/internal/theme/twentyfifteen/customheader.go new file mode 100644 index 0000000..a005f3f --- /dev/null +++ b/internal/theme/twentyfifteen/customheader.go @@ -0,0 +1,124 @@ +package twentyfifteen + +import ( + str "github.com/fthvgb1/wp-go/helper/strings" + "github.com/fthvgb1/wp-go/safety" +) + +var style = `") + r = ss.String() + return +} + +func (h *handle) CustomHeader() { + headers := header.Load() + if headers == "default" { + headerss, rand := h.CalCustomHeader() + headers = headerss + if !rand { + header.Store(headers) + } + } + h.IndexHandle.GinH["customHeader"] = headers + return +} diff --git a/internal/theme/twentyfifteen/layout/head.gohtml b/internal/theme/twentyfifteen/layout/head.gohtml index 0b1bcdc..d243e25 100644 --- a/internal/theme/twentyfifteen/layout/head.gohtml +++ b/internal/theme/twentyfifteen/layout/head.gohtml @@ -61,4 +61,7 @@ {{if .customBackground}} {{.customBackground|unescaped}} {{end}} + {{if .customHeader}} + {{.customHeader|unescaped}} + {{end}} {{end}} \ No newline at end of file diff --git a/internal/theme/twentyfifteen/twentyfifteen.go b/internal/theme/twentyfifteen/twentyfifteen.go index 609302d..17cf800 100644 --- a/internal/theme/twentyfifteen/twentyfifteen.go +++ b/internal/theme/twentyfifteen/twentyfifteen.go @@ -12,12 +12,13 @@ import ( const ThemeName = "twentyfifteen" -type indexHandle struct { +type handle struct { *common.IndexHandle + *common.DetailHandle } -func newIndexHandle(iHandle *common.IndexHandle) *indexHandle { - return &indexHandle{iHandle} +func newHandle(iHandle *common.IndexHandle, dHandle *common.DetailHandle) *handle { + return &handle{iHandle, dHandle} } type detailHandle struct { @@ -31,19 +32,22 @@ func newDetailHandle(dHandle *common.DetailHandle) *detailHandle { func Hook(h *common.Handle) { h.WidgetAreaData() h.GetPassword() + handle := newHandle(common.NewIndexHandle(h), common.NewDetailHandle(h)) if h.Scene == constraints.Detail { - newDetailHandle(common.NewDetailHandle(h)).Detail() + handle.Detail() return } - newIndexHandle(common.NewIndexHandle(h)).Index() + handle.Index() } -func (i *indexHandle) Index() { - i.Indexs() +func (h *handle) Index() { + h.CustomHeader() + h.Indexs() } -func (d *detailHandle) Detail() { - d.Details() +func (h *handle) Detail() { + h.CustomHeader() + h.Details() } func getHeaderImage(c *gin.Context) (r models.PostThumbnail) { diff --git a/internal/wpconfig/thememods.go b/internal/wpconfig/thememods.go index 582e6b9..f5b213f 100644 --- a/internal/wpconfig/thememods.go +++ b/internal/wpconfig/thememods.go @@ -114,6 +114,7 @@ func GetThemeMods(theme string) (r ThemeMods, err error) { return } r.setThemeColorScheme(theme) + r.setThemeSupport(theme) themeModes.Store(theme, r) return }