From 2840c9ccd2acd3a8300008581b9c41c350b216e7 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Mon, 17 Apr 2023 04:17:42 +0800 Subject: [PATCH] perf(i18n): set the global default locales to "en" (#979) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - avoid missing labels caused by languages outside of locales - also improved the code style --- _includes/datetime.html | 28 +++-- _includes/footer.html | 46 ++++--- _includes/post-nav.html | 54 ++++---- _includes/post-sharing.html | 67 +++++----- _includes/read-time.html | 29 ++--- _includes/related-posts.html | 131 +++++++------------- _includes/search-loader.html | 23 ++-- _includes/sidebar.html | 4 + _includes/toc.html | 21 ++-- _includes/topbar.html | 75 ++++++----- _includes/trending-tags.html | 68 ++++------ _includes/update-list.html | 59 ++++----- _layouts/categories.html | 232 ++++++++++++++++------------------- _layouts/category.html | 11 +- _layouts/default.html | 59 +++++++++ _layouts/page.html | 18 +-- _layouts/post.html | 133 +++++++++----------- _layouts/tag.html | 11 +- assets/404.html | 6 + 19 files changed, 513 insertions(+), 562 deletions(-) diff --git a/_includes/datetime.html b/_includes/datetime.html index 9f954b698ef..87c03338b05 100644 --- a/_includes/datetime.html +++ b/_includes/datetime.html @@ -3,18 +3,30 @@ See: ${JS_ROOT}/utils/locale-dateime.js --> -{% assign df_strftime = site.data.locales[include.lang].df.post.strftime | default: '%d/%m/%Y' %} -{% assign df_dayjs = site.data.locales[include.lang].df.post.dayjs | default: 'DD/MM/YYYY' %} +{% assign df_strftime = site.data.locales[include.lang].df.post.strftime | +default: '%d/%m/%Y' %} {% assign df_dayjs = +site.data.locales[include.lang].df.post.dayjs | default: 'DD/MM/YYYY' %} {{ include.date | date: df_strftime }} diff --git a/_includes/footer.html b/_includes/footer.html index a015f469f1b..2340fbf1a90 100644 --- a/_includes/footer.html +++ b/_includes/footer.html @@ -2,41 +2,37 @@ diff --git a/_includes/post-nav.html b/_includes/post-nav.html index 736bec376b2..8b30c01a08f 100644 --- a/_includes/post-nav.html +++ b/_includes/post-nav.html @@ -1,34 +1,34 @@ - + {% assign previous = site.data.locales[include.lang].post.button.previous %} - {% assign next = site.data.locales[include.lang].post.button.next %} - - {% if page.previous.url %} - - {{ page.previous.title }} - + {% assign next = site.data.locales[include.lang].post.button.next %} {% if + page.previous.url %} + + {{ page.previous.title }} + {% else %} - - - - - {% endif %} - - {% if page.next.url %} - - {{ page.next.title }} - + + - + + {% endif %} {% if page.next.url %} + + {{ page.next.title }} + {% else %} - - - - + + - + {% endif %} diff --git a/_includes/post-sharing.html b/_includes/post-sharing.html index d8941994925..7f0ae260385 100644 --- a/_includes/post-sharing.html +++ b/_includes/post-sharing.html @@ -1,40 +1,45 @@ - {{ site.data.locales[include.lang].post.share }} + {{ site.data.locales[include.lang].post.share }} - {% capture title %}{{ page.title }} - {{ site.title }}{% endcapture %} - {% assign title = title | uri_escape %} - {% assign url = page.url | absolute_url | url_encode %} - - {% for share in site.data.share.platforms -%} - {%- capture tooltip -%} - data-bs-toggle="tooltip" data-bs-placement="top" title="{{ share.type }}" aria-label="{{ share.type }}" - {%- endcapture -%} - - {% if share.type == 'Mastodon' %} - - - - - - - - {% continue %} - {% endif %} + {% capture title %}{{ page.title }} - {{ site.title }}{% endcapture %} {% + assign title = title | uri_escape %} {% assign url = page.url | absolute_url + | url_encode %} {% for share in site.data.share.platforms -%} {%- capture + tooltip -%} data-bs-toggle="tooltip" data-bs-placement="top" title="{{ + share.type }}" aria-label="{{ share.type }}" {%- endcapture -%} {% if + share.type == 'Mastodon' %} + + + + + + - {% assign link = share.link | replace: 'TITLE', title | replace: 'URL', url %} + {% continue %} {% endif %} {% assign link = share.link | replace: 'TITLE', + title | replace: 'URL', url %} - - - + + + {% endfor %} -{% assign wpm = 180 %} -{% assign min_time = 1 %} - -{% assign read_time = words | divided_by: wpm %} - -{% unless read_time > 0 %} - {% assign read_time = min_time %} -{% endunless %} - -{% capture read_prompt %} - {{- site.data.locales[include.lang].post.read_time.prompt -}} -{% endcapture %} +{% assign wpm = 180 %} {% assign min_time = 1 %} {% assign read_time = words | +divided_by: wpm %} {% unless read_time > 0 %} {% assign read_time = min_time %} +{% endunless %} {% capture read_prompt %} {{- +site.data.locales[include.lang].post.read_time.prompt -}} {% endcapture %} - {{- read_time -}} - {{ ' ' }} - {{- site.data.locales[include.lang].post.read_time.unit -}} + {{- read_time -}} {{ ' ' }} {{- + site.data.locales[include.lang].post.read_time.unit -}} - {%- if include.prompt -%} - {%- assign _prompt_words = read_prompt | number_of_words: 'auto' -%} - {%- unless _prompt_words > 1 -%}{{ ' ' }}{%- endunless -%} - {{ read_prompt }} - {%- endif -%} + {%- if include.prompt -%} {%- assign _prompt_words = read_prompt | + number_of_words: 'auto' -%} {%- unless _prompt_words > 1 -%}{{ ' ' }}{%- + endunless -%} {{ read_prompt }} {%- endif -%} diff --git a/_includes/related-posts.html b/_includes/related-posts.html index 1ba2f322008..390a32e73dc 100644 --- a/_includes/related-posts.html +++ b/_includes/related-posts.html @@ -7,90 +7,49 @@ {% assign TAG_SCORE = 1 %} -{% assign CATEGORY_SCORE = 0.5 %} - -{% assign SEPARATOR = ':' %} - -{% assign match_posts = '' | split: '' %} - -{% for category in page.categories %} - {% assign match_posts = match_posts | push: site.categories[category] | uniq %} -{% endfor %} - -{% for tag in page.tags %} - {% assign match_posts = match_posts | push: site.tags[tag] | uniq %} -{% endfor %} - -{% assign last_index = match_posts.size | minus: 1 %} -{% assign score_list = '' | split: '' %} - -{% for i in (0..last_index) %} - {% assign post = match_posts[i] %} - - {% if post.url == page.url %} - {% continue %} - {% endif %} - - {% assign score = 0 %} - - {% for tag in post.tags %} - {% if page.tags contains tag %} - {% assign score = score | plus: TAG_SCORE %} - {% endif %} - {% endfor %} - - {% for category in post.categories %} - {% if page.categories contains category %} - {% assign score = score | plus: CATEGORY_SCORE %} - {% endif %} - {% endfor %} - - {% if score > 0 %} - {% capture score_item %}{{ score }}{{ SEPARATOR }}{{ i }}{% endcapture %} - {% assign score_list = score_list | push: score_item %} - {% endif %} -{% endfor %} - -{% assign index_list = '' | split: '' %} - -{% if score_list.size > 0 %} - {% assign score_list = score_list | sort | reverse %} - {% for entry in score_list limit: TOTAL_SIZE %} - {% assign index = entry | split: SEPARATOR | last %} - {% assign index_list = index_list | push: index %} - {% endfor %} -{% endif %} - -{% assign relate_posts = '' | split: '' %} - -{% for index in index_list %} - {% assign i = index | to_integer %} - {% assign relate_posts = relate_posts | push: match_posts[i] %} -{% endfor %} - -{% if relate_posts.size > 0 %} - - +{% assign CATEGORY_SCORE = 0.5 %} {% assign SEPARATOR = ':' %} {% assign +match_posts = '' | split: '' %} {% for category in page.categories %} {% assign +match_posts = match_posts | push: site.categories[category] | uniq %} {% endfor +%} {% for tag in page.tags %} {% assign match_posts = match_posts | push: +site.tags[tag] | uniq %} {% endfor %} {% assign last_index = match_posts.size | +minus: 1 %} {% assign score_list = '' | split: '' %} {% for i in (0..last_index) +%} {% assign post = match_posts[i] %} {% if post.url == page.url %} {% continue +%} {% endif %} {% assign score = 0 %} {% for tag in post.tags %} {% if page.tags +contains tag %} {% assign score = score | plus: TAG_SCORE %} {% endif %} {% +endfor %} {% for category in post.categories %} {% if page.categories contains +category %} {% assign score = score | plus: CATEGORY_SCORE %} {% endif %} {% +endfor %} {% if score > 0 %} {% capture score_item %}{{ score }}{{ SEPARATOR +}}{{ i }}{% endcapture %} {% assign score_list = score_list | push: score_item +%} {% endif %} {% endfor %} {% assign index_list = '' | split: '' %} {% if +score_list.size > 0 %} {% assign score_list = score_list | sort | reverse %} {% +for entry in score_list limit: TOTAL_SIZE %} {% assign index = entry | split: +SEPARATOR | last %} {% assign index_list = index_list | push: index %} {% endfor +%} {% endif %} {% assign relate_posts = '' | split: '' %} {% for index in +index_list %} {% assign i = index | to_integer %} {% assign relate_posts = +relate_posts | push: match_posts[i] %} {% endfor %} {% if relate_posts.size > 0 +%} + + {% endif %} diff --git a/_includes/search-loader.html b/_includes/search-loader.html index be3ca8a69f5..783b93e0c2a 100644 --- a/_includes/search-loader.html +++ b/_includes/search-loader.html @@ -4,20 +4,19 @@ --> {% capture result_elem %} - - - {title} - - {categories} - {tags} - - - {snippet} - + + + {title} + + {categories} {tags} + + + {snippet} + +{% endcapture %} {% capture not_found %} +{{ site.data.locales[include.lang].search.no_results }} {% endcapture %} -{% capture not_found %}{{ site.data.locales[include.lang].search.no_results }}{% endcapture %} -
{{ page.previous.title }}
-
{{ page.next.title }}
{snippet}
{{ site.data.locales[include.lang].search.no_results }}