Skip to content

Commit

Permalink
✨ Feat: add total word count feature in section and remove from footer (
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed May 20, 2022
1 parent a7c3055 commit e82a654
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 73 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
15 changes: 15 additions & 0 deletions assets/css/_page/_archive.scss
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions i18n/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ other = "Artikel"
[allSome]
other = "Alle {{ .Some }}"

[totalwordCount]
one = "" # waitting for translation
other = "" # waitting for translation

[tag]
other = "Tag"

Expand Down Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ other = "Posts"
[allSome]
other = "All {{ .Some }}"

[totalwordCount]
one = "Total one word"
other = "Total {{ .Count }} words"

[tag]
other = "Tag"

Expand Down Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions i18n/es.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ other = "Artículos"
[allSome]
other = "Todo {{ .Some }}"

[totalwordCount]
one = "" # waitting for translation
other = "" # waitting for translation

[tag]
other = "Etiqueta"

Expand Down Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions i18n/fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ other = "Posts"
[allSome]
other = "Tous {{ .Some }}"

[totalwordCount]
one = "" # waitting for translation
other = "" # waitting for translation

[tag]
other = "Balise"

Expand Down Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions i18n/it.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ other = "Articoli"
[allSome]
other = "Tutti {{ .Some }}"

[totalwordCount]
one = "" # waitting for translation
other = "" # waitting for translation

[tag]
other = "Etichetta"

Expand Down Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions i18n/pl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ other = "Posty"
[allSome]
other = "Wszystkie {{ .Some }}"

[totalwordCount]
one = "" # waitting for translation
other = "" # waitting for translation

[tag]
other = "Tag"

Expand Down Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions i18n/pt-BR.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ other = "Posts"
[allSome]
other = "Todos {{ .Some }}"

[totalwordCount]
one = "" # waitting for translation
other = "" # waitting for translation

[tag]
other = "Tag"

Expand Down Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions i18n/ro.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ other = "Articole"
[allSome]
other = "Toate {{ .Some }}"

[totalwordCount]
one = "" # waitting for translation
other = "" # waitting for translation

[tag]
other = "Etichetă"

Expand Down Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions i18n/ru.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ other = "Статьи"
[allSome]
other = "Все {{ .Some }}"

[totalwordCount]
one = "" # waitting for translation
other = "" # waitting for translation

[tag]
other = "Тэг"

Expand Down Expand Up @@ -152,10 +156,6 @@ other = "включен в {{ .Categories }}"
one = "Одно слово"
other = "{{ .Count }} слов"

[totalwordCount]
one = "" # waitting for translation
other = "" # waitting for translation

[readingTime]
one = "Одна минута"
other = "{{ .Count }} минут"
Expand Down
8 changes: 4 additions & 4 deletions i18n/sr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ other = "Постови"
[allSome]
other = "Све {{ .Some }}"

[totalwordCount]
one = "" # waitting for translation
other = "" # waitting for translation

[tag]
other = "Таг"

Expand Down Expand Up @@ -149,10 +153,6 @@ other = "укључено {{ .Categories }}"
one = "Једна реч"
other = "{{ .Count }} речи"

[totalwordCount]
one = "" # waitting for translation
other = "" # waitting for translation

[readingTime]
one = "Један минут"
other = "{{ .Count }} минута"
Expand Down
8 changes: 4 additions & 4 deletions i18n/vi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions i18n/zh-CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ other = "文章"
[allSome]
other = "所有{{ .Some }}"

[totalwordCount]
other = "总计约 {{ .Count }} 字"

[tag]
other = "标签"

Expand Down Expand Up @@ -154,9 +157,6 @@ other = "收录于 {{ .Categories }}"
[wordCount]
other = "约 {{ .Count }} 字"

[totalwordCount]
other = "总计约 {{ .Count }} 字"

[readingTime]
other = "预计阅读 {{ .Count }} 分钟"

Expand Down
6 changes: 3 additions & 3 deletions i18n/zh-TW.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ other = "文章"
[allSome]
other = "所有{{ .Some }}"

[totalwordCount]
other = "總計約 {{ .Count }} 字"

[tag]
other = "標籤"

Expand Down Expand Up @@ -154,9 +157,6 @@ other = "收錄於 {{ .Categories }}"
[wordCount]
other = "約 {{ .Count }} 字"

[totalwordCount]
other = "總計約 {{ .Count }} 字"

[readingTime]
other = "預計閱讀 {{ .Count }} 分鐘"

Expand Down
30 changes: 24 additions & 6 deletions layouts/_default/section.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,29 @@

{{- define "content" -}}
<div class="page archive">
{{- /* Title */ -}}
<h2 class="single-title animate__animated animate__pulse animate__faster">
{{- .Params.Title | default (T .Section) | default .Section | dict "Some" | T "allSome" }}
<sup>{{- len .Pages -}}</sup>
</h2>
<div class="header">
{{- /* Title */ -}}
<h1 class="single-title animate__animated animate__pulse animate__faster">
{{- .Params.Title | default (T .Section) | default .Section | dict "Some" | T "allSome" }}
<sup>{{- len .Pages -}}</sup>
</h1>
{{- /* 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 -}}
<p class="single-subtitle total-word-count" title='{{- T "totalwordCount" . }}'>
<i class="fa-regular fa-keyboard fa-fw"></i>
{{ T "totalwordCount" (dict "Count" $humanizedNum) -}}
</p>
{{- end -}}
</div>

{{- /* Paginate */ -}}
{{- if .Pages -}}
Expand All @@ -20,7 +38,7 @@ <h2 class="single-title animate__animated animate__pulse animate__faster">
{{- end -}}
{{- partial "recently-updated.html" . -}}
{{- range $pages.PageGroups -}}
<h3 class="group-title">{{ .Key }}</h3>
<h2 class="group-title">{{ .Key }}</h2>
{{- range .Pages -}}
<article class="archive-item">
<a href="{{ .RelPermalink }}" class="archive-item-link">
Expand Down
17 changes: 0 additions & 17 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,6 @@
{{- if .Site.Params.footer.siteTime -}}
<span class="site-time" title='{{ T "siteRunning" }}'><i class="fa-solid fa-heartbeat fa-fw animate-icon"></i>&nbsp;<span class="run-times">{{- T "siteRunning" -}}</span></span>
{{- 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 -}}
<span class="total-word-count footer-divider" title='{{- T "totalwordCount" . }}'><i class="fa-regular fa-keyboard fa-fw"></i>&nbsp;{{- T "totalwordCount" (dict "Count" $humanizedNum) -}}</span>
{{- end -}}
{{- end -}}
</div>
{{- end -}}

Expand Down

0 comments on commit e82a654

Please sign in to comment.