From e82a6549a622a4d8116cf503ea949e0076938247 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Fri, 20 May 2022 11:30:19 +0800 Subject: [PATCH] :sparkles: Feat: add total word count feature in section and remove from footer (#124) --- CHANGELOG.md | 1 + assets/css/_page/_archive.scss | 15 +++++++++++++++ i18n/de.toml | 8 ++++---- i18n/en.toml | 8 ++++---- i18n/es.toml | 8 ++++---- i18n/fr.toml | 8 ++++---- i18n/it.toml | 8 ++++---- i18n/pl.toml | 8 ++++---- i18n/pt-BR.toml | 8 ++++---- i18n/ro.toml | 8 ++++---- i18n/ru.toml | 8 ++++---- i18n/sr.toml | 8 ++++---- i18n/vi.toml | 8 ++++---- i18n/zh-CN.toml | 6 +++--- i18n/zh-TW.toml | 6 +++--- layouts/_default/section.html | 30 ++++++++++++++++++++++++------ layouts/partials/footer.html | 17 ----------------- 17 files changed, 90 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fe9ca5c2..9d5cba571 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. > Add hugo new features support. > Snapshot: +- :sparkles: Feat: add total word count feature in section and remove from footer ([#124](https://github.com/Lruihao/FixIt/issues/124)) - :sparkles: Feat: enhance auto toc feature ([#104](https://github.com/Lruihao/FixIt/issues/104) [#136](https://github.com/Lruihao/FixIt/issues/136)) - :sparkles: Feat(SEO): add options to make output baidu_urls.txt file ([#138](https://github.com/Lruihao/FixIt/issues/138)) - :bug: Fix: Giscus comments invalid config `inputPosition` diff --git a/assets/css/_page/_archive.scss b/assets/css/_page/_archive.scss index 3f606dbe8..af981d1c0 100644 --- a/assets/css/_page/_archive.scss +++ b/assets/css/_page/_archive.scss @@ -1,9 +1,24 @@ .archive { .single-title { + padding: 1rem 0 0.5rem; + margin: 0; + font-size: 1.6rem; + font-weight: bold; + line-height: 140%; + text-align: right; + } + + .single-subtitle { + margin: 0.4rem 0; + font-size: 1.2rem; + font-weight: normal; + font-style: italic; + line-height: 100%; text-align: right; } .group-title { + font-size: 1.2rem; margin-top: 1.5rem; margin-bottom: 1rem; } diff --git a/i18n/de.toml b/i18n/de.toml index fd2b2f6ec..c6518ed76 100644 --- a/i18n/de.toml +++ b/i18n/de.toml @@ -33,6 +33,10 @@ other = "Artikel" [allSome] other = "Alle {{ .Some }}" +[totalwordCount] +one = "" # waitting for translation +other = "" # waitting for translation + [tag] other = "Tag" @@ -152,10 +156,6 @@ other = "enthalten in {{ .Categories }}" one = "Ein wort" other = "{{ .Count }} wörter" -[totalwordCount] -one = "" # waitting for translation -other = "" # waitting for translation - [readingTime] one = "Eine minute" other = "{{ .Count }} minuten" diff --git a/i18n/en.toml b/i18n/en.toml index 0b1c050b9..12c40a48b 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -32,6 +32,10 @@ other = "Posts" [allSome] other = "All {{ .Some }}" +[totalwordCount] +one = "Total one word" +other = "Total {{ .Count }} words" + [tag] other = "Tag" @@ -148,10 +152,6 @@ other = "included in {{ .Categories }}" one = "One word" other = "{{ .Count }} words" -[totalwordCount] -one = "Total one word" -other = "Total {{ .Count }} words" - [readingTime] one = "One minute" other = "{{ .Count }} minutes" diff --git a/i18n/es.toml b/i18n/es.toml index 3fcd9840c..0c2649231 100644 --- a/i18n/es.toml +++ b/i18n/es.toml @@ -33,6 +33,10 @@ other = "Artículos" [allSome] other = "Todo {{ .Some }}" +[totalwordCount] +one = "" # waitting for translation +other = "" # waitting for translation + [tag] other = "Etiqueta" @@ -152,10 +156,6 @@ other = "incluido en {{ .Categories }}" one = "Una palabra" other = "{{ .Count }} palabras" -[totalwordCount] -one = "" # waitting for translation -other = "" # waitting for translation - [readingTime] one = "Un minuto" other = "{{ .Count }} minutos" diff --git a/i18n/fr.toml b/i18n/fr.toml index b48502a2e..dec8fb005 100644 --- a/i18n/fr.toml +++ b/i18n/fr.toml @@ -33,6 +33,10 @@ other = "Posts" [allSome] other = "Tous {{ .Some }}" +[totalwordCount] +one = "" # waitting for translation +other = "" # waitting for translation + [tag] other = "Balise" @@ -152,10 +156,6 @@ other = "inclus dans {{ .Categories }}" one = "Un mot" other = "{{ .Count }} mots" -[totalwordCount] -one = "" # waitting for translation -other = "" # waitting for translation - [readingTime] one = "Une minute" other = "{{ .Count }} minutes" diff --git a/i18n/it.toml b/i18n/it.toml index b57153d62..c0c473161 100644 --- a/i18n/it.toml +++ b/i18n/it.toml @@ -33,6 +33,10 @@ other = "Articoli" [allSome] other = "Tutti {{ .Some }}" +[totalwordCount] +one = "" # waitting for translation +other = "" # waitting for translation + [tag] other = "Etichetta" @@ -152,10 +156,6 @@ other = "incluso in {{ .Categories }}" one = "Una parola" other = "{{ .Count }} parole" -[totalwordCount] -one = "" # waitting for translation -other = "" # waitting for translation - [readingTime] one = "Un minuto" other = "{{ .Count }} minuti" diff --git a/i18n/pl.toml b/i18n/pl.toml index 8ef4ae129..b765a6344 100644 --- a/i18n/pl.toml +++ b/i18n/pl.toml @@ -33,6 +33,10 @@ other = "Posty" [allSome] other = "Wszystkie {{ .Some }}" +[totalwordCount] +one = "" # waitting for translation +other = "" # waitting for translation + [tag] other = "Tag" @@ -149,10 +153,6 @@ other = "zawarty w {{ .Categories }}" one = "Jedno słowo" other = "{{ .Count }} słów" -[totalwordCount] -one = "" # waitting for translation -other = "" # waitting for translation - [readingTime] one = "Jedna minuta" other = "{{ .Count }} minuty" diff --git a/i18n/pt-BR.toml b/i18n/pt-BR.toml index 7a93d62e6..06a14614a 100644 --- a/i18n/pt-BR.toml +++ b/i18n/pt-BR.toml @@ -33,6 +33,10 @@ other = "Posts" [allSome] other = "Todos {{ .Some }}" +[totalwordCount] +one = "" # waitting for translation +other = "" # waitting for translation + [tag] other = "Tag" @@ -152,10 +156,6 @@ other = "incluido em {{ .Categories }}" one = "Uma palavra" other = "{{ .Count }} palavras" -[totalwordCount] -one = "" # waitting for translation -other = "" # waitting for translation - [readingTime] one = "Um minuto" other = "{{ .Count }} minutos" diff --git a/i18n/ro.toml b/i18n/ro.toml index f2090fd61..f8a490772 100644 --- a/i18n/ro.toml +++ b/i18n/ro.toml @@ -33,6 +33,10 @@ other = "Articole" [allSome] other = "Toate {{ .Some }}" +[totalwordCount] +one = "" # waitting for translation +other = "" # waitting for translation + [tag] other = "Etichetă" @@ -152,10 +156,6 @@ other = "inclus în {{ .Categories }}" one = "Un cuvânt" other = "{{ .Count }} cuvinte" -[totalwordCount] -one = "" # waitting for translation -other = "" # waitting for translation - [readingTime] one = "Un minut" other = "{{ .Count }} minute" diff --git a/i18n/ru.toml b/i18n/ru.toml index b1c70986f..0e877dabc 100644 --- a/i18n/ru.toml +++ b/i18n/ru.toml @@ -33,6 +33,10 @@ other = "Статьи" [allSome] other = "Все {{ .Some }}" +[totalwordCount] +one = "" # waitting for translation +other = "" # waitting for translation + [tag] other = "Тэг" @@ -152,10 +156,6 @@ other = "включен в {{ .Categories }}" one = "Одно слово" other = "{{ .Count }} слов" -[totalwordCount] -one = "" # waitting for translation -other = "" # waitting for translation - [readingTime] one = "Одна минута" other = "{{ .Count }} минут" diff --git a/i18n/sr.toml b/i18n/sr.toml index 80aba4f8c..930b6841e 100644 --- a/i18n/sr.toml +++ b/i18n/sr.toml @@ -33,6 +33,10 @@ other = "Постови" [allSome] other = "Све {{ .Some }}" +[totalwordCount] +one = "" # waitting for translation +other = "" # waitting for translation + [tag] other = "Таг" @@ -149,10 +153,6 @@ other = "укључено {{ .Categories }}" one = "Једна реч" other = "{{ .Count }} речи" -[totalwordCount] -one = "" # waitting for translation -other = "" # waitting for translation - [readingTime] one = "Један минут" other = "{{ .Count }} минута" diff --git a/i18n/vi.toml b/i18n/vi.toml index 003976d9d..bf5b7fe19 100644 --- a/i18n/vi.toml +++ b/i18n/vi.toml @@ -32,6 +32,10 @@ other = "Bài viết" [allSome] other = "Tất cả {{ .Some }}" +[totalwordCount] +one = "" # waitting for translation +other = "" # waitting for translation + [tag] other = "Nhãn" @@ -151,10 +155,6 @@ other = "trong {{ .Categories }}" one = "One word" other = "{{ .Count }} từ" -[totalwordCount] -one = "" # waitting for translation -other = "" # waitting for translation - [readingTime] one = "One minute" other = "{{ .Count }} phút" diff --git a/i18n/zh-CN.toml b/i18n/zh-CN.toml index 5031b2d58..c6e4e5d7b 100644 --- a/i18n/zh-CN.toml +++ b/i18n/zh-CN.toml @@ -33,6 +33,9 @@ other = "文章" [allSome] other = "所有{{ .Some }}" +[totalwordCount] +other = "总计约 {{ .Count }} 字" + [tag] other = "标签" @@ -154,9 +157,6 @@ other = "收录于 {{ .Categories }}" [wordCount] other = "约 {{ .Count }} 字" -[totalwordCount] -other = "总计约 {{ .Count }} 字" - [readingTime] other = "预计阅读 {{ .Count }} 分钟" diff --git a/i18n/zh-TW.toml b/i18n/zh-TW.toml index 77b399fc7..d3d019086 100644 --- a/i18n/zh-TW.toml +++ b/i18n/zh-TW.toml @@ -33,6 +33,9 @@ other = "文章" [allSome] other = "所有{{ .Some }}" +[totalwordCount] +other = "總計約 {{ .Count }} 字" + [tag] other = "標籤" @@ -154,9 +157,6 @@ other = "收錄於 {{ .Categories }}" [wordCount] other = "約 {{ .Count }} 字" -[totalwordCount] -other = "總計約 {{ .Count }} 字" - [readingTime] other = "預計閱讀 {{ .Count }} 分鐘" diff --git a/layouts/_default/section.html b/layouts/_default/section.html index ee64a0128..6396fac7c 100644 --- a/layouts/_default/section.html +++ b/layouts/_default/section.html @@ -4,11 +4,29 @@ {{- define "content" -}}
- {{- /* Title */ -}} -

- {{- .Params.Title | default (T .Section) | default .Section | dict "Some" | T "allSome" }} - {{- len .Pages -}} -

+
+ {{- /* Title */ -}} +

+ {{- .Params.Title | default (T .Section) | default .Section | dict "Some" | T "allSome" }} + {{- len .Pages -}} +

+ {{- /* Total word count */ -}} + {{- /* See https://github.com/Lruihao/FixIt/issues/124 */ -}} + {{- $localData := newScratch -}} + {{- range .Pages -}} + {{- $localData.Add "totalWordCount" .WordCount -}} + {{- end -}} + {{- with ($localData.Get "totalWordCount") -}} + {{- $humanizedNum := . -}} + {{- if ge $humanizedNum 1000 -}} + {{- $humanizedNum = printf "%.2fK" (div $humanizedNum 1000.0) -}} + {{- end -}} +

+ + {{ T "totalwordCount" (dict "Count" $humanizedNum) -}} +

+ {{- end -}} +
{{- /* Paginate */ -}} {{- if .Pages -}} @@ -20,7 +38,7 @@

{{- end -}} {{- partial "recently-updated.html" . -}} {{- range $pages.PageGroups -}} -

{{ .Key }}

+

{{ .Key }}

{{- range .Pages -}}
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 50b012eb7..fc3927222 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -50,23 +50,6 @@ {{- if .Site.Params.footer.siteTime -}}  {{- T "siteRunning" -}} {{- end -}} - - {{- /* Total word count */ -}} - {{- /* There is a fatal bug. See https://github.com/Lruihao/FixIt/issues/124 */ -}} - {{- /* if ne .Site.Params.footer.wordCount false */ -}} - {{- if false -}} - {{- $localData := newScratch -}} - {{- range (where .Site.Pages "Kind" "page") -}} - {{- $localData.Add "totalWordCount" .WordCount -}} - {{- end -}} - {{- with ($localData.Get "totalWordCount") -}} - {{- $humanizedNum := . -}} - {{- if ge $humanizedNum 1000 -}} - {{- $humanizedNum = printf "%.2fK" (div $humanizedNum 1000.0) -}} - {{- end -}} -  {{- T "totalwordCount" (dict "Count" $humanizedNum) -}} - {{- end -}} - {{- end -}}
{{- end -}}