diff --git a/internal/theme/common/customcss.go b/internal/theme/common/customcss.go new file mode 100644 index 0000000..3af457b --- /dev/null +++ b/internal/theme/common/customcss.go @@ -0,0 +1,33 @@ +package common + +import ( + "fmt" + "github.com/fthvgb1/wp-go/helper/html" + "github.com/fthvgb1/wp-go/internal/pkg/cache" + "github.com/fthvgb1/wp-go/internal/wpconfig" + "github.com/fthvgb1/wp-go/safety" +) + +var css = safety.NewVar("default") + +func (h *Handle) CalCustomCss() (r string) { + mods, err := wpconfig.GetThemeMods(h.Theme) + if err != nil || mods.CustomCssPostId < 1 { + return + } + post, err := cache.GetPostById(h.C, uint64(mods.CustomCssPostId)) + if err != nil || post.Id < 1 { + return + } + r = fmt.Sprintf(``, html.StripTags(post.PostContent, "")) + return +} + +func (h *Handle) CustomCss() { + cs := css.Load() + if cs == "default" { + cs = h.CalCustomCss() + css.Store(cs) + } + h.GinH["customCss"] = cs +} diff --git a/internal/theme/common/detail.go b/internal/theme/common/detail.go index c5801ca..9decf6b 100644 --- a/internal/theme/common/detail.go +++ b/internal/theme/common/detail.go @@ -99,6 +99,7 @@ func (d *DetailHandle) Render() { } d.SiteIcon() d.CustomLogo() + d.CustomCss() d.RenderComment() d.CalBodyClass() if d.Templ == "" { diff --git a/internal/theme/common/index.go b/internal/theme/common/index.go index 2ebf47f..17d0a07 100644 --- a/internal/theme/common/index.go +++ b/internal/theme/common/index.go @@ -114,6 +114,7 @@ func (i *IndexHandle) Render() { i.Pagination() i.SiteIcon() i.CustomLogo() + i.CustomCss() i.CalBodyClass() if i.Templ == "" { i.Templ = fmt.Sprintf("%s/posts/index.gohtml", i.Theme) diff --git a/internal/theme/common/reload.go b/internal/theme/common/reload.go index ce7d291..27ffc32 100644 --- a/internal/theme/common/reload.go +++ b/internal/theme/common/reload.go @@ -3,4 +3,5 @@ package common func Reload() { backgroud.Store("default") icon.Store("default") + css.Store("default") } diff --git a/internal/theme/twentyfifteen/layout/head.gohtml b/internal/theme/twentyfifteen/layout/head.gohtml index 9db72e0..4085965 100644 --- a/internal/theme/twentyfifteen/layout/head.gohtml +++ b/internal/theme/twentyfifteen/layout/head.gohtml @@ -68,5 +68,8 @@ {{if .siteIcon}} {{.siteIcon|unescaped}} {{end}} + {{if .customCss}} + {{.customCss|unescaped}} + {{end}} {{end}} \ No newline at end of file