From 65a7228bfc87815c5c49082e21101c68a42a593e Mon Sep 17 00:00:00 2001 From: wizardbyron <1400427+wizardbyron@users.noreply.github.com> Date: Thu, 16 Dec 2021 17:37:46 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20word=20count=20to=20page=20me?= =?UTF-8?q?ta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/_default/params.toml | 1 + i18n/en.yaml | 1 + i18n/zh.yaml | 1 + layouts/partials/article-meta.html | 4 ++++ layouts/partials/meta/word-count.html | 5 +++++ 5 files changed, 12 insertions(+) create mode 100644 layouts/partials/meta/word-count.html diff --git a/config/_default/params.toml b/config/_default/params.toml index 875dc423..4d693ddb 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -30,6 +30,7 @@ colorScheme = "congo" showPagination = true showReadingTime = true # sharingLinks = ["facebook", "twitter", "pinterest", "reddit", "linkedin", "email"] + showWordCount = true [list] showBreadcrumbs = false diff --git a/i18n/en.yaml b/i18n/en.yaml index 1c539b3b..d8de5fee 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -6,6 +6,7 @@ article: one: "{{ .Count }} min" other: "{{ .Count }} mins" reading_time_title: "Reading time" + word_count_unit: "Words" author: byline_title: "Author" diff --git a/i18n/zh.yaml b/i18n/zh.yaml index 175208a0..a539072d 100644 --- a/i18n/zh.yaml +++ b/i18n/zh.yaml @@ -5,6 +5,7 @@ article: reading_time: other: "{{ .Count }} 分钟" reading_time_title: "预计阅读" + word_count_unit: "字" author: byline_title: "作者" diff --git a/layouts/partials/article-meta.html b/layouts/partials/article-meta.html index e2118119..c0e2a8f3 100644 --- a/layouts/partials/article-meta.html +++ b/layouts/partials/article-meta.html @@ -16,6 +16,10 @@ {{ $meta.Add "partials" (slice (partial "meta/date.html" .)) }} {{ end }} + {{ if and (.Params.showWordCount | default (.Site.Params.article.showWordCount | default true)) (ne .WordCount 0) }} + {{ $meta.Add "partials" (slice (partial "meta/word-count.html" .)) }} + {{ end }} + {{ if and (.Params.showReadingTime | default (.Site.Params.article.showReadingTime | default true)) (ne .ReadingTime 0) }} {{ $meta.Add "partials" (slice (partial "meta/reading-time.html" .)) }} {{ end }} diff --git a/layouts/partials/meta/word-count.html b/layouts/partials/meta/word-count.html new file mode 100644 index 00000000..6907581d --- /dev/null +++ b/layouts/partials/meta/word-count.html @@ -0,0 +1,5 @@ + + {{ .WordCount }} {{- i18n "article.word_count_unit" -}} + +{{- /* Trim EOF */ -}} + \ No newline at end of file