diff --git a/archetypes/chapter.md b/archetypes/chapter.md index 3fe15e2cec..1d975216f1 100644 --- a/archetypes/chapter.md +++ b/archetypes/chapter.md @@ -1,9 +1,6 @@ --- title: "Some Chapter title" weight: 0 -prev: /prev/path -next: /next/path -chapter: true icon: "X. " # HTML code as prefix in the menu --- diff --git a/archetypes/default.md b/archetypes/default.md index 2b35103feb..e47481e95a 100644 --- a/archetypes/default.md +++ b/archetypes/default.md @@ -1,8 +1,6 @@ --- title: "Some Title" weight: 5 -prev: /prev/path -next: /next/path toc: true --- diff --git a/layouts/_default/list.html b/layouts/_default/list.html index e69de29bb2..c536b82900 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -0,0 +1,13 @@ +{{ if .Content }} +{{ partial "header.html" . }} +{{ .Content }} +{{ partial "footer.html" . }} +{{ else }} +{{ with (index (index .Site.Sections .Section) 0) }} +{{ with .Page }} +{{ partial "header.html" . }} +{{ .Content }} +{{ partial "footer.html" . }} +{{ end }} +{{ end }} +{{ end }} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index c07802bcc3..eedba9d357 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,14 +1,54 @@ - {{ if .Params.chapter }} + {{ $isChapter := .Params.chapter | default (eq .Kind "section")}} + {{ if $isChapter }} {{ end }} + {{ if $.Site.Params.autoNav }} + {{ $.Scratch.Set "_sectionpages" (slice) }} + {{ if $.Site.Params.menu }} + {{ range $sname := $.Site.Params.menu }} + {{ $.Scratch.Add "_sectionpages" ($.Site.GetPage "section" $sname) }} + {{ end }} + {{ else }} + {{ range $sname, $spages := .Site.Sections }} + {{ $.Scratch.Add "_sectionpages" ($.Site.GetPage "section" $sname) }} + {{ end }} + {{ $.Scratch.Set "_sectionpages" (sort ($.Scratch.Get "_sectionpages") "Weight") }} + {{ end }} + {{ $.Scratch.Set "_allpages" (slice) }} + {{ range $.Scratch.Get "_sectionpages" }} + {{ if .Content }} + {{ $.Scratch.Add "_allpages" . }} + {{ end }} + {{ range index $.Site.Sections .Section }} + {{ $.Scratch.Add "_allpages" .Page }} + {{ end }} + {{ end }} + {{ end }} + diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 7a34089eb4..26ce94f20c 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -22,6 +22,7 @@ {{ partial "style.html" . }} + {{ $isChapter := .Params.chapter | default (eq .Kind "section")}} {{ partial "menu.html" . }}
@@ -47,15 +48,20 @@ - {{ if and (not .Params.chapter) (.Params.toc) }} + {{ if and (not $isChapter) (.Params.toc) }} {{ end }} - {{ $type := .Type }} - {{ $relLink := .RelPermalink }} - {{ range $name , $value := .Site.Sections }} - {{ if eq $name $type }} - {{ $first := (index $value 0).Page }} - {{ if ne $first.RelPermalink $relLink }} + {{ if ne $.Section "" }} + {{ $section := index $.Site.Sections $.Section }} + {{ $sectionPage := $.Site.GetPage "section" $.Section }} + {{ if $sectionPage.Content }} + {{ $first := $.Site.GetPage "section" $.Section }} + {{ if ne $first.UniqueID $.UniqueID }} + + {{ end }} + {{ else if gt $section.Len 0 }} + {{ $first := (index $section 0).Page }} + {{ if ne $first.UniqueID $.UniqueID }} {{ end }} {{ end }} @@ -67,10 +73,10 @@ {{ end }} - {{ if .Params.chapter }} + {{ if $isChapter }}
{{ end }} -
- {{ if not .Params.chapter }} +
+ {{ if not $isChapter }}

{{.Title}}

{{ end }} diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html index 5d344a4735..8e60b3b658 100644 --- a/layouts/partials/menu.html +++ b/layouts/partials/menu.html @@ -11,56 +11,65 @@
    - {{ $page := . }} - {{ if .Site.Params.menu }} - {{ $.Scratch.Set "menuItems" (slice) }} - {{ range $i, $key := .Site.Params.menu }} - {{ if isset $page.Site.Sections $key }} - {{ $.Scratch.Add "menuItems" $key }} - {{ else }} -
  • - {{ printf "Unknown section '%s' found in site menu" $key }} -

  • + {{ if $.Site.Params.menu }} + {{ $.Scratch.Set "menuItems" $.Site.Params.menu }} + {{ else }} + {{ $.Scratch.Set "_pages" (slice) }} + {{ range $key, $value := .Site.Sections }} + {{ $sectionPage := $.Site.GetPage "section" $key }} + {{ if $sectionPage.Content }} + {{ $.Scratch.Add "_pages" $sectionPage }} + {{ else if gt $value.Len 0 }} + {{ $.Scratch.Add "_pages" (index $value 0).Page }} {{ end }} {{ end }} - {{ else }} - {{ $.Scratch.Set "menuItems" .Site.Sections }} + {{ $.Scratch.Set "menuItems" (slice)}} + {{ range $key, $value := sort ($.Scratch.Get "_pages") "Weight" }} + {{ $.Scratch.Add "menuItems" $value.Section }} + {{ end }} {{ end }} {{ $menuItems := $.Scratch.Get "menuItems" }} {{ range $i, $key := $menuItems }} {{ if ne $key "" }} - {{ if not $.Site.Params.menu }} - {{ $.Scratch.Set "currentItem" (index $page.Site.Sections $i) }} - {{ else }} - {{ $.Scratch.Set "currentItem" (index $page.Site.Sections $key) }} + {{ $value := (index $.Site.Sections $key) }} + {{ $.Scratch.Set "_value" $value }} + {{ with $index := $.Site.GetPage "section" $key }} + {{ if .Content }} + {{ $.Scratch.Set "first" $index }} + {{ else if gt $value.Len 0}} + {{ $.Scratch.Set "first" (index $value 0).Page }} + {{ if gt $value.Len 1 }} + {{ $.Scratch.Set "_value" (after 1 $value) }} + {{ else }} + {{ $.Scratch.Set "_value" nil }} + {{ end }} + {{ end }} {{ end }} - {{ $value := $.Scratch.Get "currentItem" }} - {{ $first := (index $value 0).Page }} + {{ $first := $.Scratch.Get "first" }} + {{ $value := $.Scratch.Get "_value" }} -
  • {{ if isset $first.Params "icon" }} {{ printf $first.Params.icon | safeHTML }} {{ end }} {{ $first.Title }} - {{ if $page.Site.Params.showVisitedLinks}} + {{ if $.Site.Params.showVisitedLinks}} {{ end }} - {{ if gt $value.Len 1}} + {{ if gt $value.Len 0}} {{ end }}
  • diff --git a/theme.toml b/theme.toml index 4716162269..ee54a6eac4 100644 --- a/theme.toml +++ b/theme.toml @@ -8,7 +8,7 @@ description = "Documentation theme for Hugo, based on Grav Learn theme" homepage = "https://matcornic.github.io/hugo-learn-doc/basics/what-is-this-hugo-theme/" tags = ["documentation", "grav", "learn", "doc"] features = ["documentation"] -min_version = 0.17 +min_version = 0.19 [author] name = "Mathieu Cornic"