Compare commits
No commits in common. "cd5a9eadd76aaea912f558f3cfa279d32cced570" and "a635b9a8eaa4d17c3cacc4e9b1866ae051322894" have entirely different histories.
cd5a9eadd7
...
a635b9a8ea
@ -2,6 +2,7 @@ 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"
|
||||||
@ -20,6 +21,22 @@ 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...)
|
||||||
}
|
}
|
||||||
@ -29,7 +46,6 @@ 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"
|
||||||
@ -50,12 +66,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 len(mods.ThemeSupport.PostFormats) > 0 {
|
if h.IsSupport("post-formats") {
|
||||||
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")
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
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,7 +99,6 @@ func (d *DetailHandle) Render() {
|
|||||||
}
|
}
|
||||||
d.SiteIcon()
|
d.SiteIcon()
|
||||||
d.CustomLogo()
|
d.CustomLogo()
|
||||||
d.CustomCss()
|
|
||||||
d.RenderComment()
|
d.RenderComment()
|
||||||
d.CalBodyClass()
|
d.CalBodyClass()
|
||||||
if d.Templ == "" {
|
if d.Templ == "" {
|
||||||
|
@ -114,7 +114,6 @@ func (i *IndexHandle) Render() {
|
|||||||
i.Pagination()
|
i.Pagination()
|
||||||
i.SiteIcon()
|
i.SiteIcon()
|
||||||
i.CustomLogo()
|
i.CustomLogo()
|
||||||
i.CustomCss()
|
|
||||||
i.CalBodyClass()
|
i.CalBodyClass()
|
||||||
if i.Templ == "" {
|
if i.Templ == "" {
|
||||||
i.Templ = fmt.Sprintf("%s/posts/index.gohtml", i.Theme)
|
i.Templ = fmt.Sprintf("%s/posts/index.gohtml", i.Theme)
|
||||||
|
@ -3,5 +3,4 @@ package common
|
|||||||
func Reload() {
|
func Reload() {
|
||||||
backgroud.Store("default")
|
backgroud.Store("default")
|
||||||
icon.Store("default")
|
icon.Store("default")
|
||||||
css.Store("default")
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ 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() {
|
||||||
|
@ -68,8 +68,5 @@
|
|||||||
{{if .siteIcon}}
|
{{if .siteIcon}}
|
||||||
{{.siteIcon|unescaped}}
|
{{.siteIcon|unescaped}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .customCss}}
|
|
||||||
{{.customCss|unescaped}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
Loading…
Reference in New Issue
Block a user