优化
This commit is contained in:
parent
98cee2f18b
commit
5266e85f21
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
{{template "layout/head" .}}
|
{{template "layout/head" .}}
|
||||||
|
|
||||||
<body class="{{.bodyClass}}">
|
<body class="{{.calBodyClass|exec}}">
|
||||||
{{template "svg"}}
|
{{template "svg"}}
|
||||||
<div id="page" class="site">
|
<div id="page" class="site">
|
||||||
<a class="skip-link screen-reader-text" href="#content">跳至内容</a>
|
<a class="skip-link screen-reader-text" href="#content">跳至内容</a>
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<div id="primary" class="content-area">
|
<div id="primary" class="content-area">
|
||||||
<main id="main" class="site-main">
|
<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">
|
<header class="entry-header">
|
||||||
<div class="entry-meta">
|
<div class="entry-meta">
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<div id="primary" class="content-area">
|
<div id="primary" class="content-area">
|
||||||
<main id="main" class="site-main">
|
<main id="main" class="site-main">
|
||||||
{{ range $k,$v:=.posts}}
|
{{ 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}}
|
{{if $v.IsSticky}}
|
||||||
<svg class="icon icon-thumb-tack" aria-hidden="true" role="img">
|
<svg class="icon icon-thumb-tack" aria-hidden="true" role="img">
|
||||||
<use href="#icon-thumb-tack" xlink:href="#icon-thumb-tack"></use>
|
<use href="#icon-thumb-tack" xlink:href="#icon-thumb-tack"></use>
|
||||||
|
|
|
@ -9,13 +9,10 @@ import (
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
||||||
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CalBodyClass(h *Handle) {
|
|
||||||
h.ginH["bodyClass"] = h.BodyClass()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Handle) BodyClass() string {
|
func (h *Handle) BodyClass() string {
|
||||||
var class []string
|
var class []string
|
||||||
if constraints.Ok != h.Stats {
|
if constraints.Ok != h.Stats {
|
||||||
|
@ -101,19 +98,24 @@ func (h *Handle) PostClass(posts models.Posts) string {
|
||||||
if !ok || term.Slug == "" {
|
if !ok || term.Slug == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
termClass := term.Slug
|
class = append(class, TermClass(term))
|
||||||
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-", "")))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return h.ComponentFilterFnHook("postClass", strings.Join(class, " "))
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -334,7 +334,7 @@ func (h *Handle) Render() {
|
||||||
func (h *Handle) CommonComponents() {
|
func (h *Handle) CommonComponents() {
|
||||||
h.AddCacheComponent("customLogo", CalCustomLogo)
|
h.AddCacheComponent("customLogo", CalCustomLogo)
|
||||||
h.PushCacheGroupHeadScript("siteIconAndCustomCss", 0, CalSiteIcon, CalCustomCss)
|
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.PushHandleFn(constraints.AllStats, NewHandleFn(func(h *Handle) {
|
||||||
h.C.HTML(h.Code, h.templ, h.ginH)
|
h.C.HTML(h.Code, h.templ, h.ginH)
|
||||||
}, 0))
|
}, 0))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user