Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejh/hugo-theme-cactus-plus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHang Jiang <jianghangscu@gmail.com>2021-08-21 18:05:30 +0300
committerGitHub <noreply@github.com>2021-08-21 18:05:30 +0300
commit82c38b65ec3d82df24fc26229e23c1ec7545d21a (patch)
tree8ff116c04889ce60309137d6fdfac8775c56545a
parentc293a33d4713edb3ab9879127e1789d2866af155 (diff)
parent655b4841ba2c7efb7f108d78ea9064b3ff724ea0 (diff)
Merge pull request #105 from nodejh/feature/i18n
feat: support multiple languages
-rw-r--r--CHANGELOG6
-rw-r--r--README-zh_CN.md17
-rw-r--r--README.md26
-rw-r--r--data/months_nl.yaml12
-rw-r--r--exampleSite/config-example.yaml2
-rw-r--r--exampleSite/config.yaml24
-rw-r--r--i18n/en.yaml50
-rw-r--r--i18n/nl.yaml53
-rw-r--r--i18n/zh.yaml50
-rw-r--r--layouts/404.html6
-rw-r--r--layouts/_default/list.html2
-rw-r--r--layouts/_default/single.html12
-rw-r--r--layouts/index.html11
-rw-r--r--layouts/partials/footer.html2
-rw-r--r--layouts/partials/navigation.html10
-rw-r--r--layouts/partials/toc.html24
-rw-r--r--static/css/style.css2
17 files changed, 251 insertions, 58 deletions
diff --git a/CHANGELOG b/CHANGELOG
index fa7fb80..44dccc9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,8 @@
-## 2021.03.01 Version 2.1.0
+## 2021.08.21 Version 2.2.0
+
+- [x] Support multiple languages
+
+## 2021.08.17 Version 2.1.0
- [x] Adding ability to disable disqus comments on a single post
diff --git a/README-zh_CN.md b/README-zh_CN.md
index 824e29f..e89454e 100644
--- a/README-zh_CN.md
+++ b/README-zh_CN.md
@@ -72,6 +72,23 @@
> ⚠️ 你需要删除这行配置: `themesDir: ../../` 。
+### 2.2 默认语言
+
+你可以通过 `defaultContentLanguage` 配置设置默认语言:
+
+```yaml
+defaultContentLanguage: en
+```
+
+默认是 `en`。目前支持以下语言:
+
+- `en`: 英语
+- `zh`: 汉语
+- `nl`: 荷兰语
+
+更多关于多语言的信息可以参考:[Multilingual Mode](https://gohugo.io/content-management/multilingual/)。
+
+
### 2.2 评论功能
要使用评论功能,你需要添加下面的配置:
diff --git a/README.md b/README.md
index 7ce417d..fcf2681 100644
--- a/README.md
+++ b/README.md
@@ -70,7 +70,23 @@ Take a look inside the [`exampleSite`](https://github.com/nodejh/hugo-theme-mini
> ⚠️ You may need to delete the line: `themesDir: ../../`
-### 2.2 Add Comments
+### 2.2 Default Content Language
+
+You can set default content language by `defaultContentLanguage`:
+
+```yaml
+defaultContentLanguage: en
+```
+
+Default is `en`. Now support:
+
+- `en`: English
+- `zh`: Chinese
+- `nl`: Dutch
+
+More about multiple languages: [Multilingual Mode](https://gohugo.io/content-management/multilingual/).
+
+### 2.3 Add Comments
To enable comments, add following to your config file:
@@ -82,7 +98,7 @@ To enable comments, add following to your config file:
enableComments: true
```
-### 2.3 Google Analytics
+### 2.4 Google Analytics
To enable google analytics, add following to your config file:
@@ -94,7 +110,7 @@ To enable google analytics, add following to your config file:
enableGoogleAnalytics: true
```
-### 2.4 Logo and favicon
+### 2.5 Logo and favicon
You can replace the log in the top of each page and favicon with your own images. To do that put your own logo and favicon into the `images` directory of your website static directory, then named them `avatar.png` and `favicon.ico`. For example:
@@ -106,7 +122,7 @@ You can replace the log in the top of each page and favicon with your own images
└── favicon.ico
```
-### 2.5 Nearly finished
+### 2.6 Nearly finished
In order to see your site in action, run Hugo's built-in local server.
@@ -116,7 +132,7 @@ $ hugo server
Now enter http://localhost:1313 in the address bar of your browser.
-### 2.6 Production
+### 2.7 Production
To run in production (e.g. to have Google Analytics show up), run HUGO_ENV=production before your build command. For example:
diff --git a/data/months_nl.yaml b/data/months_nl.yaml
new file mode 100644
index 0000000..c979892
--- /dev/null
+++ b/data/months_nl.yaml
@@ -0,0 +1,12 @@
+1: "januari"
+2: "februari"
+3: "maart"
+4: "april"
+5: "mei"
+6: "juni"
+7: "juli"
+8: "augustus"
+9: "september"
+10: "oktober"
+11: "november"
+12: "december" \ No newline at end of file
diff --git a/exampleSite/config-example.yaml b/exampleSite/config-example.yaml
index 383b76f..00adc63 100644
--- a/exampleSite/config-example.yaml
+++ b/exampleSite/config-example.yaml
@@ -4,7 +4,7 @@ title: Hugo
theme: hugo-theme-mini
paginate: 3
-# for exampleSite only, you may need to delete the line: `themesDir: ../../`
+# !!! exampleSite only, you may need to delete the line: `themesDir: ../../`
themesDir: ../../
hasCJKLanguage: true
diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml
index b5caf30..1854e16 100644
--- a/exampleSite/config.yaml
+++ b/exampleSite/config.yaml
@@ -3,7 +3,10 @@ languageCode: en-us
title: Hugo
theme: hugo-theme-mini
-# for exampleSite only, you may need to delete the line: `themesDir: ../../`
+# Default content language, support en (English) / zh (Chinese) / nl (Dutch), default 'en'
+defaultContentLanguage: en
+
+# !!! exampleSite only, you may need to delete the line: `themesDir: ../../`
themesDir: ../../
hasCJKLanguage: true
@@ -14,7 +17,7 @@ googleAnalytics: your-google-analytics-id
disqusShortname: your-disqus-shortname
# Hugo Configure Markup
-# more info: https://gohugo.io/getting-started/configuration-markup#
+# More info: https://gohugo.io/getting-started/configuration-markup#
markup:
highlight:
guessSyntax: true
@@ -44,7 +47,7 @@ params:
###########################################
- # Optional
+ # Optional Configuration
###########################################
# To enable RSS, you could set `enableRSS: true`, default is `true`
@@ -61,19 +64,8 @@ params:
math: false
# To hidden post summary in home page, you could set `hiddenPostSummaryInHomePage: true`, default is `false`
hiddenPostSummaryInHomePage: false
-
- # text in page
- home: '' # Default: Home
- about: '' # Default: About
- archive: '' # Default: Archive
- tags: '' # Default: Tags
- subscribe: '' # Default: Subscribe
- olderPosts: '' # Default: Older Posts
- newerPosts: '' # Default: Newer Posts
- copyright: '' # Default: © Copyright 2021 ❤️ author
- title404: '' # Default: 404 - Page Not Found
- subtitle404: '' # Default: The content you're looking for doesn't seem to exist.
- readMore: '' # Default: Read More
+ # Website copy write, default: '© Copyright 2021 ❤️ {params.author}'
+ copyright: ''
# Extra links in navigation
links:
diff --git a/i18n/en.yaml b/i18n/en.yaml
new file mode 100644
index 0000000..66ba272
--- /dev/null
+++ b/i18n/en.yaml
@@ -0,0 +1,50 @@
+home:
+ other: Home
+
+archive:
+ other: Archive
+
+tags:
+ other: Tags
+
+about:
+ other: About
+
+subscribe:
+ other: Subscribe
+
+404title:
+ other: 404 - Page Not Found
+
+404subtitle:
+ other: The content you're looking for doesn't seem to exist.
+
+readMore:
+ other: Read more
+
+minuteRead:
+ other: "{{ .ReadingTime }} minute read"
+
+publishDate:
+ other: '{{ .PublishDate.Format "January 2, 2006" }}'
+
+publishDateFull:
+ other: '{{ .PublishDate.Format "January 2, 2006" }}'
+
+wordCount:
+ one: "{{ .WordCount }} word"
+ other: "{{ .WordCount }} words"
+
+postsNewer:
+ other: Newer posts
+
+postsOlder:
+ other: Older posts
+
+poweredBy:
+ other: >-
+ Powered by <a href='http://www.gohugo.io/'>Hugo</a> Theme By <a
+ href='https://github.com/nodejh/hugo-theme-cactus-plus'>nodejh</a>
+
+publishDateShort:
+ other: '{{ .PublishDate.Format "January 2" }}'
diff --git a/i18n/nl.yaml b/i18n/nl.yaml
new file mode 100644
index 0000000..d2f8704
--- /dev/null
+++ b/i18n/nl.yaml
@@ -0,0 +1,53 @@
+home:
+ other: Huis
+
+archive:
+ other: Archief
+
+tags:
+ other: Tags
+
+subscribe:
+ other: Abonneren
+
+about:
+ other: Over
+
+404title:
+ other: 404 - Pagina Niet Gevonden
+
+404subtitle:
+ other: 'De pagina waar u naar op zoek bent, lijkt niet te bestaan.'
+
+readMore:
+ other: Lees meer
+
+minuteRead:
+ other: "{{ .ReadingTime }} minuten leestijd"
+
+publishDate:
+ other: >-
+ {{ .PublishDate.Day }} {{ index $.Site.Data.months_nl (printf "%d" .PublishDate.Month) }} {{ .PublishDate.Year }}
+
+publishDateFull:
+ other: >-
+ {{ .PublishDate.Day }} {{ index $.Site.Data.months_nl (printf "%d" .PublishDate.Month) }} {{ .PublishDate.Year }}
+
+wordCount:
+ one: "{{ .WordCount }} woord"
+ other: "{{ .WordCount }} woorden"
+
+postsNewer:
+ other: Nieuwere posts
+
+postsOlder:
+ other: Oudere posts
+
+poweredBy:
+ other: >-
+ Gemaakt met <a href='http://www.gohugo.io/'>Hugo</a> Thema door <a
+ href='https://github.com/nodejh/hugo-theme-cactus-plus'>nodejh</a>
+
+publishDateShort:
+ other: >-
+ {{ .PublishDate.Day }} {{ index $.Site.Data.months_nl (printf "%d" .PublishDate.Month) }}
diff --git a/i18n/zh.yaml b/i18n/zh.yaml
new file mode 100644
index 0000000..803ca9f
--- /dev/null
+++ b/i18n/zh.yaml
@@ -0,0 +1,50 @@
+home:
+ other: 首页
+
+archive:
+ other: 归档
+
+tags:
+ other: 标签
+
+subscribe:
+ other: 订阅
+
+about:
+ other: 关于
+
+404title:
+ other: "404"
+
+404subtitle:
+ other: 页面不存在
+
+readMore:
+ other: 更多内容
+
+minuteRead:
+ other: "{{ .ReadingTime }}分钟"
+
+publishDate:
+ other: '{{ .PublishDate.Format "2006/01/02" }}'
+
+publishDateFull:
+ other: '{{ .PublishDate.Format "2006年01月02日" }}'
+
+wordCount:
+ one: "{{ .WordCount }}字"
+ other: "{{ .WordCount }}字"
+
+postsNewer:
+ other: 下一页
+
+postsOlder:
+ other: 上一页
+
+poweredBy:
+ other: >-
+ Powered by <a href='http://www.gohugo.io/'>Hugo</a> Theme By <a
+ href='https://github.com/nodejh/hugo-theme-cactus-plus'>nodejh</a>
+
+publishDateShort:
+ other: '{{ .PublishDate.Format "01/02" }}'
diff --git a/layouts/404.html b/layouts/404.html
index 2c108c0..ae1af4f 100644
--- a/layouts/404.html
+++ b/layouts/404.html
@@ -5,20 +5,20 @@
{{ with .Site.Params.title404 }}
<h1>{{ . }}</h1>
{{ else }}
- <h1>404 - Page Not Found</h1>
+ <h1>{{ i18n "404title" }}</h1>
{{ end }}
{{ with .Site.Params.subtitle404 }}
<div>{{ . }}</div>
{{ else }}
- <div>The content you're looking for doesn't seem to exist.</div>
+ <div>{{ i18n "404subtitle" }}</div>
{{ end }}
</div>
{{ with .Site.Params.readMore }}
<h2 class="read-more">{{ . }}</h2>
{{ else }}
- <h2 class="read-more">Read More</h2>
+ <h2 class="read-more">{{ i18n "readMore" }}</h2>
{{ end }}
diff --git a/layouts/_default/list.html b/layouts/_default/list.html
index 4fcce78..9e88396 100644
--- a/layouts/_default/list.html
+++ b/layouts/_default/list.html
@@ -11,7 +11,7 @@
{{ range .Pages }}
<div class="value">
<div class="date">
- {{ .Date.Format "Jan 2" }}
+ <time datetime="{{ .PublishDate }}">{{ i18n "publishDateShort" . }}</time>
</div>
<div class="title">
<a href="{{ .Permalink }}">
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index 22a559e..c4159a8 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -4,24 +4,18 @@
<h1 class="title">{{ .Title }}</h1>
<div class="tip">
- <span>
- {{ .Date.Format "Jan 2, 2006 15:04" }}
- </span>
+ <time datetime="{{ .PublishDate }}">{{ i18n "publishDateFull" . }}</time>
<span class="split">
·
</span>
<span>
- {{ if lt 1 .WordCount }}
- {{ .WordCount }} words
- {{ else }}
- {{ .WordCount }} word
- {{ end }}
+ {{ i18n "wordCount" . }}
</span>
<span class="split">
·
</span>
<span>
- {{ .ReadingTime }} minute read
+ {{ i18n "minuteRead" . }}
</span>
</div>
diff --git a/layouts/index.html b/layouts/index.html
index 2db56a3..d43a0cd 100644
--- a/layouts/index.html
+++ b/layouts/index.html
@@ -7,11 +7,12 @@
{{ range $paginator.Pages }}
{{ $title := .Title }}
{{ $summary := .Summary }}
- {{ $date := dateFormat "Jan 2, 2006" .Date }}
<section class="item">
<div>
- <h1 class="title"><a href='{{ .RelPermalink }}'>{{ $title }}</a></h1>
- <div class="date">{{ $date }}</div>
+ <h1 class="title"><a href='{{ .RelPermalink }}'>{{ $title }}</a></h1>
+ <div class ="date">
+ <time datetime="{{ .PublishDate }}">{{ i18n "publishDate" . }}</time>
+ </div>
</div>
{{ if ne .Site.Params.hiddenPostSummaryInHomePage true }}
@@ -26,7 +27,7 @@
{{ if $paginator.HasPrev }}
<span class="prev">
<a href="{{.Paginator.Prev.URL}}">
- <span class="arrow">←</span> {{ with .Site.Params.newerPosts }}{{ . }}{{ else }}Newer Posts{{ end }}
+ <span class="arrow">←</span> {{ with .Site.Params.newerPosts }}{{ . }}{{ else }}{{ i18n "postsNewer" }}{{ end }}
</a>
</span>
{{ end }}
@@ -34,7 +35,7 @@
{{ if $paginator.HasNext }}
<span class="next">
<a href="{{.Paginator.Next.URL}}">
- {{ with .Site.Params.olderPosts }}{{ . }}{{ else }}Older Posts{{ end }} <span class="arrow">→</span>
+ {{ with .Site.Params.olderPosts }}{{ . }}{{ else }}{{ i18n "postsOlder" }}{{ end }} <span class="arrow">→</span>
</a>
</span>
{{ end }}
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html
index 833c955..27a7518 100644
--- a/layouts/partials/footer.html
+++ b/layouts/partials/footer.html
@@ -18,7 +18,7 @@
{{ if ne .Site.Params.showPowerBy false }}
<div class="powerby">
- Powered by <a href="http://www.gohugo.io/">Hugo</a> Theme By <a href="https://github.com/nodejh/hugo-theme-cactus-plus">nodejh</a>
+ {{ i18n "poweredBy" | safeHTML }}
</div>
{{ end }}
</footer>
diff --git a/layouts/partials/navigation.html b/layouts/partials/navigation.html
index 72f44f3..c96fc49 100644
--- a/layouts/partials/navigation.html
+++ b/layouts/partials/navigation.html
@@ -1,16 +1,16 @@
<nav class="navigation">
{{ if not .IsHome }}
- <a href="{{ "/" | relURL }}"> <span class="arrow">←</span>{{ with .Site.Params.home }}{{ . }}{{ else }}Home{{ end }}</a>
+ <a href="{{ "/" | relURL }}"> <span class="arrow">←</span>{{ with .Site.Params.home }}{{ . }}{{ else }}{{ i18n "home" }}{{ end }}</a>
{{ end }}
- <a href="{{ "/posts" | relURL }}">{{ with .Site.Params.archive }}{{ . }}{{ else }}Archive{{ end }}</a>
- <a href="{{ "/tags" | relURL }}">{{ with .Site.Params.tags }}{{ . }}{{ else }}Tags{{ end }}</a>
- <a href="{{ "/about" | relURL }}">{{ with .Site.Params.about }}{{ . }}{{ else }}About{{ end }}</a>
+ <a href="{{ "/posts" | relURL }}">{{ with .Site.Params.archive }}{{ . }}{{ else }}{{ i18n "archive" }}{{ end }}</a>
+ <a href="{{ "/tags" | relURL }}">{{ with .Site.Params.tags }}{{ . }}{{ else }}{{ i18n "tags" }}{{ end }}</a>
+ <a href="{{ "/about" | relURL }}">{{ with .Site.Params.about }}{{ . }}{{ else }}{{ i18n "about" }}{{ end }}</a>
{{ range $element := .Site.Params.Links }}
<a href="{{ $element.path }}">{{ $element.name }}</a>
{{ end }}
{{ if .Site.Params.enableRSS }}
- <a class="button" href="{{ .Site.RSSLink }}">{{ with .Site.Params.subscribe }}{{ . }}{{ else }}Subscribe{{ end }}</a>
+ <a class="button" href="{{ .Site.RSSLink }}">{{ with .Site.Params.subscribe }}{{ . }}{{ else }}{{ i18n "subscribe" }}{{ end }}</a>
{{ end }}
</nav>
diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html
index 4f20f04..9490e59 100644
--- a/layouts/partials/toc.html
+++ b/layouts/partials/toc.html
@@ -1,10 +1,14 @@
-<aside class="toc">
- <details>
- <summary>
- {{- i18n "toc" | default "Table of Contents" }}
- </summary>
- <div>
- {{ .TableOfContents }}
- </div>
- </details>
-</aside> \ No newline at end of file
+{{ with .TableOfContents }}
+ {{ if ne . "<nav id=\"TableOfContents\"></nav>" }}
+ <aside class="toc">
+ <details>
+ <summary>
+ {{- i18n "toc" | default "Table of Contents" }}
+ </summary>
+ <div>
+ {{ . }}
+ </div>
+ </details>
+ </aside>
+ {{ end }}
+{{ end }}
diff --git a/static/css/style.css b/static/css/style.css
index 9c05c65..b27930a 100644
--- a/static/css/style.css
+++ b/static/css/style.css
@@ -427,7 +427,7 @@ nav.navigation a.button {
#archive .group .value .date {
display: inline-block;
color: #999;
- width: 60px;
+ min-width: 60px;
}
#archive .group .value .title {
display: inline;