From 79107d2e75a610999c11c6d57e37fd7f23498a47 Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Tue, 14 Mar 2017 02:10:33 +0300 Subject: [PATCH] Backwards compatibility --- layouts/_default/list.html | 2 ++ layouts/partials/footer.html | 20 +++++++++++++++----- layouts/partials/header.html | 7 ++++--- layouts/partials/menu.html | 25 ++++++++++++++++--------- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 16f6ffc141..3902b7741a 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,3 +1,5 @@ +{{ if .Content }} {{ partial "header.html" . }} {{ .Content }} {{ partial "footer.html" . }} +{{ end }} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index ffc2b6922f..40bbb5f6e5 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,17 +1,27 @@ - {{ if eq .Kind "section" }} + {{ $isChapter := or (eq .Kind "section") (.Params.chapter)}} + {{ if $isChapter }} {{ end }} {{ $.Scratch.Set "_sectionpages" (slice) }} - {{ range $sname, $spages := .Site.Sections }} - {{ $.Scratch.Add "_sectionpages" ($.Site.GetPage "section" $sname) }} + {{ 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 sort ($.Scratch.Get "_sectionpages") "Weight" }} - {{ $.Scratch.Add "_allpages" . }} + {{ range $.Scratch.Get "_sectionpages" }} + {{ if .Content }} + {{ $.Scratch.Add "_allpages" . }} + {{ end }} {{ range index $.Site.Sections .Section }} {{ $.Scratch.Add "_allpages" .Page }} {{ end }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 12ee292785..7de4a5924c 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -22,6 +22,7 @@ {{ partial "style.html" . }} + {{ $isChapter := or (eq .Kind "section") (.Params.chapter)}} {{ partial "menu.html" . }}
@@ -47,7 +48,7 @@ - {{ if and (ne .Kind "section") (.Params.toc) }} + {{ if and (not $isChapter) (.Params.toc) }} {{ end }} {{ $type := .Type }} @@ -67,10 +68,10 @@ {{ end }} - {{ if eq .Kind "section" }} + {{ if $isChapter }}
{{ end }}
- {{ if ne .Kind "section" }} + {{ if not $isChapter }}

{{.Title}}

{{ end }} diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html index 7956836817..6b11ea63c1 100644 --- a/layouts/partials/menu.html +++ b/layouts/partials/menu.html @@ -12,27 +12,34 @@
    {{ $page := . }} - {{ $.Scratch.Set "_pages" (slice) }} - {{ range $key, $value := .Site.Sections }} - {{ $.Scratch.Add "_pages" ($.Site.GetPage "section" $key) }} - {{ end }} - {{ $.Scratch.Set "menuItems" (slice)}} - {{ range $key, $value := sort ($.Scratch.Get "_pages") "Weight" }} - {{ $.Scratch.Add "menuItems" $value.Section }} + {{ if $.Site.Params.menu }} + {{ $.Scratch.Set "menuItems" $.Site.Params.menu }} + {{ else }} + {{ $.Scratch.Set "_pages" (slice) }} + {{ range $key, $value := .Site.Sections }} + {{ $.Scratch.Add "_pages" ($.Site.GetPage "section" $key) }} + {{ end }} + {{ $.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 "" }} {{ $value := (index $page.Site.Sections $key) }} + {{ $.Scratch.Set "_value" $value }} {{ with $index := $.Site.GetPage "section" $key }} - {{ if .Title }} + {{ if .Content }} {{ $.Scratch.Set "first" $index }} {{ else }} - {{ $.Scratch.Set (index $value 0).Page }} + {{ $.Scratch.Set "first" (index $value 0).Page }} + {{ $.Scratch.Set "_value" (after 1 $value) }} {{ end }} {{ end }} {{ $first := $.Scratch.Get "first" }} + {{ $value := $.Scratch.Get "_value" }}