wp-go/internal/theme/wp/bodyclass.go

74 lines
2.2 KiB
Go
Raw Normal View History

2023-03-01 05:17:12 +00:00
package wp
2023-02-14 11:47:47 +00:00
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"
)
func (h *Handle) CalBodyClass() {
2023-02-28 15:38:23 +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 {
2023-02-27 14:58:35 +00:00
class = append(class, "error404")
2023-02-14 11:47:47 +00:00
}
2023-02-28 15:38:23 +00:00
switch h.scene {
2023-02-26 14:20:20 +00:00
case constraints.Home:
class = append(class, "home", "blog")
case constraints.Archive:
class = append(class, "archive", "date")
2023-02-14 11:47:47 +00:00
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 14:20:20 +00:00
class = append(class, "search", s)
2023-02-14 11:47:47 +00:00
case constraints.Category, constraints.Tag:
2023-02-26 14:20:20 +00:00
class = append(class, "archive", "category")
2023-02-26 05:55:05 +00:00
cat := h.Index.Param.Category
2023-02-28 15:38:23 +00:00
_, cate := slice.SearchFirst(cache.CategoriesTags(h.C, h.scene), func(my models.TermsMy) bool {
2023-02-14 11:47:47 +00:00
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:
2023-02-26 14:20:20 +00:00
class = append(class, "archive", "author")
2023-02-26 05:55:05 +00:00
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 14:20:20 +00:00
class = append(class, "post-template-default", "single", "single-post")
2023-02-26 05:55:05 +00:00
class = append(class, str.Join("postid-", number.ToString(h.Detail.Post.Id)))
2023-02-28 15:38:23 +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-28 15:38:23 +00:00
if wpconfig.IsCustomBackground(h.theme) {
2023-02-18 15:35:39 +00:00
class = append(class, "custom-background")
}
2023-02-28 15:38:23 +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")
}
2023-02-28 15:38:23 +00:00
if h.themeMods.ThemeSupport.ResponsiveEmbeds {
2023-02-18 15:35:39 +00:00
class = append(class, "wp-embed-responsive")
2023-02-14 11:47:47 +00:00
}
2023-02-26 14:20:20 +00:00
return strings.Join(class, " ")
2023-02-14 11:47:47 +00:00
}