mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-22 23:37:53 +00:00
Auto prev/next
This commit is contained in:
parent
23e40c6b5b
commit
1238a71e12
4 changed files with 15 additions and 34 deletions
|
@ -1,9 +1,6 @@
|
||||||
---
|
---
|
||||||
title: "Some Chapter title"
|
title: "Some Chapter title"
|
||||||
weight: 0
|
weight: 0
|
||||||
prev: /prev/path
|
|
||||||
next: /next/path
|
|
||||||
chapter: true
|
|
||||||
icon: "<b>X. </b>" # HTML code as prefix in the menu
|
icon: "<b>X. </b>" # HTML code as prefix in the menu
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
---
|
---
|
||||||
title: "Some Title"
|
title: "Some Title"
|
||||||
weight: 5
|
weight: 5
|
||||||
prev: /prev/path
|
|
||||||
next: /next/path
|
|
||||||
toc: true
|
toc: true
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -5,39 +5,29 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ with .Site.Params.menu }}
|
{{ $.Scratch.Set "_sectionpages" (slice) }}
|
||||||
{{ range $index, $element := . }}
|
{{ range $sname, $spages := .Site.Sections }}
|
||||||
{{ with index $.Site.Params.menu (sub $index 1)}}
|
{{ $.Scratch.Add "_sectionpages" ($.Site.GetPage "section" $sname) }}
|
||||||
{{ $prev := index (last 1 (index $.Site.Sections .)) 0 }}
|
{{ end }}
|
||||||
{{ $.Scratch.SetInMap $element "prev" $prev }}
|
{{ $.Scratch.Set "_allpages" (slice) }}
|
||||||
{{ end }}
|
{{ range sort ($.Scratch.Get "_sectionpages") "Weight" }}
|
||||||
{{ with index $.Site.Params.menu (add $index 1)}}
|
{{ $.Scratch.Add "_allpages" . }}
|
||||||
{{ $next := index (first 1 (index $.Site.Sections .)) 0 }}
|
{{ range index $.Site.Sections .Section }}
|
||||||
{{ $.Scratch.SetInMap $element "next" $next }}
|
{{ $.Scratch.Add "_allpages" .Page }}
|
||||||
{{ 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 }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{ $allpages := $.Scratch.Get "_allpages" }}
|
||||||
|
|
||||||
<div id="navigation">
|
<div id="navigation">
|
||||||
{{ $secpages := sort (where .Site.RegularPages "Section" .Section) "Weight" }}
|
{{ range $index, $element := $allpages }}
|
||||||
{{ range $index, $element := $secpages }}
|
|
||||||
{{if eq $element.UniqueID $.UniqueID }}
|
{{if eq $element.UniqueID $.UniqueID }}
|
||||||
{{ if not (isset $.Params "prev") }}
|
{{ if not (isset $.Params "prev") }}
|
||||||
{{ with index $secpages (sub $index 1) | default ($.Scratch.Get $.Section).prev.Page}}
|
{{ with index $allpages (sub $index 1) }}
|
||||||
<a class="nav nav-prev" href="{{ $.Site.BaseURL }}{{ .URL }}"> <i class="fa fa-chevron-left"></i></a>
|
<a class="nav nav-prev" href="{{ $.Site.BaseURL }}{{ .URL }}"> <i class="fa fa-chevron-left"></i></a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if not (isset $.Params "next") }}
|
{{ if not (isset $.Params "next") }}
|
||||||
{{ with index $secpages (add $index 1) | default ($.Scratch.Get $.Section).next.Page}}
|
{{ with index $allpages (add $index 1) }}
|
||||||
<a class="nav nav-next" href="{{ $.Site.BaseURL }}{{ .URL }}" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>
|
<a class="nav nav-next" href="{{ $.Site.BaseURL }}{{ .URL }}" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -26,11 +26,7 @@
|
||||||
|
|
||||||
{{ $value := (index $page.Site.Sections $key) }}
|
{{ $value := (index $page.Site.Sections $key) }}
|
||||||
{{ with $index := $.Site.GetPage "section" $key }}
|
{{ with $index := $.Site.GetPage "section" $key }}
|
||||||
{{ if .Title }}
|
{{ $.Scratch.Set "first" $index }}
|
||||||
{{ $.Scratch.Set "first" $index }}
|
|
||||||
{{ else }}
|
|
||||||
{{ $.Scratch.Set (index $value 0).Page }}
|
|
||||||
{{ end }}
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ $first := $.Scratch.Get "first" }}
|
{{ $first := $.Scratch.Get "first" }}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue