feat: add multilingual mode support (#241)

BREAKING CHANGE:  Layout file renamed ´layouts/partials/page-footer.html → layouts/partials/menu-nextprev.html`. If you use overrides, you might need to change the filenames as well.
This commit is contained in:
Robert Kaussow 2022-01-23 13:21:44 +01:00 committed by GitHub
parent 42ebf067bb
commit 5c22ce57dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
88 changed files with 437 additions and 144 deletions

View File

@ -29,3 +29,4 @@ KaTeX
katex
Theming
Favicon[s]?
UI

4
.gitignore vendored
View File

@ -7,8 +7,12 @@
/lhci_reports/
/exampleSite/themes/
/exampleSite/public/
/exampleSite/config/development/
CHANGELOG.md
# translation envs
exampleSite/content/de
# auto-generated files
/data/
/static/

View File

@ -2,11 +2,14 @@
baseURL: https://geekdocs.de/
title: Geekdocs
theme: hugo-geekdoc
pygmentsUseClasses: true
pygmentsCodeFences: true
timeout: 180000
pluralizeListTitles: false
defaultContentLanguage: en
disablePathToLower: true
enableGitInfo: true
@ -34,19 +37,3 @@ outputs:
- HTML
term:
- HTML
params:
geekdocToC: 3
geekdocTagsToMenu: true
geekdocRepo: https://github.com/thegeeklab/hugo-geekdoc
geekdocEditPath: edit/main/exampleSite/content
geekdocSearch: true
geekdocSearchShowParent: true
geekdocLegalNotice: https://thegeeklab.de/legal-notice/#contact-information
geekdocPrivacyPolicy: https://thegeeklab.de/legal-notice/#privacy-policy
geekdocImageLazyLoading: true
geekdocDarkModeDim: true

View File

@ -0,0 +1,5 @@
---
en:
languageName: "English"
contentDir: "content/en"
weight: 10

View File

@ -0,0 +1,15 @@
---
geekdocToC: 3
geekdocTagsToMenu: true
geekdocRepo: https://github.com/thegeeklab/hugo-geekdoc
geekdocEditPath: edit/main/exampleSite/content
geekdocSearch: true
geekdocSearchShowParent: true
geekdocLegalNotice: https://thegeeklab.de/legal-notice/#contact-information
geekdocPrivacyPolicy: https://thegeeklab.de/legal-notice/#privacy-policy
geekdocImageLazyLoading: true
geekdocDarkModeDim: true

View File

Before

Width:  |  Height:  |  Size: 462 KiB

After

Width:  |  Height:  |  Size: 462 KiB

View File

@ -0,0 +1,78 @@
---
title: Multilingual
resources:
- name: translation-available
src: images/translation-available.png
title: ""
---
{{< toc >}}
Hugo supports the creation of websites with multiple languages. In this post we will explain how to get configure Multilingual Mode with this theme.
## Configuration
### Languages
You need to set a default language and configure at least two different languages used by your site to your configuration file at `config.toml`:
```Toml
defaultContentLanguage = "en"
[languages.en]
languageName = "English"
contentDir = "content/en"
weight = 10
[languages.de]
languageName = "German"
contentDir = "content/de"
weight = 20
```
### Translation Strings
To customize translation strings used by the theme you can create a file `i18n/<languagecode>.toml` for every language you want to use e.g. `i18n/en.toml`. You can lookup all used strings in the [default](https://github.com/thegeeklab/hugo-geekdoc/blob/main/i18n/en.yaml) translation file.
### Menus
For the [Bundle Menu](/usage/menus/#bundle-menu) as well as for the [Extra Header Menu](/usage/menus/#extra-header-menu) you can translate the name within the data file of the menu:
```YAML
---
more:
# If `name` is a text, this text will be used as name for each language.
- name: News
ref: "/#"
icon: "gdoc_notification"
# To translate the name you can add a sub-item per language. Important: If you miss a language key
# that is configured in the languages list of your `config.toml` the name will be empty for this language!
- name:
en: Releases
de: Veröffentlichung
ref: "https://github.com/thegeeklab/hugo-geekdoc/releases"
external: true
icon: "gdoc_download"
```
## Add Content
To translate your content you need to create a directory `content/<languagecode>/` for each language you want to use e.g. `content/en/`. This language directories will hold the translated pages for the particular language.
## Switch Content
If you have configured at least two different languages, the language switcher will be enabled in the UI automatically. The switcher is as part of the header menu and displayed on all pages.
{{< columns >}}
[![Beach Color Palette](images/translation-available.png)](images/translation-available.png)
On pages for which a translation is available it will be displayed in the selection list and links to the translated page.
<--->
[![Beach Color Palette](images/translation-not-available.png)](images/translation-not-available.png)
Pages without a translation will be displayed in the selection list as well but are marked with an asterisk and link to the start page of the respective language.
{{< /columns >}}

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View File

Before

Width:  |  Height:  |  Size: 321 KiB

After

Width:  |  Height:  |  Size: 321 KiB

View File

@ -6,17 +6,17 @@ The Columns shortcode can be used to organize content side-by-side (horizontally
```html
{{</* columns */>}} <!-- begin columns block -->
# Left Content
## Left Content
Dolor sit, sumo unique argument um no ...
<---> <!-- magic separator, between columns -->
# Mid Content
## Mid Content
Dolor sit, sumo unique argument um no ...
<---> <!-- magic separator, between columns -->
# Right Content
## Right Content
Dolor sit, sumo unique argument um no ...
{{</* /columns */>}}
```

View File

Before

Width:  |  Height:  |  Size: 715 KiB

After

Width:  |  Height:  |  Size: 715 KiB

View File

Before

Width:  |  Height:  |  Size: 463 KiB

After

Width:  |  Height:  |  Size: 463 KiB

View File

Before

Width:  |  Height:  |  Size: 484 KiB

After

Width:  |  Height:  |  Size: 484 KiB

View File

Before

Width:  |  Height:  |  Size: 472 KiB

After

Width:  |  Height:  |  Size: 472 KiB

View File

Before

Width:  |  Height:  |  Size: 406 KiB

After

Width:  |  Height:  |  Size: 406 KiB

View File

Before

Width:  |  Height:  |  Size: 415 KiB

After

Width:  |  Height:  |  Size: 415 KiB

View File

Before

Width:  |  Height:  |  Size: 183 KiB

After

Width:  |  Height:  |  Size: 183 KiB

View File

@ -49,14 +49,14 @@ This method can be used to include source code files and keep them automatically
<!-- prettier-ignore -->
```tpl
{{</* include file="config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100" */>}}
{{</* include file="config/_default/config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100" */>}}
```
Result:
<!-- prettier-ignore-start -->
<!-- spellchecker-disable -->
{{< include file="config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100" >}}
{{< include file="config/_default/config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100" >}}
<!-- spellchecker-enable -->
<!-- prettier-ignore-end -->

View File

@ -61,11 +61,11 @@ enableRobotsTXT = true
# You can also specify this parameter per page in front matter.
geekdocBreadcrumb = false
# (Optional, default none) Set source repository location. Used for 'Edit this page' links.
# (Optional, default none) Set source repository location. Used for 'Edit page' links.
# You can also specify this parameter per page in front matter.
geekdocRepo = "https://github.com/thegeeklab/hugo"
# (Optional, default none) Enable 'Edit this page' links. Requires 'GeekdocRepo' param
# (Optional, default none) Enable 'Edit page' links. Requires 'GeekdocRepo' param
# and path must point to 'content' directory of repo.
# You can also specify this parameter per page in front matter.
geekdocEditPath = "edit/main/exampleSite/content"
@ -174,11 +174,11 @@ params:
# You can also specify this parameter per page in front matter.
geekdocBreadcrumb: false
# (Optional, default none) Set source repository location. Used for 'Edit this page' links.
# (Optional, default none) Set source repository location. Used for 'Edit page' links.
# You can also specify this parameter per page in front matter.
geekdocRepo: "https://github.com/thegeeklab/hugo-geekdoc"
# (Optional, default none) Enable "Edit this page" links. Requires 'GeekdocRepo' param
# (Optional, default none) Enable "Edit page" links. Requires 'GeekdocRepo' param
# and path must point to 'content' directory of repo.
# You can also specify this parameter per page in front matter.
geekdocEditPath: edit/main/exampleSite/content
@ -262,11 +262,11 @@ geekdocBreadcrumb = false
# Set source repository location.
geekdocRepo = "https://github.com/thegeeklab/hugo-geekdoc"
# Enable "Edit this page" links. Requires 'GeekdocRepo' param and path must point
# Enable "Edit page" links. Requires 'GeekdocRepo' param and path must point
# to 'content' directory of repo.
geekdocEditPath = "edit/main/exampleSite/content"
# Used for 'Edit this page' link, set to '.File.Path' by default.
# Used for 'Edit page' link, set to '.File.Path' by default.
# Can be overwritten by a path relative to 'geekdocEditPath'
geekdocFilePath =
@ -322,11 +322,11 @@ geekdocBreadcrumb: false
# Set source repository location.
geekdocRepo: "https://github.com/thegeeklab/hugo-geekdoc"
# Enable "Edit this page" links. Requires 'GeekdocRepo' param and path must point
# Enable "Edit page" links. Requires 'GeekdocRepo' param and path must point
# to 'content' directory of repo.
geekdocEditPath: "edit/main/exampleSite/content"
# Used for 'Edit this page' link, set to '.File.Path' by default.
# Used for 'Edit page' link, set to '.File.Path' by default.
# Can be overwritten by a path relative to 'geekdocEditPath'
geekdocFilePath:

View File

@ -33,7 +33,7 @@ content/
## Bundle menu
This type of navigation needs to be enabled first by setting `geekdocMenuBundle` to `true` in your [site configuration](/usage/configuration/#site-configuration). After you have activated the bundle menu, you start with an empty navigation. This is intentional because bundle menus have to be defined manually in a data file. While this increases the effort it also offers maximum flexibility in the design. The data file needs to be written in YAML and placed at `data/menu/main.yml`.
This type of navigation needs to be enabled first by setting `geekdocMenuBundle` to `true` in your [site configuration](/usage/configuration/#site-configuration). After you have activated the bundle menu, you start with an empty navigation. This is intentional because bundle menus have to be defined manually in a data file. While this increases the effort it also offers maximum flexibility in the design. The data file needs to be written in YAML and placed at `data/menu/main.yaml`.
**Example:**
@ -73,7 +73,7 @@ As an advantage you can add [icons](/features/icon-sets/) to your menu entries e
The more menu is special type of the bundle menu and can be combined with the default file-tree menu.
{{< /hint >}}
As this is a special type of the bundle menu it is basically working in the same way. To enable it just add a data file to `data/menu/more.yml`. The more menu will also work with the file-tree menu and therefor **don't need to be enabled** by the `geekdocMenuBundle` parameter.
As this is a special type of the bundle menu it is basically working in the same way. To enable it just add a data file to `data/menu/more.yaml`. The more menu will also work with the file-tree menu and therefor **don't need to be enabled** by the `geekdocMenuBundle` parameter.
**Example:**
@ -97,7 +97,7 @@ more:
## Extra Header Menu
If you want to customize the header menu, this can be achieved by using a data file written in YAML and placed at `data/menu/extra.yml`.
If you want to customize the header menu, this can be achieved by using a data file written in YAML and placed at `data/menu/extra.yaml`.
**Example:**

View File

@ -7,7 +7,7 @@ more:
ref: "https://github.com/thegeeklab/hugo-geekdoc/releases"
external: true
icon: "gdoc_download"
- name: "View Source"
- name: View Source
ref: "https://github.com/thegeeklab/hugo-geekdoc"
external: true
icon: "gdoc_github"

39
i18n/de.yaml Normal file
View File

@ -0,0 +1,39 @@
---
edit_page: Seite bearbeiten
nav_navigation: Navigation
nav_tags: Tags
nav_more: Weitere
nav_top: Nach oben
form_placeholder_search: Suchen
error_page_title: Verlaufen? Keine Sorge
error_message_title: Verlaufen?
error_message_code: Fehler 404
error_message_text: >
Wir können die Seite nach der Du gesucht hast leider nicht finden. Keine Sorge,
wir bringen Dich zurück zur <a class="gdoc-error__link" href="{{ . }}">Startseite</a>.
button_toggle_dark: Wechsel zwischen Dunkel/Hell/Auto Modus
button_nav_open: Navigation öffnen
button_nav_close: Navigation schließen
button_menu_open: Menüband öffnen
button_menu_close: Menüband schließen
button_homepage: Zurück zur Startseite
title_anchor_prefix: "Link zu:"
posts_read_more: Ganzen Artikel lesen
posts_read_time:
one: "Eine Minute Lesedauer"
other: "{{ . }} Minuten Lesedauer"
posts_update_prefix: Aktualisiert am
footer_build_with: >
Entwickelt mit <a href="https://gohugo.io/" class="gdoc-footer__link">Hugo</a> und
<svg class="icon gdoc_heart"><use xlink:href="#gdoc_heart"></use></svg>
footer_legal_notice: Impressum
footer_privacy_policy: Datenschutzerklärung
language_switch_no_tranlation_prefix: "Seite nicht übersetzt:"

39
i18n/en.yaml Normal file
View File

@ -0,0 +1,39 @@
---
edit_page: Edit page
nav_navigation: Navigation
nav_tags: Tags
nav_more: More
nav_top: Back to top
form_placeholder_search: Search
error_page_title: Lost? Don't worry
error_message_title: Lost?
error_message_code: Error 404
error_message_text: >
Seems like what you are looking for can't be found. Don't worry, we can
bring you back to the <a class="gdoc-error__link" href="{{ . }}">homepage</a>.
button_toggle_dark: Toggle Dark/Light/Auto mode
button_nav_open: Open Navigation
button_nav_close: Close Navigation
button_menu_open: Open Menu Bar
button_menu_close: Close Menu Bar
button_homepage: Back to homepage
title_anchor_prefix: "Anchor to:"
posts_read_more: Read full post
posts_read_time:
one: "One minute to read"
other: "{{ . }} minutes to read"
posts_update_prefix: Updated on
footer_build_with: >
Built with <a href="https://gohugo.io/" class="gdoc-footer__link">Hugo</a> and
<svg class="icon gdoc_heart"><use xlink:href="#gdoc_heart"></use></svg>
footer_legal_notice: Legal Notice
footer_privacy_policy: Privacy Policy
language_switch_no_tranlation_prefix: "Page not translated:"

View File

@ -2,7 +2,7 @@
<html lang="{{ .Site.Language.Lang }}">
<head>
{{ partial "head/meta" . }}
<title>Lost? Don't worry</title>
<title>{{ i18n "error_page_title" }}</title>
{{ partial "head/favicons" . }}
{{ partial "head/others" . }}
@ -14,6 +14,7 @@
<div class="wrapper">
<input type="checkbox" class="hidden" id="menu-header-control" />
{{ partial "site-header" (dict "Root" . "MenuEnabled" false) }}
@ -23,11 +24,10 @@
<svg class="icon gdoc_cloud_off"><use xlink:href="#gdoc_cloud_off"></use></svg>
</div>
<div class="gdoc-error__message">
<div class="gdoc-error__line gdoc-error__title">Lost?</div>
<div class="gdoc-error__line gdoc-error__code">Error 404</div>
<div class="gdoc-error__line gdoc-error__title">{{ i18n "error_message_title" }}</div>
<div class="gdoc-error__line gdoc-error__code">{{ i18n "error_message_code" }}</div>
<div class="gdoc-error__line gdoc-error__help">
Seems like what you are looking for can't be found. Don't worry we can bring you back
to the <a class="gdoc-error__link" href="{{ .Site.BaseURL }}">homepage</a>.
{{ i18n "error_message_text" .Site.BaseURL | safeHTML }}
</div>
</div>
</div>

View File

@ -6,7 +6,7 @@
<div class="gdoc-page__anchorwrap">
<h{{ .Level }} id="{{ .Anchor | safeURL }}">
{{ .Text | safeHTML }}
<a data-clipboard-text="{{ .Page.Permalink }}#{{ .Anchor | safeURL }}" class="gdoc-page__anchor gdoc-page__anchor--right clip" aria-label="Anchor {{ .Text | safeHTML }}" href="#{{ .Anchor | safeURL }}">
<a data-clipboard-text="{{ .Page.Permalink }}#{{ .Anchor | safeURL }}" class="gdoc-page__anchor gdoc-page__anchor--right clip" title="{{ i18n "title_anchor_prefix" }} {{ .Text | safeHTML }}" aria-label="{{ i18n "title_anchor_prefix" }} {{ .Text | safeHTML }}" href="#{{ .Anchor | safeURL }}">
<svg class="icon gdoc_link"><use xlink:href="#gdoc_link"></use></svg>
</a>
</h{{ .Level }}>

View File

@ -39,7 +39,11 @@
<div class="gdoc-page">
{{ template "main" . }}
{{ partial "page-footer" . }}
<div class="gdoc-page__footer flex flex-wrap justify-between">
{{ partial "menu-nextprev" . }}
</div>
</div>
</main>

View File

@ -1,5 +1,6 @@
{{ if default true .Site.Params.GeekdocSearch }}
<script defer src="{{ index (index .Site.Data.assets "search.js") "src" | relURL }}"></script>
{{- $searchConfig := resources.Get "search/config.json" | resources.ExecuteAsTemplate "search/config.json" . | resources.Minify -}}
{{- $searchConfigFile := printf "search/%s.config.json" .Language.Lang -}}
{{- $searchConfig := resources.Get "search/config.json" | resources.ExecuteAsTemplate $searchConfigFile . | resources.Minify -}}
{{- $searchConfig.Publish -}}
{{ end }}

View File

@ -0,0 +1,51 @@
{{ if .Site.IsMultiLingual }}
<span class="gdoc-language">
<ul class="gdoc-language__selector" role="button" aria-pressed="false" tabindex="0">
<li>
{{ range .Site.Languages }}
{{ if eq . $.Site.Language }}
<span class="flex align-center">
<svg class="icon gdoc_language"><use xlink:href="#gdoc_language"></use></svg>
<span>{{ .Lang | upper }}</span>
</span>
{{ end }}
{{ end }}
<ul class="gdoc-language__list">
{{ if $.Translations }}
{{ range $.Translations }}
<li>
<a
class="flex gdoc-language__entry"
title="{{ .Language.LanguageName }}"
href="{{ .RelPermalink }}"
hreflang="{{ .Lang }}"
lang="{{ .Lang }}"
>
{{ .Language.LanguageName }}
</a>
</li>
{{ end }}
{{ else }}
{{ range .Site.Languages -}}
{{ if ne $.Site.Language.Lang .Lang }}
<li>
<a
class="flex gdoc-language__entry"
title="{{ i18n "language_switch_no_tranlation_prefix" }} {{ .LanguageName }}"
href="{{ .Lang | relLangURL }}"
hreflang="{{ .Lang }}"
lang="{{ .Lang }}"
>
{{ .LanguageName }}*
</a>
</li>
{{ end -}}
{{ end -}}
{{ end }}
</ul>
</li>
</ul>
</span>
{{ end }}

View File

@ -27,6 +27,13 @@
{{ $id := substr (sha1 $this.Permalink) 0 8 }}
{{ $doCollapse := and (isset . "sub") (or $this.Params.GeekdocCollapseSection (default false .Site.Params.GeekdocCollapseAllSections)) }}
{{ if reflect.IsMap .name }}
{{ $current.Scratch.Set "refName" (index .name $site.Language.Lang) }}
{{ else }}
{{ $current.Scratch.Set "refName" .name }}
{{ end }}
{{ $name := $current.Scratch.Get "refName" }}
<input
type="checkbox"
@ -56,20 +63,20 @@
{{ if $isCurrent }}is-active{{ end }}
{{ end }}"
>
{{ .name }}
{{ $name }}
</a>
</span>
{{ if $doCollapse }}
<svg class="icon gdoc_keyborad_arrow_left">
<svg class="icon toggle gdoc_keyborad_arrow_left">
<use xlink:href="#gdoc_keyborad_arrow_left"></use>
</svg>
<svg class="icon gdoc_keyborad_arrow_down hidden">
<svg class="icon toggle gdoc_keyborad_arrow_down hidden">
<use xlink:href="#gdoc_keyborad_arrow_down"></use>
</svg>
{{ end }}
</label>
{{ else }}
<span class="flex">{{ .name }}</span>
<span class="flex">{{ $name }}</span>
{{ end }}
{{ with .sub }}

View File

@ -15,8 +15,15 @@
{{ $isCurrent := eq $current $this }}
{{ $icon := default false .icon }}
{{ if reflect.IsMap .name }}
{{ $current.Scratch.Set "refName" (index .name $site.Language.Lang) }}
{{ else }}
{{ $current.Scratch.Set "refName" .name }}
{{ end }}
{{ $name := $current.Scratch.Get "refName" }}
{{ if not .icon }}
{{ errorf "Missing 'icon' attribute in data file for '%s' menu item '%s'" $target .name }}
{{ errorf "Missing 'icon' attribute in data file for '%s' menu item '%s'" $target $name }}
{{ end }}
{{ if eq $target "header" }}
@ -30,7 +37,7 @@
class="gdoc-header__link"
>
<svg class="icon {{ .icon }}">
<title>{{ .name }}</title>
<title>{{ $name }}</title>
<use xlink:href="#{{ .icon }}"></use>
</svg>
</a>

View File

@ -77,10 +77,10 @@
<span class="flex">{{ partial "title" . }}</span>
{{ end }}
{{ if $doCollapse }}
<svg class="icon gdoc_keyborad_arrow_left">
<svg class="icon toggle gdoc_keyborad_arrow_left">
<use xlink:href="#gdoc_keyborad_arrow_left"></use>
</svg>
<svg class="icon gdoc_keyborad_arrow_down">
<svg class="icon toggle gdoc_keyborad_arrow_down">
<use xlink:href="#gdoc_keyborad_arrow_down"></use>
</svg>
{{ end }}

View File

@ -22,8 +22,15 @@
{{ $this := $site.GetPage .ref }}
{{ $current := $current.Scratch.Get "current" }}
{{ if reflect.IsMap .name }}
{{ $current.Scratch.Set "refName" (index .name $site.Language.Lang) }}
{{ else }}
{{ $current.Scratch.Set "refName" .name }}
{{ end }}
{{ $name := $current.Scratch.Get "refName" }}
{{ if $current.Scratch.Get "getNext" }}
{{ $current.Scratch.Set "nextPage" (dict "name" .name "this" $this) }}
{{ $current.Scratch.Set "nextPage" (dict "name" $name "this" $this) }}
{{ $current.Scratch.Set "getNext" false }}
{{ end }}
@ -32,7 +39,7 @@
{{ $current.Scratch.Set "getNext" true }}
{{ end }}
{{ $current.Scratch.Set "prev" (dict "name" .name "this" $this) }}
{{ $current.Scratch.Set "prev" (dict "name" $name "this" $this) }}
{{ end }}
{{ $sub := default false .sub }}
@ -42,10 +49,8 @@
{{ end }}
{{ end }}
<div class="gdoc-page__footer flex flex-wrap justify-between">
{{ $showPrevNext := (and (default true .Site.Params.GeekdocNextPrev) .Site.Params.GeekdocMenuBundle) }}
{{ if $showPrevNext }}
{{ $showPrevNext := (and (default true .Site.Params.GeekdocNextPrev) .Site.Params.GeekdocMenuBundle) }}
{{ if $showPrevNext }}
<span class="gdoc-page__nav">
{{ with ($current.Scratch.Get "prevPage") }}
<a
@ -70,5 +75,4 @@
</a>
{{ end }}
</span>
{{ end }}
</div>
{{ end }}

View File

@ -3,7 +3,7 @@
<section class="gdoc-nav--main">
<h2>Navigation</h2>
<h2>{{ i18n "nav_navigation" }}</h2>
{{ if .Site.Params.GeekdocMenuBundle }}
{{ partial "menu-bundle" (dict "current" . "source" .Site.Data.menu.main.main) }}
{{ else }}
@ -13,7 +13,7 @@
{{ if and (in (slice "posts" "tags") .Section) (default false .Site.Params.GeekdocTagsToMenu) }}
<section class="gdoc-nav--tags">
<h2>Tags</h2>
<h2>{{ i18n "nav_tags" }}</h2>
<ul class="gdoc-nav__list">
{{ $currentPage := .RelPermalink }}
{{ range $name, $taxonomy := .Site.Taxonomies.tags }}
@ -35,7 +35,7 @@
<section class="gdoc-nav--more">
{{ if .Site.Data.menu.more.more }}
<h2>More</h2>
<h2>{{ i18n "nav_more" }}</h2>
{{ partial "menu-bundle" (dict "current" . "source" .Site.Data.menu.more.more) }}
{{ end }}
</section>

View File

@ -49,7 +49,7 @@
<a
href="{{ $geekdocRepo }}/{{ path.Join $geekdocEditPath ($.Scratch.Get "geekdocFilePath") }}"
>
Edit this page
{{ i18n "edit_page" }}
</a>
</span>
</div>

View File

@ -3,7 +3,7 @@
<span class="gdoc-post__tag">
<time datetime="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}">
{{ if .Lastmod.After (.Date.AddDate 0 0 1) }}
Updated on
{{ i18n "posts_update_prefix" }}
{{ end }}
{{ .Lastmod.Format "Jan 2, 2006" }}
</time>
@ -12,7 +12,7 @@
<span class="no-wrap">
<svg class="icon gdoc_timer"><use xlink:href="#gdoc_timer"></use></svg>
<span class="gdoc-post__tag">{{ .ReadingTime }} min read</span>
<span class="gdoc-post__tag">{{ i18n "posts_read_time" .ReadingTime }}</span>
</span>
{{ $tc := 0 }}

View File

@ -5,10 +5,11 @@
type="text"
id="gdoc-search-input"
class="gdoc-search__input"
placeholder="Search..."
aria-label="Search"
placeholder="{{ i18n "form_placeholder_search" }}"
aria-label="{{ i18n "form_placeholder_search" }}"
maxlength="64"
data-site-base-url="{{ .Site.BaseURL }}"
data-site-lang="{{ .Site.Language.Lang }}"
/>
<div class="gdoc-search__spinner spinner hidden"></div>
<ul id="gdoc-search-results" class="gdoc-search__list"></ul>

View File

@ -2,28 +2,31 @@
<div class="container flex">
<div class="flex flex-wrap">
<span class="gdoc-footer__item gdoc-footer__item--row">
Built with <a href="https://gohugo.io/" class="gdoc-footer__link">Hugo</a> and
<svg class="icon gdoc_heart"><use xlink:href="#gdoc_heart"></use></svg>
{{ i18n "footer_build_with" | safeHTML }}
</span>
{{ with .Site.Params.GeekdocLegalNotice }}
<span class="gdoc-footer__item gdoc-footer__item--row">
<a href="{{ . | relURL }}" class="gdoc-footer__link">Legal Notice</a>
<a href="{{ . | relURL }}" class="gdoc-footer__link">
{{ i18n "footer_legal_notice" }}
</a>
</span>
{{ end }}
{{ with .Site.Params.GeekdocPrivacyPolicy }}
<span class="gdoc-footer__item gdoc-footer__item--row">
<a href="{{ . | relURL }}" class="gdoc-footer__link">Privacy Policy</a>
<a href="{{ . | relURL }}" class="gdoc-footer__link">
{{ i18n "footer_privacy_policy" }}
</a>
</span>
{{ end }}
</div>
{{ if (default true .Site.Params.GeekdocBackToTop) }}
<div class="flex flex-25 justify-end">
<span class="gdoc-footer__item text-right">
<a class="gdoc-footer__link fake-link" href="#" aria-label="Back to top">
<a class="gdoc-footer__link fake-link" href="#" aria-label="{{ i18n "nav_top" }}">
<svg class="icon gdoc_keyborad_arrow_up">
<use xlink:href="#gdoc_keyborad_arrow_up"></use>
</svg>
<span class="hidden-mobile">Back to top</span>
<span class="hidden-mobile">{{ i18n "nav_top" }}</span>
</a>
</span>
</div>

View File

@ -1,19 +1,20 @@
<header class="gdoc-header">
<div class="container flex align-center justify-between">
{{ if .MenuEnabled }}
<label for="menu-control" class="gdoc-nav__control">
<label for="menu-control" class="gdoc-nav__control" tabindex="0">
<svg class="icon gdoc_menu">
<title>Open Nav Menu</title>
<title>{{ i18n "button_nav_open" }}</title>
<use xlink:href="#gdoc_menu"></use>
</svg>
<svg class="icon gdoc_arrow_back">
<title>Close Nav Menu</title>
<title>{{ i18n "button_nav_close" }}</title>
<use xlink:href="#gdoc_arrow_back"></use>
</svg>
</label>
{{ end }}
<a class="gdoc-header__link" href="{{ .Root.Site.BaseURL }}">
<span class="gdoc-brand flex align-center">
<div>
<a class="gdoc-brand gdoc-header__link" href="{{ .Root.Site.BaseURL }}">
<span class="flex align-center">
<img
class="gdoc-brand__img"
src="{{ (default "brand.svg" .Root.Site.Params.GeekdocLogo) | relURL }}"
@ -22,39 +23,50 @@
<span class="gdoc-brand__title">{{ .Root.Site.Title }}</span>
</span>
</a>
</div>
<div class="gdoc-menu-header">
<span {{ if .Root.Site.Data.menu.extra.header }}class="gdoc-menu-header__items"{{ end }}>
<span
{{ if .Root.Site.Data.menu.extra.header }}class="gdoc-menu-header__items"{{ end }}
>
{{ if .Root.Site.Data.menu.extra.header }}
{{ partial "menu-extra" (dict "current" .Root "source" .Root.Site.Data.menu.extra.header "target" "header") }}
{{ end }}
<span id="gdoc-dark-mode">
<svg class="icon gdoc_brightness_dark">
<title>Toggle Dark/Light/Auto mode</title>
<title>{{ i18n "button_toggle_dark" }}</title>
<use xlink:href="#gdoc_brightness_dark"></use>
</svg>
<svg class="icon gdoc_brightness_light">
<title>Toggle Dark/Light/Auto mode</title>
<title>{{ i18n "button_toggle_dark" }}</title>
<use xlink:href="#gdoc_brightness_light"></use>
</svg>
<svg class="icon gdoc_brightness_auto">
<title>Toggle Dark/Light/Auto mode</title>
<title>{{ i18n "button_toggle_dark" }}</title>
<use xlink:href="#gdoc_brightness_auto"></use>
</svg>
</span>
{{ if .Root.Site.Data.menu.extra.header }}
<span class="gdoc-menu-header__home">
<a href="{{ .Root.Site.BaseURL }}" class="gdoc-header__link">
<svg class="icon gdoc_home">
<title>Back to homepage</title>
<title>{{ i18n "button_homepage" }}</title>
<use xlink:href="#gdoc_home"></use>
</svg>
</a>
</span>
{{ end }}
{{ partial "language" .Root }}
{{ if .Root.Site.Data.menu.extra.header }}
<span class="gdoc-menu-header__control">
<label for="menu-header-control">
<svg class="icon gdoc_keyborad_arrow_right">
<use xlink:href="#gdoc_keyborad_arrow_right"></use>
<title>Close Menu Bar</title>
<title>{{ i18n "button_menu_close" }}</title>
</svg>
</label>
</span>
@ -64,7 +76,7 @@
<label for="menu-header-control" class="gdoc-menu-header__control">
<svg class="icon gdoc_keyborad_arrow_left">
<use xlink:href="#gdoc_keyborad_arrow_left"></use>
<title>Open Menu Bar</title>
<title>{{ i18n "button_menu_open" }}</title>
</svg>
</label>
{{ end }}

View File

@ -11,10 +11,10 @@
{{ if .Truncated }}
<a
class="flex-inline align-center fake-link"
title="Read full post"
title="{{ i18n "posts_read_more" }}"
href="{{ .RelPermalink }}"
>
Read full post
{{ i18n "posts_read_more" }}
<i class="gdoc-icon">gdoc_arrow_right_alt</i>
</a>
{{ end }}

View File

@ -11,10 +11,10 @@
{{ if .Truncated }}
<a
class="flex-inline align-center fake-link"
title="Read full post"
title="{{ i18n "posts_read_more" }}"
href="{{ .RelPermalink }}"
>
Read full post
{{ i18n "posts_read_more" }}
<i class="gdoc-icon">gdoc_arrow_right_alt</i>
</a>
{{ end }}

View File

@ -17,7 +17,7 @@
"prep:clean": "shx rm -rf build/ static/",
"prep:clean-all": "shx rm -rf build/ dist/ static/ data/ assets/sprites/ exampleSite/data/sprites/",
"prep:make": "mkdir -p build/icons/ build/fonts/ dist/",
"svg-sprite-list": "run-s prep:make svg ; mkdir -p exampleSite/data/sprites/ ; cp build/fonts/GeekdocIcons.json exampleSite/data/sprites/geekdoc.json",
"svg-sprite-list": "run-s prep:make svg ; mkdir -p exampleSite/data/sprites/ ; shx cp build/fonts/GeekdocIcons.json exampleSite/data/sprites/geekdoc.json",
"lint": "eslint src/js/ --color"
},
"repository": {

5
src/icons/language.svg Normal file
View File

@ -0,0 +1,5 @@
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 28 28">
<title>language</title>
<path d="M20.112 16.826h4.732q0.394-1.84 0.394-2.826t-0.394-2.826h-4.732q0.197 1.38 0.197 2.826t-0.197 2.826zM17.615 24.582q1.643-0.526 3.418-2.005t2.695-2.991h-4.141q-0.657 2.629-1.972 4.995zM17.286 16.826q0.197-1.38 0.197-2.826t-0.197-2.826h-6.573q-0.197 1.38-0.197 2.826t0.197 2.826h6.573zM14 25.173q1.84-2.695 2.695-5.587h-5.39q0.854 2.892 2.695 5.587zM8.413 8.413q0.789-2.826 1.972-4.995-1.643 0.526-3.451 2.005t-2.662 2.991h4.141zM4.272 19.587q0.854 1.512 2.662 2.991t3.451 2.005q-1.315-2.366-1.972-4.995h-4.141zM3.155 16.826h4.732q-0.197-1.38-0.197-2.826t0.197-2.826h-4.732q-0.394 1.84-0.394 2.826t0.394 2.826zM14 2.826q-1.84 2.695-2.695 5.587h5.39q-0.854-2.892-2.695-5.587zM23.727 8.413q-0.92-1.512-2.695-2.991t-3.418-2.005q1.183 2.169 1.972 4.995h4.141zM14 0q5.784 0 9.892 4.108t4.108 9.892-4.108 9.892-9.892 4.108-9.892-4.108-4.108-9.892 4.108-9.892 9.892-4.108z"></path>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -6,6 +6,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
const input = document.querySelector("#gdoc-search-input")
const results = document.querySelector("#gdoc-search-results")
const basePath = urlPath(input ? input.dataset.siteBaseUrl : "")
const lang = input ? input.dataset.siteLang : ""
const configSchema = {
type: "object",
@ -26,7 +27,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
if (!input) return
getJson(combineURLs(basePath, "/search/config.min.json"), function (searchConfig) {
getJson(combineURLs(basePath, "/search/" + lang + ".config.min.json"), function (searchConfig) {
const validationResult = validator.validate(searchConfig)
if (!validationResult.valid)

View File

@ -204,7 +204,7 @@ img {
.gdoc-menu-header {
&__items {
display: inline-block;
display: flex;
> span {
margin-left: $padding-8;
@ -287,7 +287,7 @@ img {
& ~ label {
cursor: pointer;
.icon {
.icon.toggle {
font-size: $font-size-12;
}
}
@ -323,7 +323,8 @@ img {
}
.gdoc-nav__entry,
.gdoc-search__entry {
.gdoc-search__entry,
.gdoc-language__entry {
flex: 1;
color: var(--body-font-color);
@ -338,8 +339,21 @@ img {
}
}
.gdoc-search__list,
.gdoc-language__list {
background: var(--body-background);
border-radius: $border-radius;
box-shadow: 0 1px 3px 0 var(--accent-color), 0 1px 2px 0 var(--accent-color-lite);
position: absolute;
margin: 0;
padding: $padding-8 !important;
list-style: none;
top: calc(100% + #{$padding-8});
z-index: 2;
}
.gdoc-page {
min-width: $body-min-width;
min-width: calc($body-min-width - $padding-16 * 2);
flex-grow: 1;
padding: $padding-16 0;
@ -594,17 +608,8 @@ img {
&__list {
visibility: hidden;
background: var(--body-background);
border-radius: $border-radius;
box-shadow: 0 1px 3px 0 var(--accent-color), 0 1px 2px 0 var(--accent-color-lite);
position: absolute;
margin: 0;
padding: $padding-8;
list-style: none;
left: 0;
top: calc(100% + #{$padding-8});
width: 100%;
z-index: 2;
ul {
list-style: none;
@ -635,6 +640,33 @@ img {
}
}
.gdoc-language {
&__selector {
position: relative;
list-style: none;
user-select: none;
cursor: pointer;
margin: 0;
padding: 0;
width: 100%;
&:focus,
&:focus-within,
&:active {
.gdoc-language__list {
display: block;
}
}
}
&__list {
display: none;
right: 0;
width: auto;
white-space: nowrap;
}
}
.gdoc-error {
padding: $padding-16 * 6 $padding-16;
margin: 0 auto;

View File

@ -56,10 +56,7 @@ $main-color: rgba(65, 134, 201, 1) !default;
$second-color: rgba(47, 51, 62, 1) !default;
$mark-color: rgba(255, 171, 0, 1) !default;
$body-background-dark: mix(
invert($body-background, 75%),
$second-color
) !default;
$body-background-dark: mix(invert($body-background, 75%), $second-color) !default;
$link-color-dark: rgba(110, 168, 212, 1) !default;
$link-color-visited-dark: rgba(186, 142, 240) !default;
@ -76,5 +73,5 @@ $hint-colors: (
info: rgba(0, 145, 234, 1),
ok: rgba(0, 200, 83, 1),
warning: rgba(255, 171, 0, 1),
danger: rgba(213, 0, 0, 1),
danger: rgba(213, 0, 0, 1)
) !default;

View File

@ -45,8 +45,7 @@
@font-face {
font-family: "Metropolis";
src: url("fonts/Metropolis.woff2") format("woff2"),
url("fonts/Metropolis.woff") format("woff");
src: url("fonts/Metropolis.woff2") format("woff2"), url("fonts/Metropolis.woff") format("woff");
font-weight: normal;
font-style: normal;
font-display: swap;

View File

@ -17,6 +17,7 @@
.gdoc-brand {
font-size: $font-size-24;
line-height: $font-size-24;
&__img {
display: none;
@ -30,7 +31,7 @@
&__control,
&__home {
display: inline-block;
display: flex;
}
}
@ -86,13 +87,13 @@
}
#menu-header-control:checked ~ .gdoc-header {
.gdoc-brand__title {
.gdoc-brand {
display: none;
}
.gdoc-menu-header {
&__items {
display: inline-block;
display: flex;
}
&__control {