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:
authornodejh <jianghangscu@gmail.com>2021-08-21 18:03:38 +0300
committernodejh <jianghangscu@gmail.com>2021-08-21 18:03:38 +0300
commit0912af8649dd51cc20f7cacc91ac02689c454ea8 (patch)
tree36f729963eca0dbad299cf656782f179cd8bcda5
parent3cbfc0e484f2ba067826ee2a2d018da8d300745f (diff)
feat: support multiple languages
-rw-r--r--README-zh_CN.md17
-rw-r--r--README.md26
-rw-r--r--exampleSite/config-example.yaml2
-rw-r--r--exampleSite/config.yaml24
-rw-r--r--i18n/en.toml29
-rw-r--r--i18n/en.yaml50
-rw-r--r--i18n/nl.toml29
-rw-r--r--i18n/nl.yaml53
-rw-r--r--i18n/zh.yaml50
-rw-r--r--layouts/404.html2
-rw-r--r--layouts/_default/list.html2
-rw-r--r--layouts/_default/single.html10
-rw-r--r--layouts/index.html6
-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, 229 insertions, 109 deletions
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/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.toml b/i18n/en.toml
deleted file mode 100644
index 1d85e12..0000000
--- a/i18n/en.toml
+++ /dev/null
@@ -1,29 +0,0 @@
-[404title]
-other = "404 - Page Not Found"
-
-[404subtitle]
-other = "The content you're looking for doesn't seem to exist."
-
-[minuteread]
-other = "minute read"
-
-[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>"
-
-[publishdate]
-other = "{{ .PublishDate.Format \"January 2, 2006\" }}"
-
-[readmore]
-other = "Read more"
-
-[word]
-other = "word"
-
-[words]
-other = "words"
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.toml b/i18n/nl.toml
deleted file mode 100644
index f732934..0000000
--- a/i18n/nl.toml
+++ /dev/null
@@ -1,29 +0,0 @@
-[404title]
-other = "404 - Pagina Niet Gevonden"
-
-[404subtitle]
-other = "De pagina waar u naar op zoek bent, lijkt niet te bestaan."
-
-[minuteread]
-other = "minuten leestijd"
-
-[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>"
-
-[publishdate]
-other = "{{ .PublishDate.Day }} {{ index $.Site.Data.months_nl (printf \"%d\" .PublishDate.Month) }} {{ .PublishDate.Year }}"
-
-[readmore]
-other = "Lees meer"
-
-[word]
-other = "woord"
-
-[words]
-other = "woorden"
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 f4efc76..ae1af4f 100644
--- a/layouts/404.html
+++ b/layouts/404.html
@@ -18,7 +18,7 @@
{{ with .Site.Params.readMore }}
<h2 class="read-more">{{ . }}</h2>
{{ else }}
- <h2 class="read-more">{{ i18n "readmore" }}</h2>
+ <h2 class="read-more">{{ i18n "readMore" }}</h2>
{{ end }}
diff --git a/layouts/_default/list.html b/layouts/_default/list.html
index 601e2ca..9e88396 100644
--- a/layouts/_default/list.html
+++ b/layouts/_default/list.html
@@ -11,7 +11,7 @@
{{ range .Pages }}
<div class="value">
<div class="date">
- <time datetime="{{ .PublishDate }}">{{ i18n "publishdate" . }}</time>
+ <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 b6b48b7..c4159a8 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -4,22 +4,18 @@
<h1 class="title">{{ .Title }}</h1>
<div class="tip">
- <time datetime="{{ .PublishDate }}">{{ i18n "publishdate" . }}</time>
+ <time datetime="{{ .PublishDate }}">{{ i18n "publishDateFull" . }}</time>
<span class="split">
·
</span>
<span>
- {{ if lt 1 .WordCount }}
- {{ .WordCount }} {{ i18n "words" }}
- {{ else }}
- {{ .WordCount }} {{ i18n "word" }}
- {{ end }}
+ {{ i18n "wordCount" . }}
</span>
<span class="split">
·
</span>
<span>
- {{ .ReadingTime }} {{ i18n "minuteread" }}
+ {{ i18n "minuteRead" . }}
</span>
</div>
diff --git a/layouts/index.html b/layouts/index.html
index 84fe663..d43a0cd 100644
--- a/layouts/index.html
+++ b/layouts/index.html
@@ -11,7 +11,7 @@
<div>
<h1 class="title"><a href='{{ .RelPermalink }}'>{{ $title }}</a></h1>
<div class ="date">
- <time datetime="{{ .PublishDate }}">{{ i18n "publishdate" . }}</time>
+ <time datetime="{{ .PublishDate }}">{{ i18n "publishDate" . }}</time>
</div>
</div>
@@ -27,7 +27,7 @@
{{ if $paginator.HasPrev }}
<span class="prev">
<a href="{{.Paginator.Prev.URL}}">
- <span class="arrow">←</span> {{ with .Site.Params.newerPosts }}{{ . }}{{ else }}{{ i18n "postsnewer" }}{{ end }}
+ <span class="arrow">←</span> {{ with .Site.Params.newerPosts }}{{ . }}{{ else }}{{ i18n "postsNewer" }}{{ end }}
</a>
</span>
{{ end }}
@@ -35,7 +35,7 @@
{{ if $paginator.HasNext }}
<span class="next">
<a href="{{.Paginator.Next.URL}}">
- {{ with .Site.Params.olderPosts }}{{ . }}{{ else }}{{ i18n "postsnewer" }}{{ 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 c643729..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">
- {{ i18n "poweredby" | safeHTML }}
+ {{ 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;