💄 Add support subcategory feature.

This commit is contained in:
elkan1788 2023-06-24 11:08:17 +08:00
parent d44d4c2a79
commit 05dba844d7
15 changed files with 113 additions and 45 deletions

View File

@ -15,14 +15,22 @@
list-style: none; list-style: none;
margin: 0; margin: 0;
padding: 0; padding: 0;
}
.category-list-item { .category-list-item:before {
margin: 5px 10px; font-family: var(--fa-style-family,"Font Awesome 6 Free");
font-weight: var(--fa-style,900);
content: "\f07c"
}
.category-list-item {
margin: 5px 10px;
font-weight: bold;
}
} }
.category-list-count { .category-list-count {
color: $grey; color: $grey;
padding: 0 2px;
&::before { &::before {
content: ' ('; content: ' (';
@ -33,7 +41,18 @@
} }
} }
.category-list-child { .category-children-list {
padding-left: 10px; padding-left: 38px;
list-style: none;
.category-children-list-item:before {
font-family: var(--fa-style-family,"Font Awesome 6 Free");
font-weight: var(--fa-style,900);
content: "\f0ae";
}
.category-children-list-item {
font-size: 0.925em;
}
} }
} }

View File

@ -7,7 +7,8 @@ date: 2022-09-10T21:02:32+08:00
lastmod: 2022-09-10T21:02:32+08:00 lastmod: 2022-09-10T21:02:32+08:00
categories: categories:
- 示例 - 示例文章
tags: tags:
- 自定义 - 自定义
- 个性化 - 个性化

View File

@ -7,7 +7,9 @@ date: 2022-06-04T19:46:45+08:00
lastmod: 2022-06-04T19:46:45+08:00 lastmod: 2022-06-04T19:46:45+08:00
categories: categories:
- 示例 - 示例文章
- 语法
tags: tags:
- 表情 - 表情
- emoji - emoji

View File

@ -7,7 +7,7 @@ date: 2022-06-01T15:59:41+08:00
lastmod: 2022-06-01T15:59:41+08:00 lastmod: 2022-06-01T15:59:41+08:00
categories: categories:
- 示例 - 示例文章
tags: tags:
- Hugo - Hugo
- NexT - NexT

View File

@ -6,10 +6,11 @@ lastmod: 2022-06-03T16:43:23+08:00
date: 2022-06-02T11:52:03+08:00 date: 2022-06-02T11:52:03+08:00
categories: categories:
- 博客 - 开始建站
tags: tags:
- Hugo - Hugo
- 开始 - 开始
url: post/hello-world.html url: post/hello-world.html
toc: true toc: true

View File

@ -10,7 +10,9 @@ author: Mainroad
originLink: https://mainroad-demo.netlify.app/post/basic-elements/ originLink: https://mainroad-demo.netlify.app/post/basic-elements/
categories: categories:
- 示例 - 示例文章
- 语法
tags: tags:
- Markdown - Markdown
- 语法 - 语法

View File

@ -7,7 +7,8 @@ date: 2022-09-11T10:16:02+08:00
lastmod: 2022-09-11T10:16:02+08:00 lastmod: 2022-09-11T10:16:02+08:00
categories: categories:
- 示例 - 第三方引入
- 数学公式
tags: tags:
- 数学公式 - 数学公式
- mathjax - mathjax

View File

@ -7,7 +7,8 @@ date: 2022-09-18T20:58:13+08:00
lastmod: 2022-09-18T20:58:13+08:00 lastmod: 2022-09-18T20:58:13+08:00
categories: categories:
- 示例 - 第三方引入
- 图序功能
tags: tags:
- 流程图 - 流程图
- 时序图 - 时序图

View File

@ -7,7 +7,7 @@ date: 2022-10-06T09:02:26+08:00
lastmod: 2022-10-30T21:03:16+08:00 lastmod: 2022-10-30T21:03:16+08:00
categories: categories:
- 示例 - 示例文章
tags: tags:
- toc - toc
- 标题 - 标题

View File

@ -7,7 +7,8 @@ date: 2022-08-06T14:41:50+08:00
lastmod: 2022-08-06T14:41:50+08:00 lastmod: 2022-08-06T14:41:50+08:00
categories: categories:
- 示例 - 示例文章
- 语法
tags: tags:
- 短代码 - 短代码
- 语法 - 语法

View File

@ -7,7 +7,8 @@ date: 2022-06-07T19:09:52+08:00
lastmod: 2022-06-07T19:09:52+08:00 lastmod: 2022-06-07T19:09:52+08:00
categories: categories:
- 示例 - 示例文章
- 语法
tags: tags:
- 语法 - 语法
- 高亮 - 高亮

View File

@ -7,7 +7,7 @@ date: 2022-06-08T21:12:52+08:00
lastmod: 2022-06-08T21:12:52+08:00 lastmod: 2022-06-08T21:12:52+08:00
categories: categories:
- 示例 - 示例文章
tags: tags:
- 目录 - 目录
- 导航 - 导航

View File

@ -15,40 +15,77 @@
</div> </div>
<div class="post-body"> <div class="post-body">
{{ if eq .Data.Plural "categories" }} {{ if eq .Data.Plural "categories" }}
{{ $cats := .Site.Taxonomies.categories }} {{ $categories := .Site.Taxonomies.categories }}
<div class="category-all-page"> <div class="category-all-page">
<div class="category-all-title"> <div class="category-all-title">
{{ T "CatesCounterTitle" (.Scratch.Get "catsCount") | safeHTML }} {{ T "Terms.categories" (.Scratch.Get "catsCount") | safeHTML }}
</div> </div>
<div class="category-all"> <div class="category-all">
<ul class="category-list"> <ul class="category-list">
{{ range $name, $items := $cats }} {{ $allSecondaryCats := slice }}
<li class="category-list-item"> {{ range .Site.Taxonomies.categories.ByCount }}
<a class="category-list-link" href="{{ "/categories/" | relLangURL }}{{ $name | urlize }}" data-pjax-state="">{{ .Page.Title }}</a> {{ $primaryCategory := .Name }}
<span class="category-list-count">{{ len $items }}</span> {{ $primaryCount := 0 }}
</li> {{ $secondaryCategories := slice}}
{{ $pages := $.Scratch.Get "pages" }}
{{ range where $pages "Params.categories" "intersect" (slice $primaryCategory) }}
{{ if eq (index .Params.categories 0) $primaryCategory }}
{{ $primaryCount = add $primaryCount 1 }}
{{/** if and (isset .Params.categories 1) (not (in $secondaryCategories (index .Params.categories 1))) **/}}
{{ if isset .Params.categories 1 }}
{{ if not (in $secondaryCategories (index .Params.categories 1)) }}
{{ $secondaryCategories = $secondaryCategories | append (index .Params.categories 1) }}
{{ $allSecondaryCats = $allSecondaryCats | append (index .Params.categories 1) }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ if not (in $allSecondaryCats $primaryCategory) }}
<li class="category-list-item">
<a class="category-list-link" href="{{ "categories/" | relURL }}{{ $primaryCategory | urlize }}">
{{ $primaryCategory }}
<span class="category-list-count">{{ $primaryCount }}</span>
</a>
</li>
<ul class="category-children-list">
{{ range $secondaryCategories }}
{{ $secondaryCategory := . }}
{{ $secondaryCount := 0 }}
{{ range where $pages "Params.categories" "intersect" (slice $secondaryCategory) }}
{{ if and (eq (index .Params.categories 0) $primaryCategory) (eq (index .Params.categories 1) $secondaryCategory) }}
{{ $secondaryCount = add $secondaryCount 1 }}
{{ end }}
{{ end }}
<li class="category-children-list-item">
<a class="category-list-link" href="{{ "categories/" | relURL }}{{ . | urlize }}">
{{ . }}
<span class="category-list-count">{{ $secondaryCount }}</span>
</a>
</li>
{{ end }}
</ul>
{{ end }}
{{ end }} {{ end }}
</ul> </ul>
</div>
</div>
{{ end }} {{ end }}
{{ if eq .Data.Plural "tags" }} {{ if eq .Data.Plural "tags" }}
{{ $tags := .Site.Taxonomies.tags }} {{ $tags := .Site.Taxonomies.tags }}
<div class="tag-cloud"> <div class="tag-cloud">
<div class="tag-cloud-title"> <div class="tag-cloud-title">
{{ T "Terms.tags" (.Scratch.Get "tagsCount") | safeHTML }} {{ T "Terms.tags" (.Scratch.Get "tagsCount") | safeHTML }}
</div>
<div class="tag-cloud-tags">
{{ $randNums := (seq 10) }}
{{- range $name, $items := $tags }}
<a class="tag-cloud-{{ index (shuffle $randNums) 0 }}" href="{{ "/tags/" | relLangURL }}{{ $name | urlize }}">{{ .Page.Title }}
<span class="tag-list-count">
<sup>({{ len $items }})</sup>
</span>
</a>
{{ end }}
</div>
</div> </div>
<div class="tag-cloud-tags">
{{ $randNums := (seq 10) }}
{{- range $name, $items := $tags }}
<a class="tag-cloud-{{ index (shuffle $randNums) 0 }}" href="{{ "/tags/" | relLangURL }}{{ $name | urlize }}">{{ .Page.Title }}
<span class="tag-list-count">
<sup>({{ len $items }})</sup>
</span>
</a>
{{ end }}
</div>
</div>
{{ end }} {{ end }}
</div> </div>
</div> </div>

View File

@ -14,7 +14,9 @@
{{ $globalVars := newScratch }} {{ $globalVars := newScratch }}
{{ $globalVars.Set "postsCount" (len (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)) }} {{ $pages := (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections) }}
{{ $globalVars.Set "pages" $pages}}
{{ $globalVars.Set "postsCount" (len $pages)}}
{{ $globalVars.Set "catsCount" (len .Site.Taxonomies.categories) }} {{ $globalVars.Set "catsCount" (len .Site.Taxonomies.categories) }}
{{ $globalVars.Set "tagsCount" (len .Site.Taxonomies.tags) }} {{ $globalVars.Set "tagsCount" (len .Site.Taxonomies.tags) }}

View File

@ -5,7 +5,7 @@
<span class="post-meta-item-text" title="{{ T "PostMeta.comments" }}"> <span class="post-meta-item-text" title="{{ T "PostMeta.comments" }}">
{{ print (T "PostMeta.comments") (T "Symbol.colon") }} {{ print (T "PostMeta.comments") (T "Symbol.colon") }}
</span> </span>
<span {{ if and .Site.Params.postMeta.comments.enable (eq .Site.Params.postMeta.comments.plugin "waline") }}class="waline-comment-count"{{end}} data-path="{{ .RelPermalink | relLangURL }}"> <span id="comments-count" {{ if and .Site.Params.postMeta.comments.enable (eq .Site.Params.postMeta.comments.plugin "waline") }}class="waline-comment-count"{{end}} data-path="{{ .RelPermalink | relLangURL }}">
<i class="fa fa-sync fa-spin"></i> <i class="fa fa-sync fa-spin"></i>
</span> </span>
</span> </span>