aboutsummaryrefslogtreecommitdiffstats
path: root/layouts/shortcodes
diff options
context:
space:
mode:
authorverdant <i@glowisle.me>2026-04-11 18:27:20 +0800
committerverdant <i@glowisle.me>2026-04-11 18:27:20 +0800
commit31cd7a3067a9996b7140aeaefb6c97e08db2f78f (patch)
tree752ea978c1e6e1f0dd24cd15d129034a6bb18c34 /layouts/shortcodes
parent92e642b3d9e2df106e6ad3aa38e4be6966d44268 (diff)
downloadblog-31cd7a3067a9996b7140aeaefb6c97e08db2f78f.tar.gz
blog-31cd7a3067a9996b7140aeaefb6c97e08db2f78f.zip
update
Diffstat (limited to 'layouts/shortcodes')
-rw-r--r--layouts/shortcodes/archives-list.html57
-rw-r--r--layouts/shortcodes/word-count.html70
2 files changed, 60 insertions, 67 deletions
diff --git a/layouts/shortcodes/archives-list.html b/layouts/shortcodes/archives-list.html
index b9767f7..738e368 100644
--- a/layouts/shortcodes/archives-list.html
+++ b/layouts/shortcodes/archives-list.html
@@ -1,30 +1,35 @@
+<header>
+<a href="{{ "" | relURL }}" class="title">
+ <p class="site-title">{{ .Site.Title }}</p>
+</a>
+<nav>{{- partial "nav.html" . -}}</nav>
+
+</header>
+
{{ $allPages := where .Site.RegularPages "Type" "in" (slice "posts" "blog") }}
-{{ $visiblePages := where $allPages "Params.hidden" "!=" true }}
-{{ $pagesToShow := $visiblePages.ByDate.Reverse }}
+{{ $visiblePages := where $allPages "Params.hidden" "!=" true }} {{ $pagesToShow
+:= $visiblePages.ByDate.Reverse }}
<div class="archives-content">
- <h2>归档</h2>
-
- <p>共有 {{ len $pagesToShow }} 篇文章</p>
-
- <ul class="blog-posts">
- {{ $currentYear := 0 }}
- {{ range $pagesToShow }}
- {{ $year := .Date.Year }}
- {{ if ne $year $currentYear }}
- <h3>{{ $year }}</h3>
- {{ $currentYear = $year }}
- {{ end }}
- <li>
- <span>
- <i>
- <time datetime='{{ .Date.Format "2006-01-02" }}'>
- {{ .Date.Format "2006-01-02" }}
- </time>
- </i>
- </span>
- <a href="{{ .Permalink }}">{{ .Title }}</a>
- </li>
- {{ end }}
- </ul>
+ <h2>归档</h2>
+
+ <p>共有 {{ len $pagesToShow }} 篇文章</p>
+
+ <ul class="blog-posts">
+ {{ $currentYear := 0 }} {{ range $pagesToShow }} {{ $year := .Date.Year }}
+ {{ if ne $year $currentYear }}
+ <h3>{{ $year }}</h3>
+ {{ $currentYear = $year }} {{ end }}
+ <li>
+ <span>
+ <i>
+ <time datetime='{{ .Date.Format "2006-01-02" }}'>
+ {{ .Date.Format "2006-01-02" }}
+ </time>
+ </i>
+ </span>
+ <a href="{{ .Permalink }}">{{ .Title }}</a>
+ </li>
+ {{ end }}
+ </ul>
</div>
diff --git a/layouts/shortcodes/word-count.html b/layouts/shortcodes/word-count.html
index 38dbe0e..20599f6 100644
--- a/layouts/shortcodes/word-count.html
+++ b/layouts/shortcodes/word-count.html
@@ -1,41 +1,29 @@
-{{ $scratch := newScratch }} {{ if eq (.Get 0) "posts" }} {{ range where
-site.RegularPages "Type" "in" (slice "posts" "jottings" "readings" "tech") }} {{
-if not (in .Params.categories "!往昔!") }} {{ $scratch.Add "wordcount" .WordCount
-}} {{ end }} {{ end }} {{ else if eq (.Get 0) "all" }} {{ range where
-site.RegularPages "Type" "in" (slice "posts" "about" "newsgroup" "links"
-"jottings" "readings" "tech") }} {{ if not (in .Params.categories "!往昔") }} {{
-$scratch.Add "wordcount" .WordCount }} {{ end }} {{ end }} {{ end }} {{ $count
-:= $scratch.Get "wordcount" }} {{ if gt $count 0 }} {{ $count }} 字, {{/*
-名著数据库(字数单位:汉字) */}} {{ $classics := slice (dict "name" "红楼梦"
-"author" "曹雪芹" "country" "(中)" "words" 731017) (dict "name" "源氏物语"
-"author" "紫式部" "country" "(日)" "words" 876000) (dict "name" "假面的告白"
-"author" "三岛由纪夫" "country" "(日)" "words" 86000) (dict "name" "金阁寺"
-"author" "三岛由纪夫" "country" "(日)" "words" 125000) (dict "name"
-"了不起的盖茨比" "author" "菲茨杰拉德" "country" "(美)" "words" 49800) (dict
-"name" "傲慢与偏见" "author" "简·奥斯汀" "country" "(英)" "words" 183000)
-(dict "name" "呐喊" "author" "鲁迅" "country" "(中)" "words" 152000) (dict
-"name" "罗生门" "author" "芥川龙之介" "country" "(日)" "words" 35800) (dict
-"name" "老人与海" "author" "海明威" "country" "(美)" "words" 26800) (dict
-"name" "简爱" "author" "夏洛蒂·勃朗特" "country" "(英)" "words" 322000) (dict
-"name" "三国演义" "author" "罗贯中" "country" "(中)" "words" 640000) (dict
-"name" "雪国" "author" "川端康成" "country" "(日)" "words" 78000) (dict "name"
-"杀死一只知更鸟" "author" "哈珀·李" "country" "(美)" "words" 187000) (dict
-"name" "1984" "author" "乔治·奥威尔" "country" "(英)" "words" 123000) (dict
-"name" "围城" "author" "钱钟书" "country" "(中)" "words" 257000) (dict "name"
-"我是猫" "author" "夏目漱石" "country" "(日)" "words" 402000) (dict "name"
-"飘" "author" "玛格丽特·米切尔" "country" "(美)" "words" 802000) (dict "name"
-"呼啸山庄" "author" "艾米莉·勃朗特" "country" "(英)" "words" 282000) }} {{/*
-寻找最接近的名著 */}} {{ $closest := dict "diff" 999999999 "book" (index
-$classics 0) }} {{ range $book := $classics }} {{ $ratio := div (float $count)
-$book.words }} {{ if and (ge $ratio 0.8) (le $ratio 1.2) }} {{ $diff := sub
-$ratio 1.0 }} {{ if lt $diff 0 }}{{ $diff = mul $diff -1 }}{{ end }} {{ if lt
-$diff $closest.diff }} {{ $closest = dict "diff" $diff "book" $book }} {{ end }}
-{{ end }} {{ end }} {{/* 输出对比结果 */}} {{ with $closest.book }} 约等于 《{{
-.name }}》 的{{ div (float $count) .words | printf "%.1f" }}倍 {{ else }} {{/*
-未找到匹配时显示长度最接近的名著 */}} {{ $closestBook := index $classics 0 }} {{
-$minDiff := sub $count $closestBook.words }} {{ if lt $minDiff 0 }}{{ $minDiff =
-mul $minDiff -1 }}{{ end }} {{ range $classics }} {{ $currDiff := sub $count
-.words }} {{ if lt $currDiff 0 }}{{ $currDiff = mul $currDiff -1 }}{{ end }} {{
-if lt $currDiff $minDiff }} {{ $closestBook = . }} {{ $minDiff = $currDiff }} {{
-end }} {{ end }} ≈ {{ $closestBook.name }}{{ div (float $count)
-$closestBook.words | printf "%.1f" }}倍 {{ end }} {{ else }} 0字 {{ end }}
+{{ $scratch := newScratch }} {{ $scope := .Get 0 | default "posts" }} {{ $pages
+:= where site.RegularPages "Type" "in" (slice "posts" "jottings" "readings"
+"tech") }} {{ if eq $scope "all" }} {{ $pages = where site.RegularPages "Type"
+"in" (slice "posts" "about" "newsgroup" "links" "jottings" "readings" "tech") }}
+{{ end }} {{ range $pages }} {{ if not (in .Params.categories "!往昔!") }} {{
+$scratch.Add "wordcount" .WordCount }} {{ end }} {{ end }} {{ $count :=
+$scratch.Get "wordcount" }} {{ if gt $count 0 }}
+<div class="stats-container" style="line-height: 1.8; font-family: inherit">
+ <p>
+ 共书写了 <strong>{{ lang.FormatNumber 0 $count }}</strong> 字,{{ $readTime
+ := div $count 400 }}预计需要阅读
+ <strong
+ >{{ if lt $readTime 60 }}{{ $readTime }} 分钟{{ else }}{{ div (float
+ $readTime) 60 | printf "%.1f" }} 小时{{ end }}</strong
+ >
+ ,{{ $classics := slice (dict "name" "红楼梦" "words" 731017) (dict "name"
+ "金阁寺" "words" 125000) (dict "name" "了不起的盖茨比" "words" 49800) (dict
+ "name" "呐喊" "words" 152000) (dict "name" "老人与海" "words" 26800) (dict
+ "name" "1984" "words" 123000) (dict "name" "围城" "words" 257000) (dict
+ "name" "飘" "words" 802000) }} {{ $closestBook := index $classics 0 }} {{
+ $minDiff := 99999999 }} {{ range $classics }} {{ $diff := sub $count .words
+ }}{{ if lt $diff 0 }}{{ $diff = mul $diff -1 }}{{ end }} {{ if lt $diff
+ $minDiff }} {{ $minDiff = $diff }} {{ $closestBook = . }} {{ end }} {{ end
+ }} {{ $ratio := div (float $count) $closestBook.words }}相当于写了
+ <strong>{{ $ratio | printf "%.2f" }}</strong> 本《{{ $closestBook.name
+ }}》。
+ </p>
+</div>
+{{ end }}