From 0b29c0321f669c992dfa18646157b0213026bc52 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Wed, 21 Jul 2021 01:01:09 +0800 Subject: [PATCH] Add layout localization --- _config.yml | 20 ++++++-- _data/date_format.yml | 7 --- _data/label.yml | 19 -------- _data/locales/en.yml | 87 ++++++++++++++++++++++++++++++++++ _data/locales/zh-CN.yml | 86 +++++++++++++++++++++++++++++++++ _data/rights.yml | 11 ----- _includes/footer.html | 25 ++++++---- _includes/head.html | 7 +++ _includes/no-zero-date.html | 13 +++++ _includes/panel.html | 6 +-- _includes/post-nav.html | 8 ++-- _includes/post-sharing.html | 8 ++-- _includes/read-time.html | 14 +++++- _includes/related-posts.html | 2 +- _includes/search-results.html | 2 +- _includes/sidebar.html | 15 +++--- _includes/timeago.html | 23 ++++----- _includes/topbar.html | 46 ++++++++++-------- _javascript/utils/copy-link.js | 8 +++- _javascript/utils/timeago.js | 41 +++++++--------- _layouts/archives.html | 7 +-- _layouts/categories.html | 33 ++++++------- _layouts/category.html | 4 +- _layouts/default.html | 2 +- _layouts/home.html | 7 ++- _layouts/page.html | 9 +++- _layouts/post.html | 30 ++++++++---- _layouts/tag.html | 5 +- _sass/addon/commons.scss | 2 +- _sass/layout/post.scss | 12 ----- assets/404.html | 20 ++++++-- assets/feed.xml | 2 +- assets/js/dist/home.min.js | 2 +- assets/js/dist/page.min.js | 2 +- assets/js/dist/post.min.js | 2 +- 35 files changed, 394 insertions(+), 193 deletions(-) delete mode 100644 _data/date_format.yml delete mode 100644 _data/label.yml create mode 100644 _data/locales/en.yml create mode 100644 _data/locales/zh-CN.yml delete mode 100644 _data/rights.yml create mode 100644 _includes/no-zero-date.html diff --git a/_config.yml b/_config.yml index 6608f19..6354c7a 100644 --- a/_config.yml +++ b/_config.yml @@ -7,14 +7,21 @@ theme: jekyll-theme-chirpy # change below value to '/projectname'. baseurl: '' -# the HTML language tag › https://www.w3.org/International/questions/qa-choosing-language-tags -lang: en-US +# The language of the site layout › http://www.lingoes.net/en/translator/langcode.htm +# Go to folder '_data/locales' to check the available language options +lang: en + +# The lang attribute of HTML › http://www.lingoes.net/en/translator/langcode.htm +# We can specify a language different from the layout of the content. +# If it is not assigned, the site will use the value of 'lang' instead. +content_lang: '' # Change to your timezone › http://www.timezoneconverter.com/cgi-bin/findzone/findzone timezone: Asia/Shanghai # jekyll-seo-tag settings › https://github.com/jekyll/jekyll-seo-tag/blob/master/docs/usage.md -# -------------------------- +# ↓ -------------------------- + title: Chirpy # the main title tagline: A text-focused Jekyll theme # it will display as the sub-title @@ -47,7 +54,9 @@ social: # - https://www.linkedin.com/in/username google_site_verification: google_meta_tag_verification # change to your verification string -# -------------------------- + +# ↑ -------------------------- + google_analytics: id: '' # fill in your Google Analytics ID @@ -164,3 +173,6 @@ jekyll-archives: permalinks: tag: /tags/:name/ category: /categories/:name/ + +# Outdated configuration warning +outdated: '-- Missing configuration options! --' diff --git a/_data/date_format.yml b/_data/date_format.yml deleted file mode 100644 index 3c7bc79..0000000 --- a/_data/date_format.yml +++ /dev/null @@ -1,7 +0,0 @@ -# The date format - -tooltip: "%a, %b %e, %Y, %l:%M %p %z" - -post: - long: "%b %e, %Y" - short: "%b %e" diff --git a/_data/label.yml b/_data/label.yml deleted file mode 100644 index 11cccf4..0000000 --- a/_data/label.yml +++ /dev/null @@ -1,19 +0,0 @@ -# The label text of site. - -panel: - lastmod: Recent Update - trending_tags: Trending Tags - toc: Contents - -post: - relate_posts: Further Reading - share: Share - button: - next: Newer - previous: Older - -search_hint: Search # text show on search bar - -pin_prompt: Pinned # pinned prompt - -read_time_unit: min # see posts' time to read diff --git a/_data/locales/en.yml b/_data/locales/en.yml new file mode 100644 index 0000000..d20e2f6 --- /dev/null +++ b/_data/locales/en.yml @@ -0,0 +1,87 @@ +# The layout text of site + +# ----- Commons label ----- + +layout: + post: Post + category: Category + tag: Tag + +# The tabs of sidebar +tabs: + # format: : + home: Home + categories: Categories + tags: Tags + archives: Archives + about: About + +# text displayed in the search bar +search: + hint: search + cancel: Cancel + +panel: + lastmod: Recent Update + trending_tags: Trending Tags + toc: Contents + +# The liquid date format › http://strftime.net/ +date_format: + tooltip: '%a, %b %e, %Y, %l:%M %p %z' + post: + long: '%b %e, %Y' + short: '%b %e' + archive_month: '%b' + +copyright: + # Shown at the bottom of the post + license: + template: This post is licensed under :LICENSE_NAME by the author. + name: CC BY 4.0 + link: https://creativecommons.org/licenses/by/4.0/ + + # Displayed in the footer + brief: Some rights reserved. + verbose: >- + Except where otherwise noted, the blog posts on this site are licensed + under the Creative Commons Attribution 4.0 International (CC BY 4.0) License by the author. + +meta: Powered by :PLATFORM with :THEME theme. + +not_found: + statment: Sorry, we've misplaced that URL or it's pointing to something that doesn't exist. + hint_template: :HEAD_BAK to try finding it again, or search for it on the :ARCHIVES_PAGE. + head_back: Head back Home + archives_page: Archives page + +# ----- Posts related labels ----- + +post: + published: 'on' + updated: Updated + timeago: + day: d ago + hour: hr ago + minute: min ago + just_now: just now + words: words + pageview_measure: views + read_time: + unit: min + prompt: read + relate_posts: Further Reading + share: Share + button: + next: Newer + previous: Older + copy: + title: Copy link + succeed: Link copied successfully! + # pinned prompt of posts list on homepage + pin_prompt: Pinned + +# categories page +categories: + category_measure: categories + post_measure: posts diff --git a/_data/locales/zh-CN.yml b/_data/locales/zh-CN.yml new file mode 100644 index 0000000..0f896d6 --- /dev/null +++ b/_data/locales/zh-CN.yml @@ -0,0 +1,86 @@ +# The layout text of site + +# ----- Commons label ----- + +layout: + post: 文章 + category: 分类 + tag: 标签 + +# The tabs of sidebar +tabs: + # format: : + home: 首页 + categories: 分类 + tags: 标签 + archives: 归档 + about: 关于 + +# text displayed in the search bar +search: + hint: 搜索 + cancel: 取消 + +panel: + lastmod: 最近更新 + trending_tags: 热门标签 + toc: 目录 + +# The liquid date format › http://strftime.net/ +date_format: + tooltip: '%a, %F, %R %z' + post: + long: '%F' + short: '%m-%d' + archive_month: '%m月' + +copyright: + # Shown at the bottom of the post + license: + template: 本文由作者按照 :LICENSE_NAME 进行授权 + name: CC BY 4.0 + link: https://creativecommons.org/licenses/by/4.0/ + + # Displayed in the footer + brief: 保留部分权利。 + verbose: >- + 除非另有说明,本网站上的博客文章均由作者按照知识共享署名 4.0 国际 (CC BY 4.0) 许可协议进行授权。 + +meta: 本站由 :PLATFORM 生成,采用 :THEME 主题。 + +not_found: + statment: 抱歉,我们放错了该 URL,或者它指向了不存在的内容。 + hint_template: :HEAD_BAK尝试再次查找它,或在:ARCHIVES_PAGE上搜索它。 + head_back: 返回主页 + archives_page: 归档页面 + +# ----- Posts related labels ----- + +post: + published: 发表于 + updated: 更新于 + timeago: + day: 天前 + hour: 小时前 + minute: 分钟前 + just_now: 刚刚 + words: 字 + pageview_measure: 次浏览 + read_time: + unit: 分钟 + prompt: 阅读 + relate_posts: 相关文章 + share: 分享 + button: + next: 下一篇 + previous: 上一篇 + copy: + title: 分享链接 + succeed: 链接已复制! + # pinned prompt of posts list on homepage + pin_prompt: 顶置 + +# categories page +categories: + category_measure: 个分类 + post_measure: 篇文章 diff --git a/_data/rights.yml b/_data/rights.yml deleted file mode 100644 index f6fdd42..0000000 --- a/_data/rights.yml +++ /dev/null @@ -1,11 +0,0 @@ -# License data - -license: - name: CC BY 4.0 - link: "https://creativecommons.org/licenses/by/4.0/" - -brief: Some rights reserved. - -verbose: >- - Except where otherwise noted, the blog posts on this site are licensed - under the Creative Commons Attribution 4.0 International (CC BY 4.0) License by the author. diff --git a/_includes/footer.html b/_includes/footer.html index 566d273..aa5ff90 100644 --- a/_includes/footer.html +++ b/_includes/footer.html @@ -8,21 +8,30 @@

© {{ 'now' | date: "%Y" }} {{ site.social.name }}. - {% if site.data.rights.brief %} + {% if site.data.locales[site.lang].copyright.brief %} {{ site.data.rights.brief }} + title="{{ site.data.locales[site.lang].copyright.verbose }}">{{ site.data.locales[site.lang].copyright.brief }} + {% else %} + {{ site.outdated }} {% endif %}

diff --git a/_includes/head.html b/_includes/head.html index 62d3e29..46c017d 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -8,6 +8,13 @@ {% if page.layout == 'home' or page.layout == 'post' %} + + + + + + + {% if site.google_analytics.pv.proxy_endpoint %} {% endif %} diff --git a/_includes/no-zero-date.html b/_includes/no-zero-date.html new file mode 100644 index 0000000..5c98b73 --- /dev/null +++ b/_includes/no-zero-date.html @@ -0,0 +1,13 @@ +{% comment %} + Remove the zero padding from a month/day string +{% endcomment %} + +{% assign ret = include.date_str %} +{% assign _first_chat = ret | slice: 0 %} + +{% if _first_chat == '0' %} + {% assign _last_idx = ret.size | minus: 1 %} + {% assign ret = ret | slice: 1, _last_idx %} +{% endif %} + +{{ ret | replace: ' 0', ' ' }} diff --git a/_includes/panel.html b/_includes/panel.html index 3b9fb75..bfa881b 100644 --- a/_includes/panel.html +++ b/_includes/panel.html @@ -11,7 +11,7 @@ {% if update_list.size > 0 %}
- {{- site.data.label.panel.lastmod | default: 'Recent Update' -}} + {{- site.data.locales[site.lang].panel.lastmod | default: 'Recent Update' -}}
    {% for item in update_list %} @@ -30,7 +30,7 @@ {% if trending_tags.size > 0 %}
    - {{- site.data.label.panel.trending_tags | default: 'Trending Tags' -}} + {{- site.data.locales[site.lang].panel.trending_tags | default: 'Trending Tags' -}}
    {% for tag_name in trending_tags %} @@ -48,7 +48,7 @@
    - {{- site.data.label.panel.toc | default: 'Contents' -}} + {{- site.data.locales[site.lang].panel.toc | default: 'Contents' -}}
    diff --git a/_includes/post-nav.html b/_includes/post-nav.html index c8a6f2e..c9c258c 100644 --- a/_includes/post-nav.html +++ b/_includes/post-nav.html @@ -5,24 +5,24 @@
    {% if page.previous.url %} + prompt="{{ site.data.locales[site.lang].post.button.previous | default: 'previous' }}">

    {{ page.previous.title }}

    {% else %} + prompt="{{ site.data.locales[site.lang].post.button.previous | default: 'previous' }}">

    -

    {% endif %} {% if page.next.url %} + prompt="{{ site.data.locales[site.lang].post.button.next | default: 'next' }}">

    {{ page.next.title }}

    {% else %} + prompt="{{ site.data.locales[site.lang].post.button.next | default: 'next' }}">

    -

    {% endif %} diff --git a/_includes/post-sharing.html b/_includes/post-sharing.html index c95a307..252370f 100644 --- a/_includes/post-sharing.html +++ b/_includes/post-sharing.html @@ -3,7 +3,7 @@ --> diff --git a/_includes/read-time.html b/_includes/read-time.html index f63bc3b..460c65a 100644 --- a/_includes/read-time.html +++ b/_includes/read-time.html @@ -1,9 +1,11 @@ + {% assign words = include.content | strip_html | number_of_words: "auto" %} + {% assign wpm = 180 %} {% assign min_time = 1 %} @@ -13,7 +15,15 @@ {% assign read_time = min_time %} {% endunless %} +{% capture read_prompt %} + {{- site.data.locales[site.lang].post.read_time.prompt | default: "read" -}} +{% endcapture %} + - - {{- read_time -}}{{" "}}{{- site.data.label.read_time_unit | default: "min" -}} + + {{- read_time -}}{{" "}}{{- site.data.locales[site.lang].post.read_time.unit | default: "min" -}} + {%- if include.prompt -%} + {% unless site.lang contains 'zh' %}{{" "}}{% endunless %}{{ read_prompt }} + {%- endif -%} diff --git a/_includes/related-posts.html b/_includes/related-posts.html index be63279..d4c3996 100644 --- a/_includes/related-posts.html +++ b/_includes/related-posts.html @@ -81,7 +81,7 @@ {% if index_list.size > 0 %}