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:
- name: Level 1
ref: "/toc-tree/level-1"
- name:
en: Level 1 (EN)
de: Level 1 (DE)
sub:
- name: Level 1.1
- name:
en: Level 1.1 (EN)
de: Level 1.1 (DE)
ref: "/toc-tree/level-1/level-1-1"
- name: Level 1.2
ref: "/toc-tree/level-1/level-1-2"

View file

@ -10,16 +10,16 @@
<ul class="gdoc-nav__list">
{{ range sort (default (seq 0) .sect) "weight" }}
{{ $current.Scratch.Set "current" $current }}
{{ $current.Scratch.Set "site" $site }}
{{ $name := .name }}
{{ if reflect.IsMap .name }}
{{ $name = (index .name $site.Language.Lang) }}
{{ end }}
<li>
{{ $ref := default false .ref }}
{{ if $ref }}
{{ $site := $current.Scratch.Get "site" }}
{{ $this := $site.GetPage .ref }}
{{ $current := $current.Scratch.Get "current" }}
{{ $icon := default false .icon }}
{{ $numberOfPages := (add (len $this.Pages) (len $this.Sections)) }}
{{ $isCurrent := eq $current $this }}
@ -27,13 +27,6 @@
{{ $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"
@ -80,7 +73,7 @@
{{ end }}
{{ 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 }}
</li>
{{ end }}

View file

@ -15,12 +15,10 @@
{{ $isCurrent := eq $current $this }}
{{ $icon := default false .icon }}
{{ $name := .name }}
{{ if reflect.IsMap .name }}
{{ $current.Scratch.Set "refName" (index .name $site.Language.Lang) }}
{{ else }}
{{ $current.Scratch.Set "refName" .name }}
{{ $name = (index .name $site.Language.Lang) }}
{{ end }}
{{ $name := $current.Scratch.Get "refName" }}
{{ if not .icon }}
{{ errorf "Missing 'icon' attribute in data file for '%s' menu item '%s'" $target $name }}