fix: always fetch menu name from data file (#296)

This commit is contained in:
Robert Kaussow 2022-01-23 22:32:21 +01:00 committed by GitHub
parent 5c22ce57dc
commit 2805fbd33a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 19 deletions

View File

@ -1,9 +1,12 @@
--- ---
main: main:
- name: Level 1 - name:
ref: "/toc-tree/level-1" en: Level 1 (EN)
de: Level 1 (DE)
sub: sub:
- name: Level 1.1 - name:
en: Level 1.1 (EN)
de: Level 1.1 (DE)
ref: "/toc-tree/level-1/level-1-1" ref: "/toc-tree/level-1/level-1-1"
- name: Level 1.2 - name: Level 1.2
ref: "/toc-tree/level-1/level-1-2" ref: "/toc-tree/level-1/level-1-2"

View File

@ -10,16 +10,16 @@
<ul class="gdoc-nav__list"> <ul class="gdoc-nav__list">
{{ range sort (default (seq 0) .sect) "weight" }} {{ range sort (default (seq 0) .sect) "weight" }}
{{ $current.Scratch.Set "current" $current }} {{ $name := .name }}
{{ $current.Scratch.Set "site" $site }} {{ if reflect.IsMap .name }}
{{ $name = (index .name $site.Language.Lang) }}
{{ end }}
<li> <li>
{{ $ref := default false .ref }} {{ $ref := default false .ref }}
{{ if $ref }} {{ if $ref }}
{{ $site := $current.Scratch.Get "site" }}
{{ $this := $site.GetPage .ref }} {{ $this := $site.GetPage .ref }}
{{ $current := $current.Scratch.Get "current" }}
{{ $icon := default false .icon }} {{ $icon := default false .icon }}
{{ $numberOfPages := (add (len $this.Pages) (len $this.Sections)) }} {{ $numberOfPages := (add (len $this.Pages) (len $this.Sections)) }}
{{ $isCurrent := eq $current $this }} {{ $isCurrent := eq $current $this }}
@ -27,13 +27,6 @@
{{ $id := substr (sha1 $this.Permalink) 0 8 }} {{ $id := substr (sha1 $this.Permalink) 0 8 }}
{{ $doCollapse := and (isset . "sub") (or $this.Params.GeekdocCollapseSection (default false .Site.Params.GeekdocCollapseAllSections)) }} {{ $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 <input
type="checkbox" type="checkbox"
@ -80,7 +73,7 @@
{{ end }} {{ end }}
{{ with .sub }} {{ with .sub }}
{{ template "menu-file" dict "sect" . "current" ($current.Scratch.Get "current") "site" ($current.Scratch.Get "site") }} {{ template "menu-file" dict "sect" . "current" $current "site" $site }}
{{ end }} {{ end }}
</li> </li>
{{ end }} {{ end }}

View File

@ -15,12 +15,10 @@
{{ $isCurrent := eq $current $this }} {{ $isCurrent := eq $current $this }}
{{ $icon := default false .icon }} {{ $icon := default false .icon }}
{{ $name := .name }}
{{ if reflect.IsMap .name }} {{ if reflect.IsMap .name }}
{{ $current.Scratch.Set "refName" (index .name $site.Language.Lang) }} {{ $name = (index .name $site.Language.Lang) }}
{{ else }}
{{ $current.Scratch.Set "refName" .name }}
{{ end }} {{ end }}
{{ $name := $current.Scratch.Get "refName" }}
{{ if not .icon }} {{ 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 }}