Compare commits
2 Commits
a635b9a8ea
...
cd5a9eadd7
Author | SHA1 | Date | |
---|---|---|---|
|
cd5a9eadd7 | ||
|
49b51dadcb |
@ -2,7 +2,6 @@ package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
||||
@ -21,22 +20,6 @@ var commonClass = map[int]string{
|
||||
constraints.Detail: "post-template-default single single-post ",
|
||||
}
|
||||
|
||||
type Support map[string]struct{}
|
||||
|
||||
var themeSupport = map[string]Support{}
|
||||
|
||||
func AddThemeSupport(theme string, support Support) {
|
||||
themeSupport[theme] = support
|
||||
}
|
||||
|
||||
func (h *Handle) IsSupport(name string) bool {
|
||||
m, ok := themeSupport[h.Theme]
|
||||
if ok {
|
||||
return maps.IsExists(m, name)
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
func (h *Handle) CalBodyClass() {
|
||||
h.GinH["bodyClass"] = h.bodyClass(h.Class...)
|
||||
}
|
||||
@ -46,6 +29,7 @@ func (h *Handle) bodyClass(class ...string) string {
|
||||
if constraints.Ok != h.Stats {
|
||||
return "error404"
|
||||
}
|
||||
mods, err := wpconfig.GetThemeMods(h.Theme)
|
||||
switch h.Scene {
|
||||
case constraints.Search:
|
||||
s = "search-no-results"
|
||||
@ -66,12 +50,12 @@ func (h *Handle) bodyClass(class ...string) string {
|
||||
s = fmt.Sprintf("category-%v category-%v", s, cate.Terms.TermId)
|
||||
case constraints.Detail:
|
||||
s = fmt.Sprintf("postid-%d", h.GinH["post"].(models.Posts).Id)
|
||||
if h.IsSupport("post-formats") {
|
||||
if len(mods.ThemeSupport.PostFormats) > 0 {
|
||||
s = str.Join(s, " single-format-standard")
|
||||
}
|
||||
}
|
||||
class = append(class, s)
|
||||
mods, err := wpconfig.GetThemeMods(h.Theme)
|
||||
|
||||
if err == nil {
|
||||
if wpconfig.IsCustomBackground(h.Theme) {
|
||||
class = append(class, "custom-background")
|
||||
|
33
internal/theme/common/customcss.go
Normal file
33
internal/theme/common/customcss.go
Normal file
@ -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(`<style id="wp-custom-css">%s</style>`, 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
|
||||
}
|
@ -99,6 +99,7 @@ func (d *DetailHandle) Render() {
|
||||
}
|
||||
d.SiteIcon()
|
||||
d.CustomLogo()
|
||||
d.CustomCss()
|
||||
d.RenderComment()
|
||||
d.CalBodyClass()
|
||||
if d.Templ == "" {
|
||||
|
@ -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)
|
||||
|
@ -3,4 +3,5 @@ package common
|
||||
func Reload() {
|
||||
backgroud.Store("default")
|
||||
icon.Store("default")
|
||||
css.Store("default")
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
func InitTheme() {
|
||||
addThemeHookFunc(twentyfifteen.ThemeName, twentyfifteen.Hook)
|
||||
addThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook)
|
||||
common.AddThemeSupport(twentyfifteen.ThemeName, twentyfifteen.ThemeSupport())
|
||||
}
|
||||
|
||||
func Reload() {
|
||||
|
@ -68,5 +68,8 @@
|
||||
{{if .siteIcon}}
|
||||
{{.siteIcon|unescaped}}
|
||||
{{end}}
|
||||
{{if .customCss}}
|
||||
{{.customCss|unescaped}}
|
||||
{{end}}
|
||||
|
||||
{{end}}
|
Loading…
Reference in New Issue
Block a user