Skip to content

Commit

Permalink
feat: multi languages
Browse files Browse the repository at this point in the history
  • Loading branch information
kitian616 committed Nov 16, 2017
1 parent ba6711e commit 9095e93
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bundle exec jekyll serve -H 0.0.0.0

### 网站图标

该主题自带了一个“银杏叶”图标,你可以把它替换为自己的图标。网站的图标位于根目录的 ./favicon.ico 和 ./assets/images/logo 目录下。你会看到 logo 目录中有很多的 png 文件和一个 svg 矢量图文件。那些 png 图片实际上就是根据 svg 矢量图生成的不同大小的图片,这些图片是一些场景可能会用到的大图标,像 iOS 和 Android 的固定到屏幕和 Windows 10 的磁贴。
该主题自带了一个“银杏叶”图标,你可以把它替换为自己的图标。网站的图标位于 ./favicon.ico 和 ./assets/images/logo 目录下。你会看到 logo 目录中有很多的 png 文件和一个 svg 矢量图文件。那些 png 图片实际上就是根据 svg 矢量图生成的不同大小的图片,这些图片是一些场景可能会用到的大图标,像 iOS 和 Android 的固定到屏幕和 Windows 10 的磁贴。

该主题提供了一个自动化脚本能将 svg 矢量图自动生成 favicon 和 png 文件。你所要做的是:

Expand Down
2 changes: 1 addition & 1 deletion _config.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ nav_lists:
# repository_tree: e.g. master

## Language & timezone ##
lang: zh #the language of your site
lang: zh #the language of your site eg: zh, en
timezone: Asia/Shanghai

## Author & social ##
Expand Down
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ nav_lists:
# repository_tree: e.g. master

## Language & timezone ##
lang: zh #the language of your site
lang: en #the language of your site eg: zh, en
timezone: Asia/Shanghai

## Author & social ##
Expand Down
28 changes: 28 additions & 0 deletions _data/locale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
LINKS:
HOME:
en: Home
zh: 主页
ALL:
en: All
zh: 归档
RSS:
en: RSS
zh: RSS

READMORE:
en: Click to read more ...
zh: 点我阅读更多...

COPYRIGHT_DATES: 2015 - 2017

LAST_UPDATED:
en: 'Last updated'
zh: '更新于'

ARTICLE_DATE_FORMAT:
en: '%b %d, %Y'
zh: '%Y年 %m月%d日'

ARTICLE_LIST_DATA_FORMAT:
en: '%b %d'
zh: '%m月%d日'
7 changes: 4 additions & 3 deletions _includes/blog/article-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
</div>
{% endif %}
<div class="date-wrapper">
{% assign locale_ADF = site.data.locale.ARTICLE_DATE_FORMAT } %}
{% if post %}
<span class="article-meta">{{ post.date | date: "%b %d, %Y" }}</span>
<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>
{% elsif page %}
<time class="article-meta" datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">
{{ page.date | date: "%b %-d, %Y" }}
</time>
{% if locale_ADF[site.lang] %}{{ page.date | date: locale_ADF[site.lang] }}{% else %}{{ page.date | date: locale_ADF.en }}{% endif %}</time>
{% endif %}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion _includes/blog/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% include info/follow-me.html %}
</aside>
<footer class="site-info">
<p>© {{ site.title }} 2015 - 2017</p>
<p>© {{ site.title }} {{ site.data.locale.COPYRIGHT_DATES }}</p>
<p>Powered by <a
title="Jekyll is a simple, blog-aware, static site generator." href="http://jekyllrb.com/">Jekyll</a> & <a
title="TeXt is a succinct theme for blogging." href="https://github.com/kitian616/jekyll-TeXt-theme">TeXt Theme</a>.
Expand Down
14 changes: 7 additions & 7 deletions _includes/blog/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
</div>
<nav>
<ul class="inline-list">
<li><a href="{{ "/" | prepend: site.baseurl | replace: '//', '/' }}">Home</a></li>
<li><a
href="{{ "/all.html" | prepend: site.baseurl | append: "?tag=" | replace: '//', '/'}}">All
</a></li>
{% assign locale_link = site.data.locale.LINKS %}
<li><a href="{{ "/" | prepend: site.baseurl | replace: '//', '/' }}">
{% if locale_link.HOME[site.lang] %}{{ locale_link.HOME[site.lang] }}{% else %}{{ locale_link.HOME.en }}{% endif %}</a></li>
<li><a href="{{ "/all.html" | prepend: site.baseurl | append: "?tag=" | replace: '//', '/'}}">
{% if locale_link.ALL[site.lang] %}{{ locale_link.ALL[site.lang] }}{% else %}{{ locale_link.ALL.en }}{% endif %}</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: '//', '/'}}">RSS
</a></li>
<li><a type="application/rss+xml" href="{{ "/feed.xml" | prepend: site.baseurl | replace: '//', '/'}}">
{% if locale_link.RSS[site.lang] %}{{ locale_link.RSS[site.lang] }}{% else %}{{ locale_link.RSS.en }}{% endif %}</a></li>
</ul>
</nav>
</header>
9 changes: 6 additions & 3 deletions _layouts/all.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
---
<div class="m-all">
<div class="main">
<h1 class="js-page-heading">All Posts</h1>
<h1 class="js-page-heading">{{ page.title }}</h1>
{% include blog/tags.html %}
<!--group by year: http://stackoverflow.com/questions/19086284/jekyll-liquid-templating-how-to-group-blog-posts-by-year-->
<section class="js-year-wrapper">
Expand All @@ -25,7 +25,10 @@ <h2 class="year-title" id="year-{{ post.date | date: "%Y" }}">{{ currentdate }}<
{% assign last = _tags | size | minus: 1 %}
{% assign _tags = _tags | slice: 1, last %}
<li class="js-post-block" data-tag="{{ _tags }}">
<span class="post-date">{{ post.date | date:"%b %d" }}</span><a class="post-link" href="{{ post.url | prepend: site.baseurl | replace: '//', '/' }}">{{ post.title }}</a>
{% 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>
</li>
{% if forloop.last %}</ul></section>{% endif %}
{% endfor %}
Expand Down Expand Up @@ -69,7 +72,7 @@ <h2 class="year-title" id="year-{{ post.date | date: "%Y" }}">{{ currentdate }}<
var i = 0, flag = false, cur, tagStr = '',
tags = [], _tag = '', lis = [];
if (tag === undefined || tag === '') {
$pageHeading.text('All Posts'); $tagShowAll.focus(); $postBlock.show();
$pageHeading.text('{{ page.title }}'); $tagShowAll.focus(); $postBlock.show();
} else {
tag = tag.trim();
// $articleTag.filter('.tag-' + tag).focus();
Expand Down
4 changes: 3 additions & 1 deletion _layouts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ <h1>
{{ post.excerpt | strip_html | truncate: 350 }}
{% endif %}
</div>
<a href="{{ post.url | prepend: site.baseurl | replace: '//', '/' }}">Click to read more ...</a>
{% 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>
{% include blog/article-data.html %}
</article>
{% endfor %}
Expand Down
11 changes: 5 additions & 6 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ <h1 itemprop="headline" itemprop="name headline">{{ page.title }}</h1>
</div>
<footer>
{% if page.modify_date %}
<span>
Last updated
<time datetime="{{ page.modify_date | date_to_xmlschema }}" itemprop="dateModified">
{{ page.modify_date | date: "%b %-d, %Y" }}
</time>
</span>
{% 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>
{% else %}
<meta itemprop="dateModified" content="{{ page.date | date_to_xmlschema }}">
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion jekyll-text-theme.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0").select do |f|
f.match(%r{^((_includes|_layouts|_sass|assets)/|(LICENSE|README)((\.(txt|md|markdown)|$)))}i)
f.match(%r{^((_data|_includes|_layouts|_sass|assets)/|(LICENSE|README)((\.(txt|md|markdown)|$)))}i)
end

spec.add_runtime_dependency "jekyll", "~> 3.5"
Expand Down
2 changes: 1 addition & 1 deletion test/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ nav_lists:
# repository_tree: e.g. master

## Language & timezone ##
lang: zh #the language of your site
lang: en #the language of your site eg: zh, en
timezone: Asia/Shanghai

## Author & social ##
Expand Down

0 comments on commit 9095e93

Please sign in to comment.