summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-06-06 14:53:45 +0800
committerEltrac <hi@guhub.cn>2025-06-06 14:53:45 +0800
commit9855baa4d1dea96fc4516283bf66a98f10a29eaa (patch)
tree6a6fefb50c40489c439552ab1fcd4c0beb94c34d
parentb95d3e0b2b90bbb6235da81e84b6eefc63ee1da1 (diff)
refactor: reuse some page components
Former-commit-id: ed5fe0848d18665cd3fbd6011876207b2fee61e4
-rw-r--r--layouts/fictions/single.html11
-rw-r--r--layouts/library/single.html7
-rw-r--r--layouts/partials/components/category-pill.html8
-rw-r--r--layouts/partials/components/date.html26
-rw-r--r--layouts/partials/components/endnotes.html10
-rw-r--r--layouts/partials/components/now-read-this.html19
-rw-r--r--layouts/partials/components/toc.html2
-rw-r--r--layouts/posts/single.html73
8 files changed, 77 insertions, 79 deletions
diff --git a/layouts/fictions/single.html b/layouts/fictions/single.html
index e16dd4c7..83db7d60 100644
--- a/layouts/fictions/single.html
+++ b/layouts/fictions/single.html
@@ -11,16 +11,7 @@
>
{{ partial "components/banner.html" . }}
<h1 class="post-title" data-pagefind-meta="title">{{ .Title }}</h1>
- <div class="post-meta">
- {{ if .Date }}
- <time class="post-date"
- datetime="{{ .Date.Format "2006-01-02 15:04:05 MST" }}"
- data-pagefind-sort="date[datetime], weight[data-weight]"
- data-weight="15">
- {{ .Date.Format "2006年1月2日" }}
- </time>
- {{ end }}
- </div>
+ <div class="post-meta">{{ partial "components/date" . }}</div>
</header>
<!-- Post Content -->
diff --git a/layouts/library/single.html b/layouts/library/single.html
index d0dbf542..861cee24 100644
--- a/layouts/library/single.html
+++ b/layouts/library/single.html
@@ -35,11 +35,10 @@
<div class="book-content">
{{ .Content }}
</div>
+ <!-- Endnotes -->
+ {{ partial "components/endnotes" . }}
<div class="book-footer">
- <p>于 <time
- data-pagefind-sort="date[data-date], weight[data-weight]"
- data-date="{{ .Date.Format "2006-01-02" }}"
- data-weight="10">{{ .Date.Format "2006-01-02" }}</time> 读完</p>
+ <p>于 {{ partial "components/date" . }} 读完</p>
</div>
</div>
{{ partial "components/comment.html" . }}
diff --git a/layouts/partials/components/category-pill.html b/layouts/partials/components/category-pill.html
new file mode 100644
index 00000000..aeb25747
--- /dev/null
+++ b/layouts/partials/components/category-pill.html
@@ -0,0 +1,8 @@
+{{ with .GetTerms "categories" }}
+ {{ with index . 0 }}
+ <a class="post-category" href="{{ .RelPermalink }}">
+ {{ .Params.icon }}
+ <span>{{ .LinkTitle }}</span>
+ </a>
+ {{ end }}
+{{ end }}
diff --git a/layouts/partials/components/date.html b/layouts/partials/components/date.html
new file mode 100644
index 00000000..1998202f
--- /dev/null
+++ b/layouts/partials/components/date.html
@@ -0,0 +1,26 @@
+{{ if .Date }}
+ {{ $hour := .Date.Hour }}
+ {{ $fuzzyTimes := slice
+ (dict "limit" 5 "label" "凌晨")
+ (dict "limit" 7 "label" "清晨")
+ (dict "limit" 11 "label" "早上")
+ (dict "limit" 13 "label" "中午")
+ (dict "limit" 17 "label" "下午")
+ (dict "limit" 19 "label" "傍晚")
+ (dict "limit" 22 "label" "晚上")
+ }}
+ {{ $fuzzyTime := "深夜" }} {{/* default */}}
+ {{ range $fuzzyTimes }}
+ {{ if lt $hour .limit }}
+ {{ $fuzzyTime = .label }}
+ {{ break }}
+ {{ end }}
+ {{ end }}
+
+ <time class="post-date"
+ datetime="{{ .Date.Format "2006-01-02 15:04:05 MST" }}"
+ data-pagefind-sort="date[datetime], weight[data-weight]"
+ data-weight="{{ if .Params.featured }}30{{ else }}20{{ end }}">
+ {{ .Date.Format "2006年1月2日" }} {{ $fuzzyTime }}
+ </time>
+{{ end }}
diff --git a/layouts/partials/components/endnotes.html b/layouts/partials/components/endnotes.html
new file mode 100644
index 00000000..e7245ad4
--- /dev/null
+++ b/layouts/partials/components/endnotes.html
@@ -0,0 +1,10 @@
+{{ if .Params.endnotes }}
+<hr>
+<div id="post-endnotes">
+ <ul>
+ {{ range .Params.endnotes }}
+ <li>{{ . | markdownify }}</li>
+ {{ end }}
+ </ul>
+</div>
+{{ end }}
diff --git a/layouts/partials/components/now-read-this.html b/layouts/partials/components/now-read-this.html
new file mode 100644
index 00000000..6f2950c2
--- /dev/null
+++ b/layouts/partials/components/now-read-this.html
@@ -0,0 +1,19 @@
+{{ with site.RegularPages.Related . | first 1 }}
+<div class="nrt post-content">
+ <h4 class="nrt-title">{{ T "nowReadThis" }}</h4>
+ {{ range . }}
+ <div class="nrt-header">
+ <a class="nrt-link" href="{{ .RelPermalink }}" data-umami-event="🤔 Click Related Post">
+ {{ .LinkTitle }}
+ {{ with .Params.subtitle }}
+ <span class="nrt-subtitle">:{{ . }}</span>
+ {{ end }}
+ </a>
+ <span class="nrt-reading-time">⏱️ {{ .ReadingTime }}min </span>
+ </div>
+ <div class="nrt-summary">
+ <p>{{ .Summary | plainify }}</p>
+ </div>
+ {{ end }}
+</div>
+{{ end }}
diff --git a/layouts/partials/components/toc.html b/layouts/partials/components/toc.html
index eb75badd..794328c9 100644
--- a/layouts/partials/components/toc.html
+++ b/layouts/partials/components/toc.html
@@ -1,3 +1,4 @@
+{{ if .Params.toc }}
<div id="toc-container"><div id="toc">{{ .TableOfContents }}</div></div>
<style>
/* toc */
@@ -113,3 +114,4 @@ document.addEventListener('DOMContentLoaded', () => {
headings.forEach(heading => observer.observe(heading));
});
</script>
+{{ end }}
diff --git a/layouts/posts/single.html b/layouts/posts/single.html
index 71716a82..86d595d6 100644
--- a/layouts/posts/single.html
+++ b/layouts/posts/single.html
@@ -16,38 +16,9 @@
</h1>
<!-- Post Meta -->
<div class="post-meta">
- {{ if .Date }}
- {{ $hour := .Date.Hour }}
- {{ $fuzzyTimes := slice
- (dict "limit" 5 "label" "凌晨")
- (dict "limit" 7 "label" "清晨")
- (dict "limit" 11 "label" "早上")
- (dict "limit" 13 "label" "中午")
- (dict "limit" 17 "label" "下午")
- (dict "limit" 19 "label" "傍晚")
- (dict "limit" 22 "label" "晚上")
- }}
- {{ $fuzzyTime := "深夜" }} {{/* default */}}
- {{ range $fuzzyTimes }}
- {{ if lt $hour .limit }}
- {{ $fuzzyTime = .label }}
- {{ break }}
- {{ end }}
- {{ end }}
-
- <time class="post-date"
- datetime="{{ .Date.Format "2006-01-02 15:04:05 MST" }}"
- data-pagefind-sort="date[datetime], weight[data-weight]"
- data-weight="{{ if .Params.featured }}30{{ else }}20{{ end }}">
- {{ .Date.Format "2006年1月2日" }} {{ $fuzzyTime }}
- </time>
- {{ end }}
- {{ if or .Params.categories .Params.tags }}
- <span>·</span>
- {{ end }}
- {{ if .Params.categories }}
- <a class="post-category" href="/categories/{{ .Params.categories | urlize }}">{{ .Params.categories }}</a>
- {{ end }}
+ {{ partial "components/date" . }}
+ {{ if or .Params.categories .Params.tags }}<span>·</span>{{ end }}
+ {{ partial "components/category-pill" . }}
{{ range .Params.tags }}
<a class="post-tag" href="{{ site.LanguagePrefix }}/tags/{{ lower . | urlize }}/">#{{ . }}</a>
{{ end }}
@@ -58,46 +29,18 @@
<div class="post-content markdown-body"
style="view-transition-name: post-content-{{ .File.UniqueID }}">
<!-- TOC -->
- {{ if .Params.toc }}
{{ partial "components/toc" . }}
- {{ end }}
<!-- Content -->
- <div id="post-content">{{ .Content }}</div>
- <!-- Endnotes -->
- {{ if .Params.endnotes }}
- <hr>
- <div id="post-endnotes">
- <ul>
- {{ range .Params.endnotes }}
- <li>{{ . | markdownify }}</li>
- {{ end }}
- </ul>
+ <div id="post-content">
+ {{ .Content }}
</div>
- {{ end }}
+ <!-- Endnotes -->
+ {{ partial "components/endnotes" . }}
</div>
<!-- Comment -->
{{ partial "components/comment.html" . }}
-
<!-- Now Read This -->
- {{ with site.RegularPages.Related . | first 1 }}
- <div class="nrt post-content">
- <h4 class="nrt-title">{{ T "nowReadThis" }}</h4>
- {{ range . }}
- <div class="nrt-header">
- <a class="nrt-link" href="{{ .RelPermalink }}" data-umami-event="🤔 Click Related Post">
- {{ .LinkTitle }}
- {{ with .Params.subtitle }}
- <span class="nrt-subtitle">:{{ . }}</span>
- {{ end }}
- </a>
- <span class="nrt-reading-time">⏱️ {{ .ReadingTime }}min </span>
- </div>
- <div class="nrt-summary">
- <p>{{ .Summary | plainify }}</p>
- </div>
- {{ end }}
- </div>
- {{ end }}
+ {{ partial "components/now-read-this.html" . }}
</article>
{{ end }}