This commit is contained in:
xing 2023-04-16 16:37:27 +08:00
parent 98cee2f18b
commit 5266e85f21
5 changed files with 22 additions and 20 deletions

View File

@ -4,7 +4,7 @@
{{template "layout/head" .}}
<body class="{{.bodyClass}}">
<body class="{{.calBodyClass|exec}}">
{{template "svg"}}
<div id="page" class="site">
<a class="skip-link screen-reader-text" href="#content">跳至内容</a>

View File

@ -12,7 +12,7 @@
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main">
<article id="post-{{.post.Id}}" class="post-{{.post.Id}} post type-post status-publish format-standard hentry {{if .post.Thumbnail.Path}}has-post-thumbnail{{end}} category-uncategorized">
<article id="post-{{.post.Id}}" class="{{ .post|postsFn .calPostClass}}">
<header class="entry-header">
<div class="entry-meta">

View File

@ -17,7 +17,7 @@
<div id="primary" class="content-area">
<main id="main" class="site-main">
{{ range $k,$v:=.posts}}
<article id="post-{{$v.Id}}" class="post-{{$v.Id}} post {{if $v.Thumbnail.Path}}has-post-thumbnail{{end}} {{if $v.IsSticky}}sticky{{end}} type-post status-publish format-standard hentry category">
<article id="post-{{$v.Id}}" class="{{ $v|postsFn $.calPostClass}}">
{{if $v.IsSticky}}
<svg class="icon icon-thumb-tack" aria-hidden="true" role="img">
<use href="#icon-thumb-tack" xlink:href="#icon-thumb-tack"></use>

View File

@ -9,13 +9,10 @@ import (
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
"github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/fthvgb1/wp-go/internal/wpconfig"
"strconv"
"strings"
)
func CalBodyClass(h *Handle) {
h.ginH["bodyClass"] = h.BodyClass()
}
func (h *Handle) BodyClass() string {
var class []string
if constraints.Ok != h.Stats {
@ -101,19 +98,24 @@ func (h *Handle) PostClass(posts models.Posts) string {
if !ok || term.Slug == "" {
continue
}
termClass := term.Slug
if termClass[0] == '%' {
termClass = number.ToString(term.Terms.TermId)
}
switch term.Taxonomy {
case "category":
class = append(class, str.Join("category-", termClass))
case "post_tag":
class = append(class, str.Join("tag-", termClass))
case "post_format":
class = append(class, fmt.Sprintf("format-%s", strings.ReplaceAll(term.Slug, "post-format-", "")))
}
class = append(class, TermClass(term))
}
return h.ComponentFilterFnHook("postClass", strings.Join(class, " "))
}
func TermClass(term models.TermsMy) string {
termClass := term.Slug
if strings.Contains(term.Slug, "%") {
termClass = strconv.FormatUint(term.TermTaxonomy.TermId, 10)
}
switch term.Taxonomy {
case "category":
return str.Join("category-", termClass)
case "post_tag":
return str.Join("tag-", termClass)
case "post_format":
return fmt.Sprintf("format-%s", strings.ReplaceAll(term.Slug, "post-format-", ""))
}
return fmt.Sprintf("%s-%d", term.Taxonomy, term.TermTaxonomy.TermId)
}

View File

@ -334,7 +334,7 @@ func (h *Handle) Render() {
func (h *Handle) CommonComponents() {
h.AddCacheComponent("customLogo", CalCustomLogo)
h.PushCacheGroupHeadScript("siteIconAndCustomCss", 0, CalSiteIcon, CalCustomCss)
h.PushGroupHandleFn(constraints.AllStats, 10, CalComponents, CalBodyClass)
h.PushGroupHandleFn(constraints.AllStats, 10, CalComponents)
h.PushHandleFn(constraints.AllStats, NewHandleFn(func(h *Handle) {
h.C.HTML(h.Code, h.templ, h.ginH)
}, 0))