From dcfc7b55895146380eabb511b5aaf9835f1f5e36 Mon Sep 17 00:00:00 2001 From: Bachrul uluum <49960993+uluumbch@users.noreply.github.com> Date: Fri, 23 Jul 2021 23:37:30 +0700 Subject: [PATCH] feat(article): reading time (#204) * add reading time feature * Revert change in jsconfig.json * feat: add article.readingTime param, and improve style * Revert change in jsconfig.json x2 * Remove reading time in compact layout It doesn't look right to me for now * feat: add i18n support to reading time string * Hide footer.article-time when there's not content Co-authored-by: Jimmy Cai --- assets/icons/date.svg | 9 +++++++ assets/scss/partials/article.scss | 7 ++++++ exampleSite/config.yaml | 1 + i18n/en.yaml | 5 ++++ .../partials/article/components/details.html | 25 ++++++++++++++----- 5 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 assets/icons/date.svg diff --git a/assets/icons/date.svg b/assets/icons/date.svg new file mode 100644 index 0000000..ed92a90 --- /dev/null +++ b/assets/icons/date.svg @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/assets/scss/partials/article.scss b/assets/scss/partials/article.scss index c71cab4..459c22f 100644 --- a/assets/scss/partials/article.scss +++ b/assets/scss/partials/article.scss @@ -95,7 +95,9 @@ display: flex; align-items: center; color: var(--card-text-color-tertiary); + gap: 15px; margin-top: 10px; + flex-wrap: wrap; svg { vertical-align: middle; @@ -108,6 +110,11 @@ time { font-size: 1.4rem; } + + & > div { + display: inline-flex; + align-items: center; + } } .article-category, diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index de5d951..2ff6a1e 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -44,6 +44,7 @@ params: article: math: false toc: true + readingTime: true license: enabled: true default: Licensed under CC BY-NC-SA 4.0 diff --git a/i18n/en.yaml b/i18n/en.yaml index 21b1310..e279278 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -29,6 +29,11 @@ article: lastUpdatedOn: other: Last updated on + readingTime: + one: "{{ .Count }} min read" + ### Seems that there's no need to add 's' even if it's plural in English + other: "{{ .Count }} min read" + notFound: title: other: Not Found diff --git a/layouts/partials/article/components/details.html b/layouts/partials/article/components/details.html index 5c5397b..64d6c6e 100644 --- a/layouts/partials/article/components/details.html +++ b/layouts/partials/article/components/details.html @@ -21,12 +21,25 @@ {{ end }} - {{- if not .Date.IsZero -}} + {{ if or (not .Date.IsZero) (.Site.Params.article.readingTime) }} - {{- end -}} + {{ end }} \ No newline at end of file