summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-07-14 20:45:00 +0800
committerEltrac <hi@guhub.cn>2025-07-14 20:45:00 +0800
commit5f3933751ede3845ebc3ff319986d25515501522 (patch)
treed3057a1d5876f8daf37b590a0c9b9694e05c5bb5
parent572b94c723a27c50bf2a9d80eebb5a245b1b50cf (diff)
refactor: combine categories and tags together and simplify templating
-rw-r--r--assets/css/components/_taxonomy.scss40
-rw-r--r--content/categories/_index.md2
-rw-r--r--data/series.json20
-rw-r--r--i18n/zh.yml2
-rw-r--r--layouts/_partials/components/postnav.html7
-rw-r--r--layouts/_partials/taxonomy/all-categories.html17
-rw-r--r--layouts/_partials/taxonomy/all-tags.html74
-rw-r--r--layouts/categories/taxonomy.html88
-rw-r--r--layouts/categories/term.html29
-rw-r--r--layouts/taxonomy.html86
-rw-r--r--layouts/term.html13
11 files changed, 141 insertions, 237 deletions
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 @@
<li class="{{ if eq "/featured/" $.Page.RelPermalink }}active{{ end }}">
<a data-umami-event="🧭 Click postnav link" href="{{ .Site.LanguagePrefix }}/featured">{{ T "postNav.featured" }}</a>
</li>
- <li class="{{ if eq "/categories/" $.Page.RelPermalink }}active{{ end }}">
+ <li class="{{ if or
+ (strings.HasPrefix $.Page.RelPermalink "/categories/")
+ (strings.HasPrefix $.Page.RelPermalink "/tags/") }}active{{ end }}">
<a data-umami-event="🧭 Click postnav link" href="{{ .Site.LanguagePrefix }}/categories">{{ T "postNav.categories" }}</a>
</li>
- <li class="{{ if eq "/tags/" $.Page.RelPermalink }}active{{ end }}">
- <a data-umami-event="🧭 Click postnav link" href="{{ .Site.LanguagePrefix }}/tags">{{ T "postNav.tags" }}</a>
- </li>
{{ end }}
<li id="search-instruction">
<span>{{ T "searchInstruction" }}</span>
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 @@
+<!-- Display Categories -->
+<section class="taxonomy-categories">
+{{ range sort .Site.Taxonomies.categories ".Count" "desc" }}
+ <a href="{{ .Page.RelPermalink }}" class="category-link"
+ style="view-transition-name: category-{{ .Page.Title }};">
+ <div class="taxonomy-categories-item">
+ <h3 class="category-title">
+ {{ with .Page.Params.icon }}
+ <span class="category-icon">{{ . }}</span>
+ {{ end }}
+ <span class="category-title-text">{{ .Page.LinkTitle }}</span>
+ </h3>
+ <p class="category-description">{{ .Page.Params.description | markdownify }}</p>
+ </div>
+ </a>
+{{ end }}
+</section>
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 @@
+<!-- Display Tags -->
+<section class="taxonomy-tags">
+ {{ $categorizedTags := dict }}
+ {{ $uncategorizedTags := slice }}
+
+ <!-- Group tags by category -->
+ {{ 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 }}
+
+ <!-- Sort tags by count -->
+ {{ $uncategorizedTags = sort $uncategorizedTags "Count" "desc" }}
+ {{ range $category, $categoryTags := $categorizedTags }}
+ {{ $categorizedTags = merge $categorizedTags (dict $category (sort $categoryTags "Count" "desc")) }}
+ {{ end }}
+
+ <!-- Display uncategorized tags first -->
+ {{ if $uncategorizedTags }}
+ <div class="taxonomy-tags">
+ {{ range $uncategorizedTags }}
+ <a href="{{ .Page.RelPermalink }}"
+ class="taxonomy-tags-item{{ if lt .Count 4 }} dimmed{{ end }}">
+ {{ if .Page.Params.icon }}
+ {{ if or (hasPrefix .Page.Params.icon "http://") (hasPrefix .Page.Params.icon "https://") }}
+ <span class="tag-icon">
+ <img src="{{ .Page.Params.icon }}" alt="{{ .Page.LinkTitle }}"
+ style="height:1em;width:1em">
+ </span>
+ {{ else }}
+ <span class="tag-icon">{{ .Page.Params.icon }}</span>
+ {{ end }}
+ {{ end }}
+ <span class="tag-name">{{ if not .Page.Params.icon }}#{{ end }}{{ .Page.LinkTitle }}</span>
+ <span class="tag-count">{{ .Count }}</span>
+ </a>
+ {{ end }}
+ </div>
+ {{ end }}
+
+ <!-- Display categorized tags -->
+ {{ range $category, $categoryTags := $categorizedTags }}
+ <div class="taxonomy-category">
+ <h3 class="taxonomy-category-title">{{ $category }}</h3>
+ <div class="taxonomy-tags">
+ {{ range $categoryTags }}
+ <a href="{{ .Page.RelPermalink }}"
+ class="taxonomy-tags-item{{ if lt .Count 4 }} dimmed{{ end }}">
+ {{ if .Page.Params.icon }}
+ {{ if or (hasPrefix .Page.Params.icon "http://") (hasPrefix .Page.Params.icon "https://") }}
+ <span class="tag-icon">
+ <img src="{{ .Page.Params.icon }}" alt="{{ .Page.LinkTitle }}"
+ style="height:1em;width:1em">
+ </span>
+ {{ else }}
+ <span class="tag-icon">{{ .Page.Params.icon }}</span>
+ {{ end }}
+ {{ end }}
+ <span class="tag-name">{{ if not .Page.Params.icon }}#{{ end }}{{ .Page.LinkTitle }}</span>
+ <span class="tag-count">{{ .Count }}</span>
+ </a>
+ {{ end }}
+ </div>
+ </div>
+ {{ end }}
+</section>
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" }}
-<article class="taxonomy">
- {{ partial "header.html" . }}
- {{ partial "components/postnav.html" . }}
-
- <!-- Series With Banners -->
- {{ if eq .Site.Language.Lang "zh" }}
- <div id="post-series">
- <div id="post-series-list">
- {{ range .Site.Data.series }}
- <a class="post-series-item"
- href="{{ .link }}"
- title="{{ .description }}"
- data-umami-event="🚩 Click series link from Banner"
- >
- <div class="post-series-cover">
- <img src="{{ .cover }}" />
- </div>
- <div class="post-series-text">
- <h3>{{ .name }}</h3>
- </div>
- </a>
- {{ end }}
- </div>
- </div>
- {{ end }}
-
- <!-- Display Categories -->
- {{ $featured := slice "稻草人周刊" "年终总结" "揽物日志" "极客死亡计划书" }}
- <h2>周期性刊物</h2>
- <section class="taxonomy-categories">
- {{ range sort .Site.Taxonomies.categories ".Count" "desc" }}
- {{ if in $featured .Page.Title }}
- <div class="taxonomy-categories-item">
- <h3 class="category-title">
- <a href="{{ .Page.RelPermalink }}">
- {{ with .Page.Params.icon }}<span>{{ . }}</span>{{ end }} {{ .Page.LinkTitle }}
- </a>
- </h3>
- <p class="category-description">{{ .Page.Params.description | markdownify }}</p>
- <ul class="category-articles">
- {{ range first 6 .Pages }}
- <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
- {{ end }}
- </ul>
- {{ if gt .Count 6 }}
- <a class="category-link"
- href="{{ .Page.RelPermalink }}"
- >阅读所有 {{ .Count }} 篇文章</a>
- {{ end }}
- </div>
- {{ end }}
- {{ end }}
- </section>
-
- <!-- Render Other Categories -->
- <h2>文章系列</h2>
- <section class="taxonomy-categories">
- {{ range sort .Site.Taxonomies.categories ".Count" "desc" }}
- {{ if not (in $featured .Page.Title) }}
- <div class="taxonomy-categories-item">
- <h3 class="category-title">
- <a href="{{ .Page.RelPermalink }}">
- {{ with .Page.Params.icon }}<span>{{ . }}</span>{{ end }} {{ .Page.LinkTitle }}
- </a>
- </h3>
- <p class="category-description">{{ .Page.Params.description | markdownify }}</p>
- <ul class="category-articles">
- {{ range first 6 .Pages }}
- <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
- {{ end }}
- </ul>
- {{ if gt .Count 6 }}
- <a class="category-link"
- href="{{ .Page.RelPermalink }}"
- >阅读所有 {{ .Count }} 篇文章</a>
- {{ end }}
- </div>
- {{ end }}
- {{ end }}
- </section>
-
- <p class="uncategorized-link-container">
- <a class="uncategorized-link" href="/categories/uncategorized/">查看随笔</a>
- </p>
-</article>
-{{ 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" }}
- <article class="posts termlist-page">
- {{ partial "header.html" . }}
- {{ partial "components/postnav.html" . }}
- <h1 class="term-title">{{ .Title }}</h1>
- {{ with .Params.description }}
- <div class="taxonomy-description markdown-body">
- {{ . | markdownify }}
- </div>
- {{ end }}
-
- <div class="term-list">
- <ul class="term-list-posts">
- {{ range where .Pages "Section" "ne" "cards" }}
- <li>
- <a href="{{ .RelPermalink }}" data-umami-event="🗃️ Click Post Link from Category Page">
- {{ .Title }}{{ with .Params.subtitle }}:<span class="posts-subtitle">{{. }}</span>
- {{ end }}
- </a>
- <time>
- {{ .Date.Format "2006-1-2" }}
- </time>
- </li>
- {{ end }}
- </ul>
- </div>
- </article>
- {{ 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" }}
<article class="taxonomy">
- {{ partial "header.html" . }}
- {{ partial "components/postnav.html" . }}
+ {{ partial "header.html" . }}
+ {{ partial "components/postnav.html" . }}
- <!-- Display Tags -->
- <section class="taxonomy-tags">
- {{ $categorizedTags := dict }}
- {{ $uncategorizedTags := slice }}
-
- <!-- Group tags by category -->
- {{ 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 }}
-
- <!-- Sort tags by count -->
- {{ $uncategorizedTags = sort $uncategorizedTags "Count" "desc" }}
- {{ range $category, $categoryTags := $categorizedTags }}
- {{ $categorizedTags = merge $categorizedTags (dict $category (sort $categoryTags "Count" "desc")) }}
- {{ end }}
-
- <!-- Display uncategorized tags first -->
- {{ if $uncategorizedTags }}
- <div class="taxonomy-tags">
- {{ range $uncategorizedTags }}
- <a href="{{ .Page.RelPermalink }}"
- class="taxonomy-tags-item{{ if lt .Count 4 }} dimmed{{ end }}">
- {{ if .Page.Params.icon }}
- {{ if or (hasPrefix .Page.Params.icon "http://") (hasPrefix .Page.Params.icon "https://") }}
- <span class="tag-icon">
- <img src="{{ .Page.Params.icon }}" alt="{{ .Page.LinkTitle }}"
- style="height:1em;width:1em">
- </span>
- {{ else }}
- <span class="tag-icon">{{ .Page.Params.icon }}</span>
- {{ end }}
- {{ end }}
- <span class="tag-name">{{ if not .Page.Params.icon }}#{{ end }}{{ .Page.LinkTitle }}</span>
- <span class="tag-count">{{ .Count }}</span>
- </a>
- {{ end }}
- </div>
- {{ end }}
-
- <!-- Display categorized tags -->
- {{ range $category, $categoryTags := $categorizedTags }}
- <div class="taxonomy-category">
- <h3 class="taxonomy-category-title">{{ $category }}</h3>
- <div class="taxonomy-tags">
- {{ range $categoryTags }}
- <a href="{{ .Page.RelPermalink }}"
- class="taxonomy-tags-item{{ if lt .Count 4 }} dimmed{{ end }}">
- {{ if .Page.Params.icon }}
- {{ if or (hasPrefix .Page.Params.icon "http://") (hasPrefix .Page.Params.icon "https://") }}
- <span class="tag-icon">
- <img src="{{ .Page.Params.icon }}" alt="{{ .Page.LinkTitle }}"
- style="height:1em;width:1em">
- </span>
- {{ else }}
- <span class="tag-icon">{{ .Page.Params.icon }}</span>
- {{ end }}
- {{ end }}
- <span class="tag-name">{{ if not .Page.Params.icon }}#{{ end }}{{ .Page.LinkTitle }}</span>
- <span class="tag-count">{{ .Count }}</span>
- </a>
- {{ end }}
- </div>
- </div>
- {{ end }}
- </section>
+ <h2>文章系列</h2>
+ {{ partial "taxonomy/all-categories.html" . }}
+ <p class="uncategorized-link-container">
+ <a class="uncategorized-link" href="/categories/uncategorized/">查看随笔</a>
+ </p>
+
+ <h2>标签</h2>
+ {{ partial "taxonomy/all-tags.html" . }}
</article>
{{ 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 @@
<article class="posts termlist-page">
{{ partial "header.html" . }}
{{ partial "components/postnav.html" . }}
- <h1 class="term-title">#{{ .Title }}</h1>
+ <div class="term-header">
+ <h1 class="term-title"
+ style="view-transition-name: category-{{ .Title }}">
+ {{ with .Params.icon }}
+ <span class="category-icon">{{ . }}</span>
+ {{ end }}
+ {{ if and (eq .Data.Singular "tag") (not .Params.icon) }}#{{ end }}{{ .Title }}
+ </h1>
+ {{ with .Params.description | markdownify }}
+ <p class="term-description">{{ . }}</p>
+ {{ end }}
+ </div>
<div class="term-list">
<!-- Posts under this Term -->
<ul class="term-list-posts">