aboutsummaryrefslogtreecommitdiff
path: root/layouts/partials
diff options
context:
space:
mode:
authorEgor Lynko <flexoid@gmail.com>2021-01-17 17:32:33 +0300
committerGitHub <noreply@github.com>2021-01-17 22:32:33 +0800
commitfcf20219586e4c66d703e249aac5bb6a42a4320d (patch)
treeafd0c168258572759e11d1a93cc371c1cc47b5f2 /layouts/partials
parent9d2f9230232af22ef091f3f39f8f203b1da2e78a (diff)
feat(language-selector): Implement optional language selector (#298)
Diffstat (limited to 'layouts/partials')
-rw-r--r--layouts/partials/header.html4
-rw-r--r--layouts/partials/header/language-selector.html25
-rw-r--r--layouts/partials/slideout.html4
3 files changed, 31 insertions, 2 deletions
diff --git a/layouts/partials/header.html b/layouts/partials/header.html
index 3592e88..24d5b37 100644
--- a/layouts/partials/header.html
+++ b/layouts/partials/header.html
@@ -8,6 +8,8 @@
</a>
</div>
+{{ partial "header/language-selector.html" . }}
+
<nav class="site-navbar">
<ul id="menu" class="menu">
{{ range .Site.Menus.main -}}
@@ -16,4 +18,4 @@
</li>
{{- end }}
</ul>
-</nav> \ No newline at end of file
+</nav>
diff --git a/layouts/partials/header/language-selector.html b/layouts/partials/header/language-selector.html
new file mode 100644
index 0000000..e28650e
--- /dev/null
+++ b/layouts/partials/header/language-selector.html
@@ -0,0 +1,25 @@
+<!--
+ Language selector.
+
+ If current page has version in another language, language link will lead
+ to the translated page. If not, the link will be to the home page of the site
+ with specified language.
+-->
+{{ if (and (.Site.IsMultiLingual) ($.Site.Params.showLanguageSelector)) }}
+ <div class="language-selector">
+ <ul class="languages-list">
+ {{ range $homeTranslation := .Site.Home.AllTranslations }}
+ {{ $active := eq $homeTranslation.Language $.Site.Language }}
+ {{ $pageTranslation := (index (where $.Page.AllTranslations "Language.Lang" "eq" $homeTranslation.Language.Lang) 0) }}
+
+ <li class="language-item {{if $active}}active{{end}}">
+ {{ with $pageTranslation }}
+ <a href="{{ .Permalink }}">{{ .Language.Lang }}</a>
+ {{ else }}
+ <a href="{{ $homeTranslation.Permalink }}">{{ .Language.Lang }}</a>
+ {{ end }}
+ </li>
+ {{ end }}
+ </ul>
+ </div>
+{{ end }}
diff --git a/layouts/partials/slideout.html b/layouts/partials/slideout.html
index 42ed13e..da0885c 100644
--- a/layouts/partials/slideout.html
+++ b/layouts/partials/slideout.html
@@ -22,4 +22,6 @@
</a>
{{- end }}
</ul>
-</nav> \ No newline at end of file
+
+ {{ partial "header/language-selector.html" . }}
+</nav>