refactor: reduce language include file

This commit is contained in:
Cotes Chung 2022-10-19 03:53:47 +08:00
parent 6852ceb280
commit d96fa5aa0c
No known key found for this signature in database
GPG key ID: 0D9E54843167A808
23 changed files with 59 additions and 85 deletions

View file

@ -4,8 +4,8 @@
-->
{% assign wrap_elem = include.wrap | default: 'em' %}
{% assign df_strftime = site.data.locales[lang].df.post.strftime | default: '%d/%m/%Y' %}
{% assign df_dayjs = site.data.locales[lang].df.post.dayjs | default: 'DD/MM/YYYY' %}
{% 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' %}
<{{ wrap_elem }} class="{% if include.class %}{{ include.class }}{% endif %}"
data-ts="{{ include.date | date: '%s' }}"

View file

@ -7,9 +7,9 @@
<p class="mb-0">
© {{ 'now' | date: "%Y" }}
<a href="{{ site.social.links[0] }}">{{ site.social.name }}</a>.
{% if site.data.locales[lang].copyright.brief %}
{% if site.data.locales[site.lang].copyright.brief %}
<span data-toggle="tooltip" data-placement="top"
title="{{ site.data.locales[lang].copyright.verbose }}">{{ site.data.locales[lang].copyright.brief }}</span>
title="{{ site.data.locales[site.lang].copyright.verbose }}">{{ site.data.locales[site.lang].copyright.brief }}</span>
{% endif %}
</p>
</div>
@ -25,7 +25,7 @@
<a href="https://github.com/cotes2020/jekyll-theme-chirpy" target="_blank" rel="noopener">Chirpy</a>
{% endcapture %}
{{ site.data.locales[lang].meta
{{ site.data.locales[site.lang].meta
| default: 'Powered by :PLATFORM with :THEME theme.'
| replace: ':PLATFORM', _platform | replace: ':THEME', _theme
}}

View file

@ -1,8 +0,0 @@
{% 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 %}

View file

@ -5,24 +5,24 @@
<div class="post-navigation d-flex justify-content-between">
{% if page.previous.url %}
<a href="{{ site.baseurl }}{{ page.previous.url }}" class="btn btn-outline-primary"
prompt="{{ site.data.locales[lang].post.button.previous }}">
prompt="{{ site.data.locales[site.lang].post.button.previous }}">
<p>{{ page.previous.title }}</p>
</a>
{% else %}
<div class="btn btn-outline-primary disabled"
prompt="{{ site.data.locales[lang].post.button.previous }}">
prompt="{{ site.data.locales[site.lang].post.button.previous }}">
<p>-</p>
</div>
{% endif %}
{% if page.next.url %}
<a href="{{ site.baseurl }}{{page.next.url}}" class="btn btn-outline-primary"
prompt="{{ site.data.locales[lang].post.button.next }}">
prompt="{{ site.data.locales[site.lang].post.button.next }}">
<p>{{ page.next.title }}</p>
</a>
{% else %}
<div class="btn btn-outline-primary disabled"
prompt="{{ site.data.locales[lang].post.button.next }}">
prompt="{{ site.data.locales[site.lang].post.button.next }}">
<p>-</p>
</div>
{% endif %}

View file

@ -3,7 +3,7 @@
-->
<div class="share-wrapper">
<span class="share-label text-muted mr-1">{{ site.data.locales[lang].post.share }}</span>
<span class="share-label text-muted mr-1">{{ site.data.locales[site.lang].post.share }}</span>
<span class="share-icons">
{% capture title %}{{ page.title }} - {{ site.title }}{% endcapture %}
{% assign title = title | url_encode %}
@ -19,8 +19,8 @@
<i id="copy-link" class="fa-fw fas fa-link small"
data-toggle="tooltip" data-placement="top"
title="{{ site.data.locales[lang].post.button.share_link.title }}"
data-title-succeed="{{ site.data.locales[lang].post.button.share_link.succeed }}">
title="{{ site.data.locales[site.lang].post.button.share_link.title }}"
data-title-succeed="{{ site.data.locales[site.lang].post.button.share_link.succeed }}">
</i>
</span>

View file

@ -16,13 +16,13 @@
{% endunless %}
{% capture read_prompt %}
{{- site.data.locales[lang].post.read_time.prompt -}}
{{- site.data.locales[site.lang].post.read_time.prompt -}}
{% endcapture %}
<!-- return element -->
<span class="readtime" data-toggle="tooltip" data-placement="bottom"
title="{{ words }} {{ site.data.locales[lang].post.words }}">
<em>{{- read_time -}}{{" "}}{{- site.data.locales[lang].post.read_time.unit -}}</em>
title="{{ words }} {{ site.data.locales[site.lang].post.words }}">
<em>{{- read_time -}}{{" "}}{{- site.data.locales[site.lang].post.read_time.unit -}}</em>
{%- if include.prompt -%}
{%- assign _prompt_words = read_prompt | number_of_words: 'auto' -%}
{%- unless _prompt_words > 1 -%}{{ " " }}{%- endunless -%}{{ read_prompt }}

View file

@ -177,7 +177,7 @@
| append: '<div class="code-header">'
| append: _label
| append: '<button aria-label="copy" data-title-succeed="'
| append: site.data.locales[lang].post.button.copy_code.succeed
| append: site.data.locales[site.lang].post.button.copy_code.succeed
| append: '"><i class="far fa-clipboard"></i></button></div>'
| append: '<div class="highlight"><code>'
%}

View file

@ -78,7 +78,7 @@
{% if index_list.size > 0 %}
<div id="related-posts" class="mb-2 mb-sm-4">
<h3 class="pt-2 mb-4 ml-1"
data-toc-skip>{{ site.data.locales[lang].post.relate_posts }}</h3>
data-toc-skip>{{ site.data.locales[site.lang].post.relate_posts }}</h3>
<div class="card-deck mb-4">
{% for entry in index_list %}
{% assign index = entry | plus: 0 %}

View file

@ -14,7 +14,7 @@
</div>
{% endcapture %}
{% capture not_found %}<p class="mt-5">{{ site.data.locales[lang].search.no_results }}</p>{% endcapture %}
{% capture not_found %}<p class="mt-5">{{ site.data.locales[site.lang].search.no_results }}</p>{% endcapture %}
<script src="{{ site.data.assets[origin].search.js | relative_url }}"></script>

View file

@ -34,7 +34,7 @@
<li class="nav-item{% if page.layout == 'home' %}{{ " active" }}{% endif %}">
<a href="{{ '/' | relative_url }}" class="nav-link">
<i class="fa-fw fas fa-home ml-xl-3 mr-xl-3 unloaded"></i>
<span>{{ site.data.locales[lang].tabs.home | upcase }}</span>
<span>{{ site.data.locales[site.lang].tabs.home | upcase }}</span>
</a>
</li>
<!-- the real tabs -->
@ -44,7 +44,7 @@
<i class="fa-fw {{ tab.icon }} ml-xl-3 mr-xl-3 unloaded"></i>
{% capture tab_name %}{{ tab.url | split: '/' }}{% endcapture %}
<span>{{ site.data.locales[lang].tabs.[tab_name] | default: tab.title | upcase }}</span>
<span>{{ site.data.locales[site.lang].tabs.[tab_name] | default: tab.title | upcase }}</span>
</a>
</li> <!-- .nav-item -->
{% endfor %}

View file

@ -10,7 +10,7 @@
<script src="{{ site.data.assets[origin].bootstrap-toc.js | relative_url }}"></script>
<div id="toc-wrapper" class="pl-0 pr-4 mb-5">
<div class="panel-heading pl-3 pt-2 mb-2">{{- site.data.locales[lang].panel.toc -}}</div>
<div class="panel-heading pl-3 pt-2 mb-2">{{- site.data.locales[site.lang].panel.toc -}}</div>
<nav id="toc" data-toggle="toc"></nav>
</div>
{% endif %}

View file

@ -10,7 +10,7 @@
{% if paths.size == 0 or page.layout == 'home' %}
<!-- index page -->
<span>{{ site.data.locales[lang].tabs.home | capitalize }}</span>
<span>{{ site.data.locales[site.lang].tabs.home | capitalize }}</span>
{% else %}
@ -19,14 +19,14 @@
{% if forloop.first %}
<span>
<a href="{{ '/' | relative_url }}">
{{ site.data.locales[lang].tabs.home | capitalize }}
{{ site.data.locales[site.lang].tabs.home | capitalize }}
</a>
</span>
{% elsif forloop.last %}
{% if page.collection == 'tabs' %}
<span>{{ site.data.locales[lang].tabs[item] | default: page.title }}</span>
<span>{{ site.data.locales[site.lang].tabs[item] | default: page.title }}</span>
{% else %}
<span>{{ page.title }}</span>
{% endif %}
@ -34,7 +34,7 @@
{% elsif page.layout == 'category' or page.layout == 'tag' %}
<span>
<a href="{{ item | relative_url }}">
{{ site.data.locales[lang].tabs[item] | default: page.title }}
{{ site.data.locales[site.lang].tabs[item] | default: page.title }}
</a>
</span>
{% endif %}
@ -49,12 +49,12 @@
<div id="topbar-title">
{% if page.layout == 'home' %}
{{- site.data.locales[lang].title | default: site.title -}}
{{- site.data.locales[site.lang].title | default: site.title -}}
{% elsif page.collection == 'tabs' or page.layout == 'page' %}
{%- capture tab_key -%}{{ page.url | split: '/' }}{%- endcapture -%}
{{- site.data.locales[lang].tabs[tab_key] | default: page.title -}}
{{- site.data.locales[site.lang].tabs[tab_key] | default: page.title -}}
{% else %}
{{- site.data.locales[lang].layout[page.layout] | default: page.layout | capitalize -}}
{{- site.data.locales[site.lang].layout[page.layout] | default: page.layout | capitalize -}}
{% endif %}
</div>
@ -62,9 +62,9 @@
<span id="search-wrapper" class="align-items-center">
<i class="fas fa-search fa-fw"></i>
<input class="form-control" id="search-input" type="search"
aria-label="search" autocomplete="off" placeholder="{{ site.data.locales[lang].search.hint | capitalize }}...">
aria-label="search" autocomplete="off" placeholder="{{ site.data.locales[site.lang].search.hint | capitalize }}...">
</span>
<span id="search-cancel" >{{ site.data.locales[lang].search.cancel }}</span>
<span id="search-cancel" >{{ site.data.locales[site.lang].search.cancel }}</span>
</div>
</div>

View file

@ -37,7 +37,7 @@
{% if trending_tags.size > 0 %}
<div id="access-tags">
<div class="panel-heading">{{- site.data.locales[lang].panel.trending_tags -}}</div>
<div class="panel-heading">{{- site.data.locales[site.lang].panel.trending_tags -}}</div>
<div class="d-flex flex-wrap mt-3 mb-1 mr-3">
{% for tag_name in trending_tags %}

View file

@ -26,7 +26,7 @@
{% if update_list.size > 0 %}
<div id="access-lastmod" class="post">
<div class="panel-heading">{{- site.data.locales[lang].panel.lastmod -}}</div>
<div class="panel-heading">{{- site.data.locales[site.lang].panel.lastmod -}}</div>
<ul class="post-content pl-0 pb-1 ml-1 mt-2">
{% for item in update_list %}
{% assign index = item | split: "::" | last | plus: 0 %}

View file

@ -3,10 +3,8 @@ layout: page
# The Archives of posts.
---
{% 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' %}
{% 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' %}
<div id="archives" class="pl-xl-3">

View file

@ -3,8 +3,6 @@ layout: page
# All the Categories of posts
---
{% include lang.html %}
{% assign HEAD_PREFIX = "h_" %}
{% assign LIST_PREFIX = "l_" %}
@ -48,22 +46,22 @@ layout: page
{% if sub_categories_size > 0 %}
{{ sub_categories_size }}
{% if sub_categories_size > 1 %}
{{ site.data.locales[lang].categories.category_measure.plural
| default: site.data.locales[lang].categories.category_measure }}
{{ site.data.locales[site.lang].categories.category_measure.plural
| default: site.data.locales[site.lang].categories.category_measure }}
{% else %}
{{ site.data.locales[lang].categories.category_measure.singular
| default: site.data.locales[lang].categories.category_measure }}
{{ site.data.locales[site.lang].categories.category_measure.singular
| default: site.data.locales[site.lang].categories.category_measure }}
{% endif %},
{% endif %}
{{ top_posts_size }}
{% if top_posts_size > 1 %}
{{ site.data.locales[lang].categories.post_measure.plural
| default: site.data.locales[lang].categories.post_measure }}
{{ site.data.locales[site.lang].categories.post_measure.plural
| default: site.data.locales[site.lang].categories.post_measure }}
{% else %}
{{ site.data.locales[lang].categories.post_measure.singular
| default: site.data.locales[lang].categories.post_measure }}
{{ site.data.locales[site.lang].categories.post_measure.singular
| default: site.data.locales[site.lang].categories.post_measure }}
{% endif %}
</span>
</span>
@ -99,11 +97,11 @@ layout: page
{{ posts_size }}
{% if posts_size > 1 %}
{{ site.data.locales[lang].categories.post_measure.plural
| default: site.data.locales[lang].categories.post_measure }}
{{ site.data.locales[site.lang].categories.post_measure.plural
| default: site.data.locales[site.lang].categories.post_measure }}
{% else %}
{{ site.data.locales[lang].categories.post_measure.singular
| default: site.data.locales[lang].categories.post_measure }}
{{ site.data.locales[site.lang].categories.post_measure.singular
| default: site.data.locales[site.lang].categories.post_measure }}
{% endif %}
</span>
</li>

View file

@ -3,8 +3,6 @@ layout: page
# The Category layout
---
{% include lang.html %}
<div id="page-category">
<h1 class="pl-lg-2">
<i class="far fa-folder-open fa-fw text-muted"></i>

View file

@ -5,8 +5,6 @@ layout: compress
<!DOCTYPE html>
{% include lang.html %}
{% include assets-origin.html %}
{% capture prefer_mode %}
@ -56,9 +54,9 @@ layout: compress
</button>
</div>
<div class="toast-body text-center pt-0">
<p class="pl-2 pr-2 mb-3">{{ site.data.locales[lang].notification.update_found }}</p>
<p class="pl-2 pr-2 mb-3">{{ site.data.locales[site.lang].notification.update_found }}</p>
<button type="button" class="btn btn-primary" aria-label="Update">
{{ site.data.locales[lang].notification.update }}
{{ site.data.locales[site.lang].notification.update }}
</button>
</div>
</div>

View file

@ -3,8 +3,6 @@ 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" %}
@ -79,7 +77,7 @@ layout: page
{% if post.pin %}
<div class="pin">
<i class="fas fa-thumbtack fa-fw"></i>
<span>{{ site.data.locales[lang].post.pin_prompt }}</span>
<span>{{ site.data.locales[site.lang].post.pin_prompt }}</span>
</div>
{% endif %}

View file

@ -2,8 +2,6 @@
layout: default
---
{% include lang.html %}
{% include assets-origin.html %}
<div class="row">
@ -22,7 +20,7 @@ layout: default
{% 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 %}
{% assign title = site.data.locales[site.lang].tabs[tab_key] | default: page.title %}
<h1 class="dynamic-title">
{{ title }}
</h1>

View file

@ -9,21 +9,19 @@ tail_includes:
- comments
---
{% include lang.html %}
<h1 data-toc-skip>{{ page.title }}</h1>
<div class="post-meta text-muted">
<!-- published date -->
<span>
{{ site.data.locales[lang].post.posted }}
{{ site.data.locales[site.lang].post.posted }}
{% include datetime.html date=page.date tooltip=true %}
</span>
<!-- lastmod date -->
{% if page.last_modified_at %}
<span>
{{ site.data.locales[lang].post.updated }}
{{ site.data.locales[site.lang].post.updated }}
{% include datetime.html date=page.last_modified_at tooltip=true %}
</span>
{% endif %}
@ -65,7 +63,7 @@ tail_includes:
{% assign authors = page.authors %}
{% endif %}
{{ site.data.locales[lang].post.written_by }}
{{ site.data.locales[site.lang].post.written_by }}
<em>
{% if authors %}
@ -86,7 +84,7 @@ tail_includes:
<em id="pv" class="pageviews">
<i class="fas fa-spinner fa-spin fa-fw"></i>
</em>
{{ site.data.locales[lang].post.pageview_measure }}
{{ site.data.locales[site.lang].post.pageview_measure }}
</span>
{% endif %}
@ -132,15 +130,15 @@ tail_includes:
d-flex justify-content-between align-items-center mt-3 pt-5 pb-2">
<div class="license-wrapper">
{% if site.data.locales[lang].copyright.license.template %}
{% if site.data.locales[site.lang].copyright.license.template %}
{% capture _replacement %}
<a href="{{ site.data.locales[lang].copyright.license.link }}">
{{ site.data.locales[lang].copyright.license.name }}
<a href="{{ site.data.locales[site.lang].copyright.license.link }}">
{{ site.data.locales[site.lang].copyright.license.name }}
</a>
{% endcapture %}
{{ site.data.locales[lang].copyright.license.template | replace: ':LICENSE_NAME', _replacement }}
{{ site.data.locales[site.lang].copyright.license.template | replace: ':LICENSE_NAME', _replacement }}
{% endif %}
</div>

View file

@ -3,8 +3,6 @@ layout: page
# The layout for Tag page
---
{% include lang.html %}
<div id="page-tag">
<h1 class="pl-lg-2">
<i class="fa fa-tag fa-fw text-muted"></i>

View file

@ -9,8 +9,6 @@ redirect_from:
- /posts/
---
{% include lang.html %}
<div class="lead">
<p>{{site.data.locales[lang].not_found.statment }}</p>
<p>{{site.data.locales[site.lang].not_found.statment }}</p>
</div>