Skip to content

Commit

Permalink
chore: locale to string
Browse files Browse the repository at this point in the history
  • Loading branch information
kitian616 committed Nov 18, 2017
1 parent cdd6063 commit ae36cd0
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 34 deletions.
2 changes: 1 addition & 1 deletion _config.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ nav_lists:
url: /about.html

## GitHub repository (if the site is hosted by GitHub) ##
repository: someone.github.io
repository: someone/someone.github.io
repository_tree: master

## Language & timezone ##
Expand Down
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ nav_lists:
url: /about.html

## GitHub repository (if the site is hosted by GitHub) ##
# repository: e.g. someone.github.io
# repository: e.g. someone/someone.github.ioo
# repository_tree: e.g. master

## Language & timezone ##
Expand Down
8 changes: 4 additions & 4 deletions _includes/blog/article-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
</div>
{% endif %}
<div class="date-wrapper">
{% assign locale_ADF = site.data.locale.ARTICLE_DATE_FORMAT } %}
{% assign __locale = site.data.locale.ARTICLE_DATE_FORMAT } %}
{% include snippets/locale-to-string.html %}
{% if post %}
<span class="article-meta">
{% if locale_ADF[site.lang] %}{{ post.date | date: locale_ADF[site.lang] }}{% else %}{{ post.date | date: locale_ADF.en }}{% endif %}</span>
<span class="article-meta">{{ post.date | date: __return }}</span>
{% elsif page %}
<time class="article-meta" datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">
{% if locale_ADF[site.lang] %}{{ page.date | date: locale_ADF[site.lang] }}{% else %}{{ page.date | date: locale_ADF.en }}{% endif %}</time>
{{ page.date | date: __return }}</time>
{% endif %}
</div>
</div>
Expand Down
16 changes: 9 additions & 7 deletions _includes/blog/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
</div>
<nav>
<ul class="inline-list">
{% assign locale_pages = site.data.locale.PAGES %}
<li><a href="{{ "/" | prepend: site.baseurl | replace: '//', '/' }}">
{% if locale_pages.HOME[site.lang] %}{{ locale_pages.HOME[site.lang] }}{% else %}{{ locale_pages.HOME.en }}{% endif %}</a></li>
<li><a href="{{ "/all.html" | prepend: site.baseurl | append: "?tag=" | replace: '//', '/'}}">
{% if locale_pages.ALL[site.lang] %}{{ locale_pages.ALL[site.lang] }}{% else %}{{ locale_pages.ALL.en }}{% endif %}</a></li>
{% assign __locale = site.data.locale.PAGES.HOME %}
{% include snippets/locale-to-string.html %}
<li><a href="{{ "/" | prepend: site.baseurl | replace: '//', '/' }}">{{ __return }}</a></li>
{% assign __locale = site.data.locale.PAGES.ALL %}
{% include snippets/locale-to-string.html %}
<li><a href="{{ "/all.html" | prepend: site.baseurl | append: "?tag=" | replace: '//', '/'}}">{{ __return }}</a></li>
{% for list in site.nav_lists %}
<li><a href="{{ list.url }}"> {{ list.title }} </a></li>
{% endfor %}
<li><a type="application/rss+xml" href="{{ "/feed.xml" | prepend: site.baseurl | replace: '//', '/'}}">
{% if locale_pages.RSS[site.lang] %}{{ locale_pages.RSS[site.lang] }}{% else %}{{ locale_pages.RSS.en }}{% endif %}</a></li>
{% assign __locale = site.data.locale.PAGES.RSS %}
{% include snippets/locale-to-string.html %}
<li><a type="application/rss+xml" href="{{ "/feed.xml" | prepend: site.baseurl | replace: '//', '/'}}">{{ __return }}</a></li>
</ul>
</nav>
</header>
15 changes: 9 additions & 6 deletions _includes/blog/license.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
<a class="octocat" href="https://github.com/{{ site.repository }}/tree/{{ site.repository_tree }}/{{ page.path }}">
<img alt="View on Github" src="{{ "/assets/images/octocat.jpg" | prepend: site.baseurl | replace: '//', '/'}}" />
</a>
<p><a href="https://github.com/{{ site.repository }}/tree/{{ site.repository_tree }}/{{ page.path }}">
{% if locale.POST_ON_GITHUB[site.lang] %}{{ locale.POST_ON_GITHUB[site.lang] }}{% else %}{{ locale.POST_ON_GITHUB.en }}{% endif %}</a></p>
{% assign __locale = locale.POST_ON_GITHUB %}
{% include snippets/locale-to-string.html %}
<p><a href="https://github.com/{{ site.repository }}/tree/{{ site.repository_tree }}/{{ page.path }}">{{ __return }}</a></p>
{% endif %}
{% assign LICENSE_ANNOUNCE = '' %}
{% if locale.LICENSE_ANNOUNCE[site.lang] %}{% assign LICENSE_ANNOUNCE = locale.LICENSE_ANNOUNCE[site.lang] %}{% else %}{% assign LICENSE_ANNOUNCE = locale.LICENSE_ANNOUNCE.en %}{% endif %}</p>
<p>{{ LICENSE_ANNOUNCE | replace: "[LICENSE]", '<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/">CC-BY-NC-4.0</a>' }}</p>
{% assign __locale = locale.LICENSE_ANNOUNCE %}
{% include snippets/locale-to-string.html %}
<p>{{ __return | replace: "[LICENSE]", '<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/">CC-BY-NC-4.0</a>' }}</p>
<a class="license" rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/">
<img alt="Creative Commons License" src="{{ '/assets/images/license-cc4.png' | prepend: site.baseurl | replace: '//', '/'}}" />
</a>
<p>{% if locale.LICENSE_INTRO[site.lang] %}{{ locale.LICENSE_INTRO[site.lang] }}{% else %}{{ locale.LICENSE_INTRO.en }}{% endif %}</p>
{% assign __locale = locale.LICENSE_INTRO %}
{% include snippets/locale-to-string.html %}
<p>{{ __return }}</p>
</div>
</div>
2 changes: 1 addition & 1 deletion _includes/common-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>{% if page.title or page.titles[site.lang] or page.titles.en %}
{% include snippets/page-title.html %} - {{ site.title }}
{% include snippets/page-title.html %} - {{ site.title }}
{% else %}{{ site.title }}{% endif %}</title>
<meta name="description" content="{% if page.excerpt %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% else %}{{ site.description }}{% endif %}">
<link rel="canonical" href="{% include snippets/page-url.html %}">
Expand Down
2 changes: 2 additions & 0 deletions _includes/snippets/locale-to-string.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% assign __return = '' %}
{% if __locale[site.lang] %}{% assign __return = __locale[site.lang] %}{% else %}{% assign __return = __locale.en %}{% endif %}
4 changes: 3 additions & 1 deletion _includes/snippets/page-title.html
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{% if page.title %}{{ page.title }}{% elsif page.titles[site.lang] %}{{ page.titles[site.lang] }}{% else %}{{ page.titles.en }}{% endif %}
{% assign __locale = page.titles %}
{% include snippets/locale-to-string.html %}
{% if page.title %}{{ page.title }}{% else %}{{ __return }}{% endif %}
8 changes: 4 additions & 4 deletions _layouts/all.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ <h2 class="year-title" id="year-{{ post.date | date: "%Y" }}">{{ currentdate }}<
{% endfor %}
{% assign last = _tags | size | minus: 1 %}
{% assign _tags = _tags | slice: 1, last %}
{% assign __locale = site.data.locale.ARTICLE_LIST_DATA_FORMAT } %}
{% include snippets/locale-to-string.html %}
<li class="js-post-block" data-tag="{{ _tags }}">
{% assign locale_ALDF = site.data.locale.ARTICLE_LIST_DATA_FORMAT } %}
<span class="post-date">
{% if locale_ALDF[site.lang] %}{{ post.date | date: locale_ALDF[site.lang] }}{% else %}{{ post.date | date: locale_ALDF.en }}{% endif %}
</span><a class="post-link" href="{{ post.url | prepend: site.baseurl | replace: '//', '/' }}">{{ post.title }}</a>
<span class="post-date">{{ post.date | date: __return }}</span>
<a class="post-link" href="{{ post.url | prepend: site.baseurl | replace: '//', '/' }}">{{ post.title }}</a>
</li>
{% if forloop.last %}</ul></section>{% endif %}
{% endfor %}
Expand Down
6 changes: 3 additions & 3 deletions _layouts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ <h1>
{{ post.excerpt | strip_html | truncate: 350 }}
{% endif %}
</div>
{% assign locale_readmore = site.data.locale.READMORE %}
<a href="{{ post.url | prepend: site.baseurl | replace: '//', '/' }}">
{% if locale_readmore[site.lang] %}{{ locale_readmore[site.lang] }}{% else %}{{ locale_readmore.en }}{% endif %}</a>
{% assign __locale = site.data.locale.READMORE %}
{% include snippets/locale-to-string.html %}
<a href="{{ post.url | prepend: site.baseurl | replace: '//', '/' }}">{{ __return }}</a>
{% include blog/article-data.html %}
</article>
{% endfor %}
Expand Down
12 changes: 7 additions & 5 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ <h1 itemprop="headline" itemprop="name headline">{% include snippets/page-title.
</div>
<footer>
{% if page.modify_date %}
{% assign locale_ADF = site.data.locale.ARTICLE_DATE_FORMAT %}
{% assign locale_LU = site.data.locale.LAST_UPDATED %}
<span>{% if locale_LU[site.lang] %}{{ locale_LU[site.lang] }}{% else %}{{ locale_LU.en }}{% endif %}<time datetime="{{ page.modify_date | date_to_xmlschema }}" itemprop="dateModified">
{% if locale_ADF[site.lang] %}{{ page.modify_date | date: locale_ADF[site.lang] }}{% else %}{{ page.modify_date | date: locale_ADF.en }}{% endif %}
</time></span>
{% assign __locale = site.data.locale.LAST_UPDATED %}
{% include snippets/locale-to-string.html %}
<span>{{ __return }}
{% assign __locale = site.data.locale.ARTICLE_DATE_FORMAT %}
{% include snippets/locale-to-string.html %}
<time datetime="{{ page.modify_date | date_to_xmlschema }}" itemprop="dateModified">{{ page.modify_date | date: __return }}</time>
</span>
{% else %}
<meta itemprop="dateModified" content="{{ page.date | date_to_xmlschema }}">
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion test/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ nav_lists:
url: /about.html

## GitHub repository (if the site is hosted by GitHub) ##
# repository: e.g. someone.github.io
# repository: e.g. someone/someone.github.io
# repository_tree: e.g. master

## Language & timezone ##
Expand Down

0 comments on commit ae36cd0

Please sign in to comment.