2023-02-14 11:47:47 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2023-02-26 05:55:05 +00:00
|
|
|
"github.com/fthvgb1/wp-go/helper/number"
|
2023-02-14 11:47:47 +00:00
|
|
|
"github.com/fthvgb1/wp-go/helper/slice"
|
|
|
|
str "github.com/fthvgb1/wp-go/helper/strings"
|
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
|
|
|
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var commonClass = map[int]string{
|
2023-02-23 10:21:51 +00:00
|
|
|
constraints.Home: "home blog ",
|
|
|
|
constraints.Archive: "archive date ",
|
2023-02-14 11:47:47 +00:00
|
|
|
constraints.Category: "archive category ",
|
|
|
|
constraints.Tag: "archive category ",
|
2023-02-23 10:21:51 +00:00
|
|
|
constraints.Search: "search ",
|
2023-02-26 05:55:05 +00:00
|
|
|
constraints.Author: "archive author ",
|
2023-02-14 11:47:47 +00:00
|
|
|
constraints.Detail: "post-template-default single single-post ",
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handle) CalBodyClass() {
|
2023-02-23 09:26:20 +00:00
|
|
|
h.GinH["bodyClass"] = h.BodyClass(h.Class...)
|
2023-02-14 11:47:47 +00:00
|
|
|
}
|
|
|
|
|
2023-02-23 09:26:20 +00:00
|
|
|
func (h *Handle) BodyClass(class ...string) string {
|
2023-02-14 11:47:47 +00:00
|
|
|
if constraints.Ok != h.Stats {
|
|
|
|
return "error404"
|
|
|
|
}
|
|
|
|
switch h.Scene {
|
|
|
|
case constraints.Search:
|
2023-02-26 05:55:05 +00:00
|
|
|
s := "search-no-results"
|
|
|
|
if len(h.Index.Posts) > 0 {
|
2023-02-14 11:47:47 +00:00
|
|
|
s = "search-results"
|
|
|
|
}
|
2023-02-26 05:55:05 +00:00
|
|
|
class = append(class, s)
|
2023-02-14 11:47:47 +00:00
|
|
|
case constraints.Category, constraints.Tag:
|
2023-02-26 05:55:05 +00:00
|
|
|
cat := h.Index.Param.Category
|
2023-02-14 11:47:47 +00:00
|
|
|
_, cate := slice.SearchFirst(cache.CategoriesTags(h.C, h.Scene), func(my models.TermsMy) bool {
|
|
|
|
return my.Name == cat
|
|
|
|
})
|
|
|
|
if cate.Slug[0] != '%' {
|
2023-02-26 05:55:05 +00:00
|
|
|
class = append(class, str.Join("category-", cate.Slug))
|
|
|
|
}
|
|
|
|
class = append(class, str.Join("category-", number.ToString(cate.Terms.TermId)))
|
|
|
|
|
|
|
|
case constraints.Author:
|
|
|
|
author := h.Index.Param.Author
|
|
|
|
user, _ := cache.GetUserByName(h.C, author)
|
|
|
|
class = append(class, str.Join("author-", number.ToString(user.Id)))
|
|
|
|
if user.UserLogin[0] != '%' {
|
|
|
|
class = append(class, str.Join("author-", user.UserLogin))
|
2023-02-14 11:47:47 +00:00
|
|
|
}
|
2023-02-26 05:55:05 +00:00
|
|
|
|
2023-02-14 11:47:47 +00:00
|
|
|
case constraints.Detail:
|
2023-02-26 05:55:05 +00:00
|
|
|
class = append(class, str.Join("postid-", number.ToString(h.Detail.Post.Id)))
|
2023-02-18 15:35:39 +00:00
|
|
|
if len(h.ThemeMods.ThemeSupport.PostFormats) > 0 {
|
2023-02-26 05:55:05 +00:00
|
|
|
class = append(class, "single-format-standard")
|
2023-02-14 11:47:47 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-18 15:35:39 +00:00
|
|
|
if wpconfig.IsCustomBackground(h.Theme) {
|
|
|
|
class = append(class, "custom-background")
|
|
|
|
}
|
2023-02-24 16:56:52 +00:00
|
|
|
if h.ThemeMods.CustomLogo > 0 || str.ToInteger(wpconfig.GetOption("site_logo"), 0) > 0 {
|
2023-02-18 15:35:39 +00:00
|
|
|
class = append(class, "wp-custom-logo")
|
|
|
|
}
|
|
|
|
if h.ThemeMods.ThemeSupport.ResponsiveEmbeds {
|
|
|
|
class = append(class, "wp-embed-responsive")
|
2023-02-14 11:47:47 +00:00
|
|
|
}
|
2023-02-24 16:56:52 +00:00
|
|
|
class = append(class, strings.Fields(commonClass[h.Scene])...)
|
|
|
|
return strings.Join(slice.Reverse(class), " ")
|
2023-02-14 11:47:47 +00:00
|
|
|
}
|