Skip to content

Commit

Permalink
✨ Feat: add total word count support in footer (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Apr 28, 2022
1 parent 66847cf commit 96d0fcc
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
- :sparkles: Feat: link shortcode add `external-icon` option ([#96](https://github.com/Lruihao/FixIt/issues/96))
- :sparkles: Feat: add GitHub Corners support ([#106](https://github.com/Lruihao/FixIt/issues/106))
- :sparkles: Feat: add local avatar and gravatar support for post author ([#125](https://github.com/Lruihao/FixIt/issues/125))
- :sparkles: Feat: add total word count support in footer ([#124](https://github.com/Lruihao/FixIt/issues/124))
- :sparkles: Feat: add "Edit this page" button support ([#103](https://github.com/Lruihao/FixIt/issues/103))
- :sparkles: Feat: add count badge for taxonomy ([#122](https://github.com/Lruihao/FixIt/issues/122))
- :zap: Perf: add Gravatar config support
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/theme.min.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,15 @@ enableEmoji = true
# whether to show the author
# 是否显示作者
author = true
# site creation time
# site creation year
# 网站创立年份
since = 2021
# Site creation time since v0.2.14
# 网站创立时间 since v0.2.14
siteTime = '2021-12-18T16:15:22+08:00'
# whether to show total word count of site content since v0.2.14
# 是否显示网站内容总字数 since v0.2.14
wordCount = true
# Public network security only in China (HTML format is supported) since v0.2.12
# 公网安备信息,仅在中国使用 (支持 HTML 格式) since v0.2.12
gov = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,12 @@ Please open the code block below to view the complete sample configuration :(far
copyright = true
# {{< version 0.2.0 >}} whether to show the author
author = true
# Site creation time
# Site creation year
since = 2019
# {{< version 0.2.14 >}} Site creation time
siteTime = '' # e.g. '2019-02-03T19:30:34+08:00'
# {{< version 0.2.14 >}} whether to show total word count of site content
wordCount = true
# ICP info only in China (HTML format is supported)
icp = ""
# license info (HTML format is supported)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ hugo
since = 2019
# {{< version 0.2.14 >}} 网站创立时间
siteTime = '' # 例:'2019-02-03T19:30:34+08:00'
# {{< version 0.2.14 >}} 是否显示网站内容总字数
wordCount = true
# {{< version 0.2.12 >}} 公网安备信息,仅在中国使用(支持 HTML 格式)
gov = ""
# {{< version 0.2.12 changed >}} ICP 备案信息,仅在中国使用(支持 HTML 格式)
Expand Down
4 changes: 4 additions & 0 deletions i18n/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ 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
4 changes: 4 additions & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ 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
4 changes: 4 additions & 0 deletions i18n/es.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ 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
4 changes: 4 additions & 0 deletions i18n/fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ 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
4 changes: 4 additions & 0 deletions i18n/it.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ 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
4 changes: 4 additions & 0 deletions i18n/pl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ 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
4 changes: 4 additions & 0 deletions i18n/pt-BR.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ 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
4 changes: 4 additions & 0 deletions i18n/ro.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ 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
4 changes: 4 additions & 0 deletions i18n/ru.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ other = "включен в {{ .Categories }}"
one = "Одно слово"
other = "{{ .Count }} слов"

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

[readingTime]
one = "Одна минута"
other = "{{ .Count }} минут"
Expand Down
4 changes: 4 additions & 0 deletions i18n/sr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ other = "укључено {{ .Categories }}"
one = "Једна реч"
other = "{{ .Count }} речи"

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

[readingTime]
one = "Један минут"
other = "{{ .Count }} минута"
Expand Down
4 changes: 4 additions & 0 deletions i18n/vi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ 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
3 changes: 3 additions & 0 deletions i18n/zh-CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ other = "收录于 {{ .Categories }}"
[wordCount]
other = "约 {{ .Count }} 字"

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

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

Expand Down
3 changes: 3 additions & 0 deletions i18n/zh-TW.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ other = "收錄於 {{ .Categories }}"
[wordCount]
other = "約 {{ .Count }} 字"

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

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

Expand Down
42 changes: 25 additions & 17 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,37 @@

{{- /* License */ -}}
{{- with .Site.Params.footer.license -}}
{{- if $.Site.Params.footer.copyright | or $.Site.Params.footer.author -}}
<span class="footer-divider"></span>
{{- end -}}
<span class="license">{{ . | safeHTML }}</span>
<span class="license footer-divider">{{ . | safeHTML }}</span>
{{- end -}}
</div>
{{- end -}}

<div class="footer-line statistics">
{{- /* TODO: The parameter `ibruce.siteTime` will be deleted in v0.2.15 */ -}}
{{- if .Site.Params.ibruce.siteTime | or .Site.Params.footer.siteTime -}}
<span class="site-time" title={{ T "siteRunning" }}><i class="fas fa-heartbeat fa-fw animate-icon"></i>&nbsp;<span class="run-times">Loading ...</span></span>
{{- end -}}
</div>
{{- /* TODO: The parameter `ibruce.siteTime` will be deleted in v0.2.15 */ -}}
{{- if .Site.Params.ibruce.siteTime | or .Site.Params.footer.siteTime | or .Site.Params.footer.wordCount -}}
<div class="footer-line statistics">
{{- if .Site.Params.ibruce.siteTime | or .Site.Params.footer.siteTime -}}
<span class="site-time" title='{{ T "siteRunning" }}'><i class="fas fa-heartbeat fa-fw animate-icon"></i>&nbsp;<span class="run-times">{{- T "siteRunning" -}}</span></span>
{{- end -}}

{{- /* Total word count */ -}}
{{- if ne .Site.Params.footer.wordCount false -}}
{{- $localData := newScratch -}}
{{- range (where .Site.Pages "Kind" "page") -}}
{{- $localData.Add "totalWordCount" .WordCount -}}
{{- end -}}
{{- with ($localData.Get "totalWordCount") -}}
<span class="total-word-count footer-divider"><i class="far fa-keyboard fa-fw"></i>&nbsp;{{- T "totalwordCount" . -}}</span>
{{- end -}}
{{- end -}}
</div>
{{- end -}}

{{- /* 不蒜子 */ -}}
{{- if eq .Site.Params.ibruce.enable true -}}
<div class="footer-line ibruce">
<span id="busuanzi_container_site_uv" title={{ T "siteUV" }}><i class="far fa-user fa-fw"></i><span id="busuanzi_value_site_uv"><i class="fa fa-spinner fa-spin fa-fw"></i></span></span>
<span id="busuanzi_container_site_pv" class="footer-divider" title={{ T "sitePV" }}><i class="far fa-eye fa-fw"></i>&nbsp;<span id="busuanzi_value_site_pv"><i class="fa fa-spinner fa-spin fa-fw"></i></span></span>
<span id="busuanzi_container_site_uv" title='{{ T "siteUV" }}'><i class="far fa-user fa-fw"></i>&nbsp;<span id="busuanzi_value_site_uv"><i class="fa fa-spinner fa-spin fa-fw"></i></span></span>
{{- /* remove spaces */ -}}
<span id="busuanzi_container_site_pv" class="footer-divider" title='{{ T "sitePV" }}'><i class="far fa-eye fa-fw"></i>&nbsp;<span id="busuanzi_value_site_pv"><i class="fa fa-spinner fa-spin fa-fw"></i></span></span>
</div>
{{- end -}}

Expand All @@ -69,13 +80,10 @@
{{- with .Site.Params.footer.gov -}}
<span class="gov">{{ . | safeHTML }}</span>
{{- end -}}

{{- /* ICP */ -}}
{{- with .Site.Params.footer.icp -}}
{{- if $.Site.Params.footer.gov -}}
<span class="footer-divider"></span>
{{- end -}}
<span class="icp">{{ . | safeHTML }}</span>
<span class="icp footer-divider">{{ . | safeHTML }}</span>
{{- end -}}
</div>
{{- end -}}
Expand Down
8 changes: 4 additions & 4 deletions src/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,18 +802,18 @@ class Theme {
getSiteTime = () => {
let now = new Date();
let run = new Date(this.config.siteTime);
let $siteTime = document.querySelector('.site-time');
if (!this.util.isValidDate(run) || !$siteTime) {
let $runTimes = document.querySelector('.run-times');
if (!this.util.isValidDate(run) || !$runTimes) {
clearInterval(this.siteTime);
$siteTime && $siteTime.remove();
$runTimes && $runTimes.parentNode.remove();
return;
}
let runTime = (now - run) / 1000,
days = Math.floor(runTime / 60 / 60 / 24),
hours = Math.floor(runTime / 60 / 60 - 24 * days),
minutes = Math.floor(runTime / 60 - 24 * 60 * days - 60 * hours),
seconds = Math.floor((now - run) / 1000 - 24 * 60 * 60 * days - 60 * 60 * hours - 60 * minutes);
$siteTime.querySelector('.run-times').innerHTML = `${days}, ${String(hours).padStart(2, 0)}:${String(minutes).padStart(2, 0)}:${String(seconds).padStart(2, 0)}`;
$runTimes.innerHTML = `${days}, ${String(hours).padStart(2, 0)}:${String(minutes).padStart(2, 0)}:${String(seconds).padStart(2, 0)}`;
}

initSiteTime() {
Expand Down

1 comment on commit 96d0fcc

@vercel
Copy link

@vercel vercel bot commented on 96d0fcc Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.