summaryrefslogtreecommitdiff
path: root/layouts/partials
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
commited5fe0848d18665cd3fbd6011876207b2fee61e4 (patch)
tree6a6fefb50c40489c439552ab1fcd4c0beb94c34d /layouts/partials
parent8f45cd85ea4d00cd1d0bb8a13c2f70c760d32a4c (diff)
refactor: reuse some page components
Diffstat (limited to 'layouts/partials')
-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
5 files changed, 65 insertions, 0 deletions
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 }}