From 05dba844d7a02fe40e7db3e8c84b9e77bc593e37 Mon Sep 17 00:00:00 2001 From: elkan1788 Date: Sat, 24 Jun 2023 11:08:17 +0800 Subject: [PATCH] :lipstick: Add support subcategory feature. --- .../_common/components/pages/categories.scss | 29 +++++-- exampleSite/content/post/custom-files.md | 3 +- exampleSite/content/post/emoji-support.md | 4 +- exampleSite/content/post/external-link.md | 2 +- exampleSite/content/post/hello-world.md | 7 +- exampleSite/content/post/markdown-syntax.md | 4 +- exampleSite/content/post/math-formula.md | 3 +- exampleSite/content/post/mermaid-charts.md | 3 +- exampleSite/content/post/no-header-title.md | 2 +- exampleSite/content/post/shortcodes.md | 3 +- .../content/post/syntax-highlighting.md | 3 +- exampleSite/content/post/table-of-content.md | 2 +- layouts/_default/terms.html | 87 +++++++++++++------ layouts/partials/init.html | 4 +- .../partials/post/header_meta/comments.html | 2 +- 15 files changed, 113 insertions(+), 45 deletions(-) diff --git a/assets/css/_common/components/pages/categories.scss b/assets/css/_common/components/pages/categories.scss index b79ac03..bb14e9e 100644 --- a/assets/css/_common/components/pages/categories.scss +++ b/assets/css/_common/components/pages/categories.scss @@ -15,14 +15,22 @@ list-style: none; margin: 0; padding: 0; - } - .category-list-item { - margin: 5px 10px; + .category-list-item:before { + 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 { color: $grey; + padding: 0 2px; &::before { content: ' ('; @@ -33,7 +41,18 @@ } } - .category-list-child { - padding-left: 10px; + .category-children-list { + 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; + } } } diff --git a/exampleSite/content/post/custom-files.md b/exampleSite/content/post/custom-files.md index b491936..c374deb 100644 --- a/exampleSite/content/post/custom-files.md +++ b/exampleSite/content/post/custom-files.md @@ -7,7 +7,8 @@ date: 2022-09-10T21:02:32+08:00 lastmod: 2022-09-10T21:02:32+08:00 categories: - - 示例 + - 示例文章 + tags: - 自定义 - 个性化 diff --git a/exampleSite/content/post/emoji-support.md b/exampleSite/content/post/emoji-support.md index a9dce83..ebe8847 100644 --- a/exampleSite/content/post/emoji-support.md +++ b/exampleSite/content/post/emoji-support.md @@ -7,7 +7,9 @@ date: 2022-06-04T19:46:45+08:00 lastmod: 2022-06-04T19:46:45+08:00 categories: - - 示例 + - 示例文章 + - 语法 + tags: - 表情 - emoji diff --git a/exampleSite/content/post/external-link.md b/exampleSite/content/post/external-link.md index 77fcc7b..cd14bd6 100644 --- a/exampleSite/content/post/external-link.md +++ b/exampleSite/content/post/external-link.md @@ -7,7 +7,7 @@ date: 2022-06-01T15:59:41+08:00 lastmod: 2022-06-01T15:59:41+08:00 categories: - - 示例 + - 示例文章 tags: - Hugo - NexT diff --git a/exampleSite/content/post/hello-world.md b/exampleSite/content/post/hello-world.md index dbf641f..a6e6340 100644 --- a/exampleSite/content/post/hello-world.md +++ b/exampleSite/content/post/hello-world.md @@ -6,10 +6,11 @@ lastmod: 2022-06-03T16:43:23+08:00 date: 2022-06-02T11:52:03+08:00 categories: - - 博客 +- 开始建站 + tags: - - Hugo - - 开始 + - Hugo + - 开始 url: post/hello-world.html toc: true diff --git a/exampleSite/content/post/markdown-syntax.md b/exampleSite/content/post/markdown-syntax.md index 89bf77e..32a4da0 100644 --- a/exampleSite/content/post/markdown-syntax.md +++ b/exampleSite/content/post/markdown-syntax.md @@ -10,7 +10,9 @@ author: Mainroad originLink: https://mainroad-demo.netlify.app/post/basic-elements/ categories: - - 示例 + - 示例文章 + - 语法 + tags: - Markdown - 语法 diff --git a/exampleSite/content/post/math-formula.md b/exampleSite/content/post/math-formula.md index 806b151..e0ead99 100644 --- a/exampleSite/content/post/math-formula.md +++ b/exampleSite/content/post/math-formula.md @@ -7,7 +7,8 @@ date: 2022-09-11T10:16:02+08:00 lastmod: 2022-09-11T10:16:02+08:00 categories: - - 示例 + - 第三方引入 + - 数学公式 tags: - 数学公式 - mathjax diff --git a/exampleSite/content/post/mermaid-charts.md b/exampleSite/content/post/mermaid-charts.md index 9f4e44c..1aa92a2 100644 --- a/exampleSite/content/post/mermaid-charts.md +++ b/exampleSite/content/post/mermaid-charts.md @@ -7,7 +7,8 @@ date: 2022-09-18T20:58:13+08:00 lastmod: 2022-09-18T20:58:13+08:00 categories: - - 示例 + - 第三方引入 + - 图序功能 tags: - 流程图 - 时序图 diff --git a/exampleSite/content/post/no-header-title.md b/exampleSite/content/post/no-header-title.md index 7a75e84..f7a6a6c 100644 --- a/exampleSite/content/post/no-header-title.md +++ b/exampleSite/content/post/no-header-title.md @@ -7,7 +7,7 @@ date: 2022-10-06T09:02:26+08:00 lastmod: 2022-10-30T21:03:16+08:00 categories: - - 示例 + - 示例文章 tags: - toc - 标题 diff --git a/exampleSite/content/post/shortcodes.md b/exampleSite/content/post/shortcodes.md index 013cf9c..4cac174 100644 --- a/exampleSite/content/post/shortcodes.md +++ b/exampleSite/content/post/shortcodes.md @@ -7,7 +7,8 @@ date: 2022-08-06T14:41:50+08:00 lastmod: 2022-08-06T14:41:50+08:00 categories: - - 示例 + - 示例文章 + - 语法 tags: - 短代码 - 语法 diff --git a/exampleSite/content/post/syntax-highlighting.md b/exampleSite/content/post/syntax-highlighting.md index e370982..60b94db 100644 --- a/exampleSite/content/post/syntax-highlighting.md +++ b/exampleSite/content/post/syntax-highlighting.md @@ -7,7 +7,8 @@ date: 2022-06-07T19:09:52+08:00 lastmod: 2022-06-07T19:09:52+08:00 categories: - - 示例 + - 示例文章 + - 语法 tags: - 语法 - 高亮 diff --git a/exampleSite/content/post/table-of-content.md b/exampleSite/content/post/table-of-content.md index e31b6d0..039963b 100644 --- a/exampleSite/content/post/table-of-content.md +++ b/exampleSite/content/post/table-of-content.md @@ -7,7 +7,7 @@ date: 2022-06-08T21:12:52+08:00 lastmod: 2022-06-08T21:12:52+08:00 categories: - - 示例 + - 示例文章 tags: - 目录 - 导航 diff --git a/layouts/_default/terms.html b/layouts/_default/terms.html index 3b45d59..5d76400 100644 --- a/layouts/_default/terms.html +++ b/layouts/_default/terms.html @@ -15,40 +15,77 @@
{{ if eq .Data.Plural "categories" }} - {{ $cats := .Site.Taxonomies.categories }} + {{ $categories := .Site.Taxonomies.categories }}
- {{ T "CatesCounterTitle" (.Scratch.Get "catsCount") | safeHTML }} + {{ T "Terms.categories" (.Scratch.Get "catsCount") | safeHTML }}
    - {{ range $name, $items := $cats }} -
  • - {{ .Page.Title }} - {{ len $items }} -
  • + {{ $allSecondaryCats := slice }} + {{ range .Site.Taxonomies.categories.ByCount }} + {{ $primaryCategory := .Name }} + {{ $primaryCount := 0 }} + {{ $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) }} +
  • + + {{ $primaryCategory }} + {{ $primaryCount }} + +
  • +
      + {{ 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 }} +
    • + + {{ . }} + {{ $secondaryCount }} + +
    • + {{ end }} +
    + {{ end }} {{ end }} -
-
-
+ {{ end }} {{ if eq .Data.Plural "tags" }} - {{ $tags := .Site.Taxonomies.tags }} -
-
- {{ T "Terms.tags" (.Scratch.Get "tagsCount") | safeHTML }} + {{ $tags := .Site.Taxonomies.tags }} +
+
+ {{ T "Terms.tags" (.Scratch.Get "tagsCount") | safeHTML }} +
+
+ {{ $randNums := (seq 10) }} + {{- range $name, $items := $tags }} + {{ .Page.Title }} + + ({{ len $items }}) + + + {{ end }} +
-
- {{ $randNums := (seq 10) }} - {{- range $name, $items := $tags }} - {{ .Page.Title }} - - ({{ len $items }}) - - - {{ end }} -
-
{{ end }}
diff --git a/layouts/partials/init.html b/layouts/partials/init.html index 5fb5214..a760223 100644 --- a/layouts/partials/init.html +++ b/layouts/partials/init.html @@ -14,7 +14,9 @@ {{ $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 "tagsCount" (len .Site.Taxonomies.tags) }} diff --git a/layouts/partials/post/header_meta/comments.html b/layouts/partials/post/header_meta/comments.html index d5dd017..5590703 100644 --- a/layouts/partials/post/header_meta/comments.html +++ b/layouts/partials/post/header_meta/comments.html @@ -5,7 +5,7 @@ {{ print (T "PostMeta.comments") (T "Symbol.colon") }} - + \ No newline at end of file