From b8d31039ec4c2cdbab85c0e9c0e3c6c4d9f7c108 Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Tue, 14 Mar 2017 00:16:20 +0300 Subject: [PATCH 1/7] Initial auto arrows --- layouts/partials/footer.html | 42 +++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index c07802bcc3..db86a98737 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -5,10 +5,46 @@ + {{ with .Site.Params.menu }} + {{ range $index, $element := . }} + {{ with index $.Site.Params.menu (sub $index 1)}} + {{ $prev := index (last 1 (index $.Site.Sections .)) 0 }} + {{ $.Scratch.SetInMap $element "prev" $prev }} + {{ end }} + {{ with index $.Site.Params.menu (add $index 1)}} + {{ $next := index (first 1 (index $.Site.Sections .)) 0 }} + {{ $.Scratch.SetInMap $element "next" $next }} + {{ end }} + {{ end }} + {{ else }} + {{ range $key, $section := $.Site.Sections }} + {{ with $prevSec := $.Scratch.Get "prevIter"}} + {{ with index $.Site.Sections . }} + {{ $.Scratch.SetInMap $key "prev" (index (last 1 .) 0) }} + {{ $.Scratch.SetInMap $prevSec "next" (index (first 1 $section) 0) }} + {{ end }} + {{ end }} + {{ $.Scratch.Set "prevIter" $key }} + {{ end }} + {{ end }} From 23e40c6b5b4599840267a6164baa34965ee0eb66 Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Tue, 14 Mar 2017 01:07:40 +0300 Subject: [PATCH 2/7] Use index pages --- layouts/_default/list.html | 3 +++ layouts/partials/footer.html | 2 +- layouts/partials/header.html | 8 ++++---- layouts/partials/menu.html | 38 +++++++++++++++--------------------- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/layouts/_default/list.html b/layouts/_default/list.html index e69de29bb2..16f6ffc141 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -0,0 +1,3 @@ +{{ partial "header.html" . }} +{{ .Content }} +{{ partial "footer.html" . }} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index db86a98737..86cf6c7695 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,5 +1,5 @@ - {{ if .Params.chapter }} + {{ if eq .Kind "section" }} {{ end }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 030139c576..12ee292785 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -47,7 +47,7 @@ - {{ if and (not .Params.chapter) (.Params.toc) }} + {{ if and (ne .Kind "section") (.Params.toc) }} {{ end }} {{ $type := .Type }} @@ -67,10 +67,10 @@ {{ end }} - {{ if .Params.chapter }} + {{ if eq .Kind "section" }}
{{ end }} -
- {{ if not .Params.chapter }} +
+ {{ if ne .Kind "section" }}

{{.Title}}

{{ end }} diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html index 5d344a4735..7956836817 100644 --- a/layouts/partials/menu.html +++ b/layouts/partials/menu.html @@ -12,31 +12,27 @@
    {{ $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 }} -

  • - {{ end }} - {{ end }} - {{ else }} - {{ $.Scratch.Set "menuItems" .Site.Sections }} + {{ $.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 }} {{ $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 $page.Site.Sections $key) }} + {{ with $index := $.Site.GetPage "section" $key }} + {{ if .Title }} + {{ $.Scratch.Set "first" $index }} + {{ else }} + {{ $.Scratch.Set (index $value 0).Page }} + {{ end }} {{ end }} - {{ $value := $.Scratch.Get "currentItem" }} - {{ $first := (index $value 0).Page }} + {{ $first := $.Scratch.Get "first" }} From f238cdbc16fa413e036eb669fc66d15708a3b7ca Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Tue, 14 Mar 2017 01:31:13 +0300 Subject: [PATCH 3/7] Auto prev/next --- archetypes/chapter.md | 3 --- archetypes/default.md | 2 -- layouts/partials/footer.html | 38 +++++++++++++----------------------- 3 files changed, 14 insertions(+), 29 deletions(-) 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/partials/footer.html b/layouts/partials/footer.html index 86cf6c7695..ffc2b6922f 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -5,39 +5,29 @@
- {{ with .Site.Params.menu }} - {{ range $index, $element := . }} - {{ with index $.Site.Params.menu (sub $index 1)}} - {{ $prev := index (last 1 (index $.Site.Sections .)) 0 }} - {{ $.Scratch.SetInMap $element "prev" $prev }} - {{ end }} - {{ with index $.Site.Params.menu (add $index 1)}} - {{ $next := index (first 1 (index $.Site.Sections .)) 0 }} - {{ $.Scratch.SetInMap $element "next" $next }} - {{ end }} - {{ end }} - {{ else }} - {{ range $key, $section := $.Site.Sections }} - {{ with $prevSec := $.Scratch.Get "prevIter"}} - {{ with index $.Site.Sections . }} - {{ $.Scratch.SetInMap $key "prev" (index (last 1 .) 0) }} - {{ $.Scratch.SetInMap $prevSec "next" (index (first 1 $section) 0) }} - {{ end }} - {{ end }} - {{ $.Scratch.Set "prevIter" $key }} + {{ $.Scratch.Set "_sectionpages" (slice) }} + {{ range $sname, $spages := .Site.Sections }} + {{ $.Scratch.Add "_sectionpages" ($.Site.GetPage "section" $sname) }} + {{ end }} + {{ $.Scratch.Set "_allpages" (slice) }} + {{ range sort ($.Scratch.Get "_sectionpages") "Weight" }} + {{ $.Scratch.Add "_allpages" . }} + {{ range index $.Site.Sections .Section }} + {{ $.Scratch.Add "_allpages" .Page }} {{ end }} {{ end }} + {{ $allpages := $.Scratch.Get "_allpages" }} + {{ 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 @@
- {{ with .Site.Params.menu }} - {{ range $index, $element := . }} - {{ with index $.Site.Params.menu (sub $index 1)}} - {{ $prev := index (last 1 (index $.Site.Sections .)) 0 }} - {{ $.Scratch.SetInMap $element "prev" $prev }} - {{ end }} - {{ with index $.Site.Params.menu (add $index 1)}} - {{ $next := index (first 1 (index $.Site.Sections .)) 0 }} - {{ $.Scratch.SetInMap $element "next" $next }} - {{ end }} - {{ end }} - {{ else }} - {{ range $key, $section := $.Site.Sections }} - {{ with $prevSec := $.Scratch.Get "prevIter"}} - {{ with index $.Site.Sections . }} - {{ $.Scratch.SetInMap $key "prev" (index (last 1 .) 0) }} - {{ $.Scratch.SetInMap $prevSec "next" (index (first 1 $section) 0) }} - {{ end }} - {{ end }} - {{ $.Scratch.Set "prevIter" $key }} + {{ $.Scratch.Set "_sectionpages" (slice) }} + {{ range $sname, $spages := .Site.Sections }} + {{ $.Scratch.Add "_sectionpages" ($.Site.GetPage "section" $sname) }} + {{ end }} + {{ $.Scratch.Set "_allpages" (slice) }} + {{ range sort ($.Scratch.Get "_sectionpages") "Weight" }} + {{ $.Scratch.Add "_allpages" . }} + {{ range index $.Site.Sections .Section }} + {{ $.Scratch.Add "_allpages" .Page }} {{ end }} {{ end }} + {{ $allpages := $.Scratch.Get "_allpages" }} +
+ {{ if $.Site.Params.autoNav }} {{ $.Scratch.Set "_sectionpages" (slice) }} {{ if $.Site.Params.menu }} {{ range $sname := $.Site.Params.menu }} @@ -26,11 +27,14 @@ {{ $.Scratch.Add "_allpages" .Page }} {{ end }} {{ end }} - {{ $allpages := $.Scratch.Get "_allpages" }} + {{ end }}