From 5a048dc954bdc9641b1dca9305cd26ed2b25c480 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Mon, 14 Jul 2025 20:45:00 +0800 Subject: refactor: combine categories and tags together and simplify templating Former-commit-id: 5f3933751ede3845ebc3ff319986d25515501522 --- assets/css/components/_taxonomy.scss | 40 +++++++----- content/categories/_index.md | 2 +- data/series.json | 20 ------ i18n/zh.yml | 2 +- layouts/_partials/components/postnav.html | 7 +- layouts/_partials/taxonomy/all-categories.html | 17 +++++ layouts/_partials/taxonomy/all-tags.html | 74 ++++++++++++++++++++++ layouts/categories/taxonomy.html | 88 -------------------------- layouts/categories/term.html | 29 --------- layouts/taxonomy.html | 86 +++---------------------- layouts/term.html | 13 +++- 11 files changed, 141 insertions(+), 237 deletions(-) delete mode 100644 data/series.json create mode 100644 layouts/_partials/taxonomy/all-categories.html create mode 100644 layouts/_partials/taxonomy/all-tags.html delete mode 100644 layouts/categories/taxonomy.html delete mode 100644 layouts/categories/term.html diff --git a/assets/css/components/_taxonomy.scss b/assets/css/components/_taxonomy.scss index 9b5c5047..8b55d32f 100644 --- a/assets/css/components/_taxonomy.scss +++ b/assets/css/components/_taxonomy.scss @@ -5,26 +5,21 @@ grid-template-columns: repeat(2, 1fr); grid-template-rows: masonry; gap: 1rem; + .category-link:hover { + text-decoration: none; + } .taxonomy-categories-item { - ul.category-articles { - padding-inline-start: 1.5rem; - list-style-type: square; - } - a.category-link { - @include small-button; - font-size: 0.9rem - } h3.category-title { margin: 0.25rem 0; - a:hover { - text-decoration: none; - } - span { - display: inline-block; - } - &:hover span { - animation: bounce 1s ease-in-out; - } + .category-icon { + display: inline-block; + } + .category-title-text { + filter: url(#x); + } + &:hover span { + animation: bounce 1s ease-in-out; + } @keyframes bounce { 0%, 20%, 50%, 80%, 100% { transform: translateY(0); @@ -99,3 +94,14 @@ } } } + +.termlist-page { + .term-header { + .term-title { + margin-bottom: 0; + } + .term-description { + margin-top: 0; + } + } +} diff --git a/content/categories/_index.md b/content/categories/_index.md index 6bfa05ea..1080d041 100644 --- a/content/categories/_index.md +++ b/content/categories/_index.md @@ -1,3 +1,3 @@ --- -title: 专栏 +title: 分类 --- diff --git a/data/series.json b/data/series.json deleted file mode 100644 index cd2d8bde..00000000 --- a/data/series.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "name": "人类恶疾", - "link": "/categories/人类恶疾/", - "cover": "https://image.guhub.cn/uPic/2025/01/%E4%BA%BA%E7%B1%BB%E6%81%B6%E7%96%BE.jpeg", - "description": "尝试以非专业的病理视角分析人类行为" - }, - { - "name": "塔罗牌漫谈", - "link": "/categories/塔罗牌漫谈/", - "cover": "https://image.guhub.cn/uPic/2025/01/%E5%A1%94%E7%BD%97%E7%89%8C%E6%BC%AB%E8%B0%88%E5%B0%81%E9%9D%A2.jpeg", - "description": "随便聊聊牌意" - }, - { - "name": "稻草人周刊", - "link": "/categories/稻草人周刊/", - "cover": "https://image.guhub.cn/uPic/2025/01/%E7%A8%BB%E8%8D%89%E4%BA%BA%E5%91%A8%E5%88%8A.jpeg", - "description": "个人化的信息整合,每周一更新" - } -] diff --git a/i18n/zh.yml b/i18n/zh.yml index 96aa8086..df0e5c05 100644 --- a/i18n/zh.yml +++ b/i18n/zh.yml @@ -12,7 +12,7 @@ footer: searchInstruction: '⌘+K 搜索' postNav: latest: '最新' - categories: '专栏' + categories: '分类' tags: '标签' featured: '精选' cards: 最近在学 diff --git a/layouts/_partials/components/postnav.html b/layouts/_partials/components/postnav.html index 0174060c..55dd8a51 100644 --- a/layouts/_partials/components/postnav.html +++ b/layouts/_partials/components/postnav.html @@ -7,12 +7,11 @@
  • {{ T "postNav.featured" }}
  • -
  • +
  • -
  • - {{ T "postNav.tags" }} -
  • {{ end }}
  • {{ T "searchInstruction" }} diff --git a/layouts/_partials/taxonomy/all-categories.html b/layouts/_partials/taxonomy/all-categories.html new file mode 100644 index 00000000..a5ceef8e --- /dev/null +++ b/layouts/_partials/taxonomy/all-categories.html @@ -0,0 +1,17 @@ + +
    +{{ range sort .Site.Taxonomies.categories ".Count" "desc" }} + +
    +

    + {{ with .Page.Params.icon }} + {{ . }} + {{ end }} + {{ .Page.LinkTitle }} +

    +

    {{ .Page.Params.description | markdownify }}

    +
    +
    +{{ end }} +
    diff --git a/layouts/_partials/taxonomy/all-tags.html b/layouts/_partials/taxonomy/all-tags.html new file mode 100644 index 00000000..fae9676f --- /dev/null +++ b/layouts/_partials/taxonomy/all-tags.html @@ -0,0 +1,74 @@ + +
    + {{ $categorizedTags := dict }} + {{ $uncategorizedTags := slice }} + + + {{ range $tagName, $tagPages := .Site.Taxonomies.tags }} + {{ $tagPage := site.GetPage (printf "/tags/%s" $tagName) }} + {{ $tagData := dict "Name" $tagName "Count" (len $tagPages) "Page" $tagPage }} + {{ if $tagPage.Params.category }} + {{ $category := $tagPage.Params.category }} + {{ $categoryTags := index $categorizedTags $category | default slice }} + {{ $categoryTags = $categoryTags | append $tagData }} + {{ $categorizedTags = merge $categorizedTags (dict $category $categoryTags) }} + {{ else }} + {{ $uncategorizedTags = $uncategorizedTags | append $tagData }} + {{ end }} + {{ end }} + + + {{ $uncategorizedTags = sort $uncategorizedTags "Count" "desc" }} + {{ range $category, $categoryTags := $categorizedTags }} + {{ $categorizedTags = merge $categorizedTags (dict $category (sort $categoryTags "Count" "desc")) }} + {{ end }} + + + {{ if $uncategorizedTags }} + + {{ end }} + + + {{ range $category, $categoryTags := $categorizedTags }} + + {{ end }} +
    diff --git a/layouts/categories/taxonomy.html b/layouts/categories/taxonomy.html deleted file mode 100644 index 27ac35ff..00000000 --- a/layouts/categories/taxonomy.html +++ /dev/null @@ -1,88 +0,0 @@ -{{ define "main" }} -
    - {{ partial "header.html" . }} - {{ partial "components/postnav.html" . }} - - - {{ if eq .Site.Language.Lang "zh" }} -
    -
    - {{ range .Site.Data.series }} - -
    - -
    -
    -

    {{ .name }}

    -
    -
    - {{ end }} -
    -
    - {{ end }} - - - {{ $featured := slice "稻草人周刊" "年终总结" "揽物日志" "极客死亡计划书" }} -

    周期性刊物

    -
    - {{ range sort .Site.Taxonomies.categories ".Count" "desc" }} - {{ if in $featured .Page.Title }} -
    -

    - - {{ with .Page.Params.icon }}{{ . }}{{ end }} {{ .Page.LinkTitle }} - -

    -

    {{ .Page.Params.description | markdownify }}

    - - {{ if gt .Count 6 }} - 阅读所有 {{ .Count }} 篇文章 - {{ end }} -
    - {{ end }} - {{ end }} -
    - - -

    文章系列

    -
    - {{ range sort .Site.Taxonomies.categories ".Count" "desc" }} - {{ if not (in $featured .Page.Title) }} -
    -

    - - {{ with .Page.Params.icon }}{{ . }}{{ end }} {{ .Page.LinkTitle }} - -

    -

    {{ .Page.Params.description | markdownify }}

    - - {{ if gt .Count 6 }} - 阅读所有 {{ .Count }} 篇文章 - {{ end }} -
    - {{ end }} - {{ end }} -
    - - -
    -{{ partial "footer.html" . }} -{{ end }} diff --git a/layouts/categories/term.html b/layouts/categories/term.html deleted file mode 100644 index d383b6b0..00000000 --- a/layouts/categories/term.html +++ /dev/null @@ -1,29 +0,0 @@ -{{ define "main" }} -
    - {{ partial "header.html" . }} - {{ partial "components/postnav.html" . }} -

    {{ .Title }}

    - {{ with .Params.description }} -
    - {{ . | markdownify }} -
    - {{ end }} - -
    - -
    -
    - {{ partial "footer.html" . }} -{{ end }} diff --git a/layouts/taxonomy.html b/layouts/taxonomy.html index ef8f515f..b2a4779f 100644 --- a/layouts/taxonomy.html +++ b/layouts/taxonomy.html @@ -1,82 +1,16 @@ {{ define "main" }}
    - {{ partial "header.html" . }} - {{ partial "components/postnav.html" . }} + {{ partial "header.html" . }} + {{ partial "components/postnav.html" . }} - -
    - {{ $categorizedTags := dict }} - {{ $uncategorizedTags := slice }} - - - {{ range $tagName, $tagPages := .Site.Taxonomies.tags }} - {{ $tagPage := site.GetPage (printf "/tags/%s" $tagName) }} - {{ $tagData := dict "Name" $tagName "Count" (len $tagPages) "Page" $tagPage }} - {{ if $tagPage.Params.category }} - {{ $category := $tagPage.Params.category }} - {{ $categoryTags := index $categorizedTags $category | default slice }} - {{ $categoryTags = $categoryTags | append $tagData }} - {{ $categorizedTags = merge $categorizedTags (dict $category $categoryTags) }} - {{ else }} - {{ $uncategorizedTags = $uncategorizedTags | append $tagData }} - {{ end }} - {{ end }} - - - {{ $uncategorizedTags = sort $uncategorizedTags "Count" "desc" }} - {{ range $category, $categoryTags := $categorizedTags }} - {{ $categorizedTags = merge $categorizedTags (dict $category (sort $categoryTags "Count" "desc")) }} - {{ end }} - - - {{ if $uncategorizedTags }} - - {{ end }} - - - {{ range $category, $categoryTags := $categorizedTags }} - - {{ end }} -
    +

    文章系列

    + {{ partial "taxonomy/all-categories.html" . }} + + +

    标签

    + {{ partial "taxonomy/all-tags.html" . }}
    {{ partial "footer.html" . }} {{ end }} diff --git a/layouts/term.html b/layouts/term.html index 692e175e..90fb48b9 100644 --- a/layouts/term.html +++ b/layouts/term.html @@ -2,7 +2,18 @@
    {{ partial "header.html" . }} {{ partial "components/postnav.html" . }} -

    #{{ .Title }}

    +
    +

    + {{ with .Params.icon }} + {{ . }} + {{ end }} + {{ if and (eq .Data.Singular "tag") (not .Params.icon) }}#{{ end }}{{ .Title }} +

    + {{ with .Params.description | markdownify }} +

    {{ . }}

    + {{ end }} +
      -- cgit v1.2.3