完善 bodyclass
This commit is contained in:
parent
a635b9a8ea
commit
49b51dadcb
|
@ -2,7 +2,6 @@ package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fthvgb1/wp-go/helper/maps"
|
|
||||||
"github.com/fthvgb1/wp-go/helper/slice"
|
"github.com/fthvgb1/wp-go/helper/slice"
|
||||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
"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 ",
|
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() {
|
func (h *Handle) CalBodyClass() {
|
||||||
h.GinH["bodyClass"] = h.bodyClass(h.Class...)
|
h.GinH["bodyClass"] = h.bodyClass(h.Class...)
|
||||||
}
|
}
|
||||||
|
@ -46,6 +29,7 @@ func (h *Handle) bodyClass(class ...string) string {
|
||||||
if constraints.Ok != h.Stats {
|
if constraints.Ok != h.Stats {
|
||||||
return "error404"
|
return "error404"
|
||||||
}
|
}
|
||||||
|
mods, err := wpconfig.GetThemeMods(h.Theme)
|
||||||
switch h.Scene {
|
switch h.Scene {
|
||||||
case constraints.Search:
|
case constraints.Search:
|
||||||
s = "search-no-results"
|
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)
|
s = fmt.Sprintf("category-%v category-%v", s, cate.Terms.TermId)
|
||||||
case constraints.Detail:
|
case constraints.Detail:
|
||||||
s = fmt.Sprintf("postid-%d", h.GinH["post"].(models.Posts).Id)
|
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")
|
s = str.Join(s, " single-format-standard")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class = append(class, s)
|
class = append(class, s)
|
||||||
mods, err := wpconfig.GetThemeMods(h.Theme)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if wpconfig.IsCustomBackground(h.Theme) {
|
if wpconfig.IsCustomBackground(h.Theme) {
|
||||||
class = append(class, "custom-background")
|
class = append(class, "custom-background")
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
func InitTheme() {
|
func InitTheme() {
|
||||||
addThemeHookFunc(twentyfifteen.ThemeName, twentyfifteen.Hook)
|
addThemeHookFunc(twentyfifteen.ThemeName, twentyfifteen.Hook)
|
||||||
addThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook)
|
addThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook)
|
||||||
common.AddThemeSupport(twentyfifteen.ThemeName, twentyfifteen.ThemeSupport())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Reload() {
|
func Reload() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user