blob: 20599f6a9b2dcfc59eb728305d41f722966b7b54 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
{{ $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 }}
|