summaryrefslogtreecommitdiff
path: root/layouts
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
commit5a048dc954bdc9641b1dca9305cd26ed2b25c480 (patch)
treed3057a1d5876f8daf37b590a0c9b9694e05c5bb5 /layouts
parent9a261d9b5fecd4eea019ec63e300c25fdee1812e (diff)
refactor: combine categories and tags together and simplify templating
Former-commit-id: 5f3933751ede3845ebc3ff319986d25515501522
Diffstat (limited to 'layouts')
-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
7 files changed, 116 insertions, 198 deletions
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">