From 61fdbcb83a3601ecae62ec230602b94a5eb832e1 Mon Sep 17 00:00:00 2001
From: Cotes Chung <11371340+cotes2020@users.noreply.github.com>
Date: Sat, 6 May 2023 07:22:29 +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.
---
_includes/datetime.html | 16 +--
_includes/footer.html | 20 ++--
_includes/lang.html | 8 ++
_includes/post-nav.html | 47 +++++----
_includes/post-sharing.html | 34 ++++---
_includes/read-time.html | 27 +++--
_includes/refactor-content.html | 2 +-
_includes/related-posts.html | 70 +++++++------
_includes/search-loader.html | 2 +-
_includes/sidebar.html | 70 ++++++-------
_includes/toc.html | 2 +-
_includes/topbar.html | 85 ++++++++--------
_includes/trending-tags.html | 24 ++---
_includes/update-list.html | 19 ++--
_layouts/archives.html | 6 +-
_layouts/categories.html | 174 ++++++++++++++++++--------------
_layouts/category.html | 12 ++-
_layouts/default.html | 37 ++++---
_layouts/home.html | 6 +-
_layouts/page.html | 56 +++++-----
_layouts/post.html | 26 ++---
_layouts/tag.html | 12 ++-
assets/404.html | 4 +-
23 files changed, 417 insertions(+), 342 deletions(-)
create mode 100644 _includes/lang.html
diff --git a/_includes/datetime.html b/_includes/datetime.html
index e659c5a..00aaea4 100644
--- a/_includes/datetime.html
+++ b/_includes/datetime.html
@@ -4,12 +4,16 @@
-->
{% assign wrap_elem = include.wrap | default: 'em' %}
-{% assign df_strftime = site.data.locales[site.lang].df.post.strftime | default: '%d/%m/%Y' %}
-{% assign df_dayjs = site.data.locales[site.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' %}
-<{{ wrap_elem }} class="{% if include.class %}{{ include.class }}{% endif %}"
- data-ts="{{ include.date | date: '%s' }}"
- data-df="{{ df_dayjs }}"
- {% if include.tooltip %}data-toggle="tooltip" data-placement="bottom"{% endif %}>
+<{{ wrap_elem }}
+ class="{% if include.class %}{{ include.class }}{% endif %}"
+ data-ts="{{ include.date | date: '%s' }}"
+ data-df="{{ df_dayjs }}"
+ {% if include.tooltip %}
+ data-toggle="tooltip" data-placement="bottom"
+ {% endif %}
+>
{{ include.date | date: df_strftime }}
{{ wrap_elem }}>
diff --git a/_includes/footer.html b/_includes/footer.html
index f4b16d9..b8f4ec7 100644
--- a/_includes/footer.html
+++ b/_includes/footer.html
@@ -5,18 +5,22 @@
diff --git a/_includes/lang.html b/_includes/lang.html
new file mode 100644
index 0000000..19558a0
--- /dev/null
+++ b/_includes/lang.html
@@ -0,0 +1,8 @@
+{% comment %}
+ Detect appearance language and return it through variable "lang"
+{% endcomment %}
+{% if site.data.locales[site.lang] %}
+ {% assign lang = site.lang %}
+{% else %}
+ {% assign lang = 'en' %}
+{% endif %}
diff --git a/_includes/post-nav.html b/_includes/post-nav.html
index 7a12e69..76bcd59 100644
--- a/_includes/post-nav.html
+++ b/_includes/post-nav.html
@@ -1,30 +1,37 @@
-
+
{% if page.previous.url %}
-
- {{ page.previous.title }}
-
+
+ {{ page.previous.title }}
+
{% else %}
-
+
{% endif %}
{% if page.next.url %}
-
- {{ page.next.title }}
-
+
+ {{ page.next.title }}
+
{% else %}
-
+
{% endif %}
-
diff --git a/_includes/post-sharing.html b/_includes/post-sharing.html
index c241ea5..8c4598e 100644
--- a/_includes/post-sharing.html
+++ b/_includes/post-sharing.html
@@ -1,9 +1,7 @@
-
+
-
{{ site.data.locales[site.lang].post.share }}
+
{{ site.data.locales[include.lang].post.share }}
{% capture title %}{{ page.title }} - {{ site.title }}{% endcapture %}
{% assign title = title | uri_escape %}
@@ -11,17 +9,27 @@
{% for share in site.data.share.platforms %}
{% assign link = share.link | replace: 'TITLE', title | replace: 'URL', url %}
-
-
-
+
+
+
{% endfor %}
-
+
-
diff --git a/_includes/read-time.html b/_includes/read-time.html
index 6363da3..6d53357 100644
--- a/_includes/read-time.html
+++ b/_includes/read-time.html
@@ -1,10 +1,8 @@
-
+
-{% assign words = include.content | strip_html | number_of_words: "auto" %}
+{% assign words = include.content | strip_html | number_of_words: 'auto' %}
-
+
{% assign wpm = 180 %}
{% assign min_time = 1 %}
@@ -16,15 +14,24 @@
{% endunless %}
{% capture read_prompt %}
- {{- site.data.locales[site.lang].post.read_time.prompt -}}
+ {{- site.data.locales[include.lang].post.read_time.prompt -}}
{% endcapture %}
-
- {{- read_time -}}{{" "}}{{- site.data.locales[site.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 }}
+ {%- unless _prompt_words > 1 -%}{{ ' ' }}{%- endunless -%}
+ {{ read_prompt }}
{%- endif -%}
diff --git a/_includes/refactor-content.html b/_includes/refactor-content.html
index 3a6f943..ea6f139 100644
--- a/_includes/refactor-content.html
+++ b/_includes/refactor-content.html
@@ -225,7 +225,7 @@
| append: ''
| append: ''
%}
diff --git a/_includes/related-posts.html b/_includes/related-posts.html
index b992c6e..69e9970 100644
--- a/_includes/related-posts.html
+++ b/_includes/related-posts.html
@@ -1,20 +1,20 @@
-
+
{% assign TOTAL_SIZE = 3 %}
-
+
{% assign TAG_SCORE = 1 %}
-
+
{% assign CATEGORY_SCORE = 0.5 %}
-{% assign SEPARATOR = ":" %}
+{% assign SEPARATOR = ':' %}
-{% assign score_list = "" | split: "" %}
+{% assign score_list = '' | split: '' %}
{% assign last_index = site.posts.size | minus: 1 %}
{% for i in (0..last_index) %}
@@ -42,11 +42,9 @@
{% capture score_item %}{{ score }}{{ SEPARATOR }}{{ i }}{% endcapture %}
{% assign score_list = score_list | push: score_item %}
{% endif %}
-
{% endfor %}
-
-{% assign index_list = "" | split: "" %}
+{% assign index_list = '' | split: '' %}
{% if score_list.size > 0 %}
{% assign score_list = score_list | sort | reverse %}
@@ -56,13 +54,13 @@
{% endfor %}
{% endif %}
-
+
{% assign less = TOTAL_SIZE | minus: index_list.size %}
{% if less > 0 %}
{% for i in (0..last_index) %}
{% assign post = site.posts[i] %}
- {% if post.url != page.url %}
+ {% if post.url != page.url %}
{% capture cur_index %}{{ i }}{% endcapture %}
{% unless index_list contains cur_index %}
{% assign index_list = index_list | push: cur_index %}
@@ -77,27 +75,33 @@
{% if index_list.size > 0 %}
-
{{ site.data.locales[site.lang].post.relate_posts }}
+
+ {{ site.data.locales[include.lang].post.relate_posts }}
+
+ {% endfor %}
+
+
+
+
{% endif %}
diff --git a/_includes/search-loader.html b/_includes/search-loader.html
index 603ea5b..b14d1e5 100644
--- a/_includes/search-loader.html
+++ b/_includes/search-loader.html
@@ -14,7 +14,7 @@
{% endcapture %}
-{% capture not_found %}{{ site.data.locales[site.lang].search.no_results }}
{% endcapture %}
+{% capture not_found %}{{ site.data.locales[include.lang].search.no_results }}
{% endcapture %}
diff --git a/_includes/sidebar.html b/_includes/sidebar.html
index c570597..5dd8fc2 100644
--- a/_includes/sidebar.html
+++ b/_includes/sidebar.html
@@ -1,6 +1,4 @@
-
+
+
+
+
+
-
-
+
+
+
+
diff --git a/_includes/toc.html b/_includes/toc.html
index 0d1967c..d47ea28 100644
--- a/_includes/toc.html
+++ b/_includes/toc.html
@@ -7,7 +7,7 @@
{% if enable_toc %}
-
{{- site.data.locales[site.lang].panel.toc -}}
+
{{- site.data.locales[include.lang].panel.toc -}}
diff --git a/_includes/topbar.html b/_includes/topbar.html
index 51fbf1a..91494db 100644
--- a/_includes/topbar.html
+++ b/_includes/topbar.html
@@ -1,70 +1,67 @@
-
+
diff --git a/_includes/trending-tags.html b/_includes/trending-tags.html
index d0f58a1..a36108c 100644
--- a/_includes/trending-tags.html
+++ b/_includes/trending-tags.html
@@ -4,26 +4,26 @@
{% assign MAX = 10 %}
-{% assign size_list = "" | split: "" %}
-{% assign tag_list = "" | split: "" %}
+{% assign size_list = '' | split: '' %}
+{% assign tag_list = '' | split: '' %}
{% for tag in site.tags %}
{% assign size = tag | last | size %}
{% assign size_list = size_list | push: size %}
- {% assign tag_str = tag | first | append: "::" | append: size %}
- {% assign tag_list = tag_list | push: tag_str %}
+ {% assign tag_str = tag | first | append: '::' | append: size %}
+ {% assign tag_list = tag_list | push: tag_str %}
{% endfor %}
{% assign size_list = size_list | sort | reverse %}
{% assign tag_list = tag_list | sort_natural %}
-{% assign trending_tags = "" | split: "" %}
+{% assign trending_tags = '' | split: '' %}
{% for size in size_list limit: MAX %}
{% for tag_str in tag_list %}
- {% assign tag = tag_str | split: "::" %}
+ {% assign tag = tag_str | split: '::' %}
{% assign tag_name = tag | first %}
{% assign tag_size = tag | last | plus: 0 %}
{% if tag_size == size %}
@@ -37,14 +37,12 @@
{% if trending_tags.size > 0 %}
{% endif %}
diff --git a/_includes/update-list.html b/_includes/update-list.html
index a4edd11..0ee7b70 100644
--- a/_includes/update-list.html
+++ b/_includes/update-list.html
@@ -4,7 +4,7 @@
{% assign MAX_SIZE = 5 %}
-{% assign all_list = "" | split: "" %}
+{% assign all_list = '' | split: '' %}
{% for post in site.posts %}
{% if post.last_modified_at %}
@@ -17,24 +17,25 @@
{% assign all_list = all_list | sort | reverse %}
-{% assign update_list = "" | split: "" %}
+{% assign update_list = '' | split: '' %}
-{% for entry in all_list limit:MAX_SIZE %}
+{% for entry in all_list limit: MAX_SIZE %}
{% assign update_list = update_list | push: entry %}
{% endfor %}
{% if update_list.size > 0 %}
-
-
{{- site.data.locales[site.lang].panel.lastmod -}}
+
{{- site.data.locales[include.lang].panel.lastmod -}}
{% for item in update_list %}
- {% assign index = item | split: "::" | last | plus: 0 %}
+ {% assign index = item | split: '::' | last | plus: 0 %}
{% assign post = site.posts[index] %}
{% assign url = post.url | relative_url %}
- - {{ post.title }}
+ -
+ {{ post.title }}
+
{% endfor %}
-
-
+
+
{% endif %}
diff --git a/_layouts/archives.html b/_layouts/archives.html
index f86b417..fd482e5 100644
--- a/_layouts/archives.html
+++ b/_layouts/archives.html
@@ -3,8 +3,10 @@ layout: page
# The Archives of posts.
---
-{% assign df_strftime_m = site.data.locales[site.lang].df.archives.strftime | default: '/ %m' %}
-{% assign df_dayjs_m = site.data.locales[site.lang].df.archives.dayjs | default: '/ MM' %}
+{% include lang.html %}
+
+{% assign df_strftime_m = site.data.locales[lang].df.archives.strftime | default: '/ %m' %}
+{% assign df_dayjs_m = site.data.locales[lang].df.archives.dayjs | default: '/ MM' %}
diff --git a/_layouts/categories.html b/_layouts/categories.html
index b207186..a08e4c5 100644
--- a/_layouts/categories.html
+++ b/_layouts/categories.html
@@ -3,8 +3,10 @@ layout: page
# All the Categories of posts
---
-{% assign HEAD_PREFIX = "h_" %}
-{% assign LIST_PREFIX = "l_" %}
+{% include lang.html %}
+
+{% assign HEAD_PREFIX = 'h_' %}
+{% assign LIST_PREFIX = 'l_' %}
{% assign group_index = 0 %}
@@ -16,7 +18,7 @@ layout: page
{% assign first_post = posts_of_category | first %}
{% if category_name == first_post.categories[0] %}
- {% assign sub_categories = "" | split: "" %}
+ {% assign sub_categories = '' | split: '' %}
{% for post in posts_of_category %}
{% assign second_category = post.categories[1] %}
@@ -30,89 +32,107 @@ layout: page
{% assign sub_categories = sub_categories | sort %}
{% assign sub_categories_size = sub_categories | size %}
-
-
-
+
+
+
+ {% if sub_categories_size > 0 %}
+
+
+ {% for sub_category in sub_categories %}
+ -
+
+
+ {% capture _sub_ctg_url %}/categories/{{ sub_category | slugify | url_encode }}/{% endcapture %}
+ {{ sub_category }}
+
+ {% assign posts_size = site.categories[sub_category] | size %}
+
+ {{ posts_size }}
+
+ {% if posts_size > 1 %}
+ {{
+ site.data.locales[lang].categories.post_measure.plural
+ | default: site.data.locales[lang].categories.post_measure
+ }}
+ {% else %}
+ {{
+ site.data.locales[lang].categories.post_measure.singular
+ | default: site.data.locales[lang].categories.post_measure
+ }}
+ {% endif %}
+
+
+ {% endfor %}
+
+
+ {% endif %}
+
+
{% assign group_index = group_index | plus: 1 %}
-
{% endif %}
{% endfor %}
diff --git a/_layouts/category.html b/_layouts/category.html
index 07129bb..b926637 100644
--- a/_layouts/category.html
+++ b/_layouts/category.html
@@ -3,6 +3,8 @@ layout: page
# The Category layout
---
+{% include lang.html %}
+
@@ -12,11 +14,11 @@ layout: page
{% for post in page.posts %}
- -
- {{ post.title }}
-
- {% include datetime.html date=post.date wrap='span' class='text-muted small' %}
-
+ -
+ {{ post.title }}
+
+ {% include datetime.html date=post.date wrap='span' class='text-muted small' lang=lang %}
+
{% endfor %}
diff --git a/_layouts/default.html b/_layouts/default.html
index a98c230..3705831 100644
--- a/_layouts/default.html
+++ b/_layouts/default.html
@@ -3,10 +3,12 @@ layout: compress
# Default layout
---
-
+
{% include assets-origin.html %}
+{% include lang.html %}
+
{% capture prefer_mode %}
{% if site.theme_mode %}
data-mode="{{ site.theme_mode }}"
@@ -14,26 +16,24 @@ layout: compress
{% endcapture %}
-
-
+
{% include head.html %}
+ {% include sidebar.html lang=lang %}
- {% include sidebar.html %}
-
- {% include topbar.html %}
+ {% include topbar.html lang=lang %}
{{ content }}
- {% include search-results.html %}
+ {% include search-results.html lang=lang %}
+
+
-
-
- {% include footer.html %}
+ {% include footer.html lang=lang %}
{% if page.mermaid %}
{% include mermaid.html %}
@@ -46,17 +46,24 @@ layout: compress
{% if site.pwa.enabled %}
-
+
-
{{ site.data.locales[site.lang].notification.update_found }}
+
{{ site.data.locales[lang].notification.update_found }}
@@ -65,7 +72,5 @@ layout: compress
{% include search-loader.html %}
{% include js-selector.html %}
-
-
diff --git a/_layouts/home.html b/_layouts/home.html
index 42b9fe2..afc4af6 100644
--- a/_layouts/home.html
+++ b/_layouts/home.html
@@ -3,6 +3,8 @@ layout: page
# The Home page layout
---
+{% include lang.html %}
+
{% assign pinned = site.posts | where: 'pin', 'true' %}
{% assign default = site.posts | where_exp: 'item', 'item.pin != true and item.hidden != true' %}
@@ -58,7 +60,7 @@ layout: page
- {% include datetime.html date=post.date %}
+ {% include datetime.html date=post.date lang=lang %}
{% if post.categories.size > 0 %}
@@ -75,7 +77,7 @@ layout: page
{% if post.pin %}
- {{ site.data.locales[site.lang].post.pin_prompt }}
+ {{ site.data.locales[lang].post.pin_prompt }}
{% endif %}
diff --git a/_layouts/page.html b/_layouts/page.html
index 4285c85..1bfaa75 100644
--- a/_layouts/page.html
+++ b/_layouts/page.html
@@ -4,60 +4,58 @@ layout: default
{% include assets-origin.html %}
-
+{% include lang.html %}
+
-
- {% capture _content %}
+ {% capture _content %}
{% if layout.refactor or page.layout == 'page' %}
- {% include refactor-content.html content=content %}
+ {% include refactor-content.html content=content lang=lang %}
{% else %}
{{ content }}
{% endif %}
{% endcapture %}
- {% if page.layout == 'page' or page.collection == 'tabs' %}
- {% assign tab_key = page.title | downcase %}
- {% assign title = site.data.locales[site.lang].tabs[tab_key] | default: page.title %}
-
- {{ title }}
-
-
+ {% if page.layout == 'page' or page.collection == 'tabs' %}
+ {% assign tab_key = page.title | downcase %}
+ {% assign title = site.data.locales[lang].tabs[tab_key] | default: page.title %}
+
+ {{ title }}
+
+
+ {{ _content }}
+
+ {% else %}
{{ _content }}
-
- {% else %}
- {{ _content }}
- {% endif %}
-
+ {% endif %}
-
+
+
-
- {% include update-list.html %}
- {% include trending-tags.html %}
+ {% include update-list.html lang=lang %}
+ {% include trending-tags.html lang=lang %}
{% for _include in layout.panel_includes %}
{% assign _include_path = _include | append: '.html' %}
- {% include {{ _include_path }} %}
+ {% include {{ _include_path }} lang=lang %}
{% endfor %}
-
{% if layout.tail_includes %}
-
-
- {% for _include in layout.tail_includes %}
- {% assign _include_path = _include | append: '.html' %}
- {% include {{ _include_path }} %}
- {% endfor %}
+
+
+ {% for _include in layout.tail_includes %}
+ {% assign _include_path = _include | append: '.html' %}
+ {% include {{ _include_path }} lang=lang %}
+ {% endfor %}
+
-
{% endif %}
diff --git a/_layouts/post.html b/_layouts/post.html
index 367def5..2296df2 100644
--- a/_layouts/post.html
+++ b/_layouts/post.html
@@ -9,20 +9,22 @@ tail_includes:
- comments
---
+{% include lang.html %}
+
{{ page.title }}
- {{ site.data.locales[site.lang].post.posted }}
- {% include datetime.html date=page.date tooltip=true %}
+ {{ site.data.locales[lang].post.posted }}
+ {% include datetime.html date=page.date tooltip=true lang=lang %}
{% if page.last_modified_at %}
- {{ site.data.locales[site.lang].post.updated }}
- {% include datetime.html date=page.last_modified_at tooltip=true %}
+ {{ site.data.locales[lang].post.updated }}
+ {% include datetime.html date=page.last_modified_at tooltip=true lang=lang %}
{% endif %}
@@ -54,7 +56,7 @@ tail_includes:
{% assign authors = page.authors %}
{% endif %}
- {{ site.data.locales[site.lang].post.written_by }}
+ {{ site.data.locales[lang].post.written_by }}
{% if authors %}
@@ -75,12 +77,12 @@ tail_includes:
- {{ site.data.locales[site.lang].post.pageview_measure }}
+ {{ site.data.locales[lang].post.pageview_measure }}
{% endif %}
- {% include read-time.html content=content prompt=true %}
+ {% include read-time.html content=content prompt=true lang=lang %}
@@ -121,20 +123,20 @@ tail_includes:
d-flex justify-content-between align-items-center mt-3 pt-5 pb-2">
- {% include post-sharing.html %}
+ {% include post-sharing.html lang=lang %}
diff --git a/_layouts/tag.html b/_layouts/tag.html
index 5fd528f..8dbd65b 100644
--- a/_layouts/tag.html
+++ b/_layouts/tag.html
@@ -3,6 +3,8 @@ layout: page
# The layout for Tag page
---
+{% include lang.html %}
+
@@ -11,11 +13,11 @@ layout: page
{% for post in page.posts %}
- -
- {{ post.title }}
-
- {% include datetime.html date=post.date wrap='span' class='text-muted small' %}
-
+ -
+ {{ post.title }}
+
+ {% include datetime.html date=post.date wrap='span' class='text-muted small' lang=lang %}
+
{% endfor %}
diff --git a/assets/404.html b/assets/404.html
index 4490ea5..0337bac 100644
--- a/assets/404.html
+++ b/assets/404.html
@@ -9,6 +9,8 @@ redirect_from:
- /posts/
---
+{% include lang.html %}
+
-
{{site.data.locales[site.lang].not_found.statment }}
+
{{ site.data.locales[lang].not_found.statment }}