summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-06-05 13:06:36 +0800
committerEltrac <hi@guhub.cn>2025-06-05 13:06:36 +0800
commit871662725c287c73fcf55a1212f176679a690f04 (patch)
tree74c6dfb9e92788d84394cbeb576875093b199b43
parente1e10964030858ce41cb0cf578c9f2abeab018f1 (diff)
chore: configure pagefind for better UX
- set up correct title metadata - set up sorting data - exclude certain selectors
-rw-r--r--layouts/cards/single.html8
-rw-r--r--layouts/fictions/single.html9
-rw-r--r--layouts/library/single.html7
-rw-r--r--layouts/posts/single.html7
-rw-r--r--pagefind.yml9
5 files changed, 32 insertions, 8 deletions
diff --git a/layouts/cards/single.html b/layouts/cards/single.html
index a4d2a9f1..d75d1ffa 100644
--- a/layouts/cards/single.html
+++ b/layouts/cards/single.html
@@ -10,7 +10,13 @@
<div class="card markdown-body post-content"
style="view-transition-name: card-{{ .File.UniqueID }}">
<div class="card-header">
- <h3 class="card-title">{{ .Title }}</h3>
+ <h3 class="card-title"
+ data-pagefind-meta="title"
+ data-pagefind-sort="date[data-date], weight[data-weight]"
+ data-date="{{ .Date.Format "2006-01-02" }}"
+ data-weight="5">
+ {{ .Title }}
+ </h3>
{{- if .Params.tags }}
<p class="card-tags">
{{- range .Params.tags }}
diff --git a/layouts/fictions/single.html b/layouts/fictions/single.html
index 85ab59de..e16dd4c7 100644
--- a/layouts/fictions/single.html
+++ b/layouts/fictions/single.html
@@ -10,11 +10,14 @@
class="post-header fiction-header"
>
{{ partial "components/banner.html" . }}
- <h1 class="post-title">{{ .Title }}</h1>
+ <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" }}">
- {{ .Date.Format "2006-1-2" }}
+ <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>
diff --git a/layouts/library/single.html b/layouts/library/single.html
index 3bd00ca3..fa53149b 100644
--- a/layouts/library/single.html
+++ b/layouts/library/single.html
@@ -8,7 +8,7 @@
src="{{ .Params.cover }}"
/>
</div>
- <h1 class="book-title">{{ .Title }}</h1>
+ <h1 class="book-title" data-pagefind-meta="title">{{ .Title }}</h1>
{{- $rating := .Params.rating -}}
{{- $fullStars := math.Floor $rating -}}
<p class="book-author">
@@ -35,7 +35,10 @@
{{ .Content }}
</div>
<div class="book-footer">
- <p>于 {{ .Date.Format "2006-01-02" }} 读完</p>
+ <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>
</div>
</div>
{{ partial "components/comment.html" . }}
diff --git a/layouts/posts/single.html b/layouts/posts/single.html
index 0fe65678..d31c9f30 100644
--- a/layouts/posts/single.html
+++ b/layouts/posts/single.html
@@ -9,7 +9,7 @@
{{ partial "components/banner.html" . }}
<!-- Title and Subtitle -->
<h1 class="post-title">
- {{ .Title }}
+ <span data-pagefind-meta="title">{{ .Title }}</span>
{{ with .Params.subtitle }}
<small class="post-subtitle">{{ . }}</small>
{{ end }}
@@ -37,7 +37,10 @@
{{ $fuzzyTime = "深夜" }}
{{ end }}
- <time class="post-date" datetime="{{ .Date.Format "2006-01-02 15:04:05 MST" }}">
+ <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/pagefind.yml b/pagefind.yml
new file mode 100644
index 00000000..e3c2c723
--- /dev/null
+++ b/pagefind.yml
@@ -0,0 +1,9 @@
+site: public
+exclude_selectors:
+ - "#footer"
+ - "#site-header"
+ - "#latest-posts"
+ - "#posts-archive"
+ - ".cards-section"
+ - "#fiction-section"
+ - "#library"