mirror of https://github.com/onweru/compose.git

Guillaume
15.19.2023 de033dc4a2d7ffc59e9d2ad12d1909574092b5fb
Dynamic localization for menus and logo click

- Instead of using `config/_default/menus/*.toml`, this allows the use of a single `menu.toml` with `identifier = '...'` and translations in `i18n/*.toml`, as specified in https://gohugo.io/content-management/multilingual/#dynamically-localizing-menus-with-i18n
- Clicking the logo will go to the landing page while remaining in the chosen translation
1 files modified
6 ■■■■ changed files
layouts/partials/nav.html 6 ●●●● patch | view | raw | blame | history
layouts/partials/nav.html
@@ -1,7 +1,7 @@
{{- $s := .Site }}
{{- $sp := $s.Params }}
<nav class="wrap nav menu">
    <a href="{{ $s.BaseURL }}" class="nav_brand">
    <a href='{{ relLangURL "" }}' class="nav_brand">
        {{- $logos := $sp.logo }}
        {{- $litPath := absURL ($logos.lightMode) }}
        {{- $darkPath := absURL ($logos.darkMode) }}
@@ -23,11 +23,11 @@
            {{- with .Page }}
            {{- $active = or $active ( $.IsDescendant .)  }}
            {{- end }}
            {{- $url := absURL .URL }}
            {{- $url := relLangURL .URL }}
            {{- if or (hasPrefix .URL "http") (hasPrefix .URL "www.") }}
                {{- $url = .URL }}
            {{- end }}
            <a class="nav-link{{if $active }} active{{end}}" href="{{ $url }}"><span{{if $active }} class="active"{{end}}>{{ .Name }}</span></a>
            <a class="nav-link{{if $active }} active{{end}}" href="{{ $url }}"><span{{if $active }} class="active"{{end}}>{{ T .Identifier | default .Name }}</span></a>
        </li>
        {{- end }}
        {{ $repo := $sp.source }}