diff --git a/layouts/partials/_relearn/pageNext.gotmpl b/layouts/partials/_relearn/pageNext.gotmpl index d498217325..97dc7ba432 100644 --- a/layouts/partials/_relearn/pageNext.gotmpl +++ b/layouts/partials/_relearn/pageNext.gotmpl @@ -1,13 +1,30 @@ -{{- $collection := .collection }} -{{- $item := .item }} -{{- $found := false }} -{{- $result := "" }} -{{- range $collection }} - {{- if $found }} - {{- $result = .Page.Page }} - {{- break }} - {{- else if eq $item .Page.Page }} - {{- $found = true }} - {{- end }} +{{- $next := "" }} +{{- if eq .Page.Kind "term" }} + {{- /* go to next term page */}} + {{- $taxonomy_page := .Site.GetPage .Data.Plural }} + {{- $pages := partialCached "partials/_relearn/pagesTaxonomy.gotmpl" $taxonomy_page $taxonomy_page.Path }} + {{- $next = partial "inline/next-term" (dict "collection" $pages "item" .) }} +{{- else if eq .Page.Kind "taxonomy" }} + {{- /* go to first term page */}} + {{- $pages := partialCached "partials/_relearn/pagesTaxonomy.gotmpl" . .Path }} + {{- $next = (index $pages 0).Page }} +{{- else }} + {{- $next = .Scratch.Get "relearnNextPage" }} {{- end }} -{{- return $result }} \ No newline at end of file +{{- return $next }} + +{{- define "partials/inline/next-term" }} + {{- $collection := .collection }} + {{- $item := .item }} + {{- $found := false }} + {{- $result := "" }} + {{- range $collection }} + {{- if $found }} + {{- $result = .Page.Page }} + {{- break }} + {{- else if eq $item .Page.Page }} + {{- $found = true }} + {{- end }} + {{- end }} + {{- return $result }} +{{- end }} \ No newline at end of file diff --git a/layouts/partials/_relearn/pagePrev.gotmpl b/layouts/partials/_relearn/pagePrev.gotmpl index cbf88766ec..c54c6c096f 100644 --- a/layouts/partials/_relearn/pagePrev.gotmpl +++ b/layouts/partials/_relearn/pagePrev.gotmpl @@ -1,12 +1,29 @@ -{{- $collection := .collection }} -{{- $item := .item }} -{{- $found := "" }} -{{- $result := "" }} -{{- range $collection }} - {{- if eq $item .Page.Page }} - {{- $result = $found }} - {{- break }} - {{- end }} - {{- $found = .Page.Page }} +{{- $prev := "" }} +{{- if eq .Page.Kind "term" }} + {{- /* go to previous term page or taxonomy page if it is the first term */}} + {{- $taxonomy_page := .Site.GetPage .Data.Plural }} + {{- $pages := partialCached "partials/_relearn/pagesTaxonomy.gotmpl" $taxonomy_page $taxonomy_page.Path }} + {{- $prev = partial "inline/prev-term" (dict "collection" $pages "item" .) | default $taxonomy_page }} +{{- else if eq .Page.Kind "taxonomy" }} + {{- $prev = .Site.Home }} +{{- else if eq .Page.Kind "home" }} + {{- /* no prev here */}} +{{- else }} + {{- $prev = .Scratch.Get "relearnPrevPage" }} {{- end }} -{{- return $result }} \ No newline at end of file +{{- return $prev }} + +{{- define "partials/inline/prev-term" }} + {{- $collection := .collection }} + {{- $item := .item }} + {{- $last := "" }} + {{- $result := "" }} + {{- range $collection }} + {{- if eq $item .Page.Page }} + {{- $result = $last }} + {{- break }} + {{- end }} + {{- $last = .Page.Page }} + {{- end }} + {{- return $result }} +{{- end }} \ No newline at end of file diff --git a/layouts/partials/topbar/button/next.html b/layouts/partials/topbar/button/next.html index 3b252ac7d5..34afca57c2 100644 --- a/layouts/partials/topbar/button/next.html +++ b/layouts/partials/topbar/button/next.html @@ -8,17 +8,7 @@ {{- if eq (.Language.LanguageDirection | default (T "Reading-direction") | default "ltr") "rtl" }} {{- $endarrow = "🡐" }} {{- end }} - {{- $next := .Scratch.Get "relearnNextPage" }} - {{- if eq .Page.Kind "term" }} - {{- /* go to next term page */}} - {{- $taxonomy_page := .Site.GetPage .Data.Plural }} - {{- $pages := partialCached "partials/_relearn/pagesTaxonomy.gotmpl" $taxonomy_page $taxonomy_page.Path }} - {{- $next = partial "partials/_relearn/pageNext.gotmpl" (dict "collection" $pages "item" .) }} - {{- else if eq .Page.Kind "taxonomy" }} - {{- /* go to first term page */}} - {{- $pages := partialCached "partials/_relearn/pagesTaxonomy.gotmpl" . .Path }} - {{- $next = (index $pages 0).Page }} - {{- end }} + {{- $next := partialCached "_relearn/pageNext.gotmpl" . .Path }} {{- $nextTitle := partial "title.gotmpl" (dict "page" $next "outputFormat" "html") }} {{- partial "topbar/func/button.html" (dict "page" . diff --git a/layouts/partials/topbar/button/prev.html b/layouts/partials/topbar/button/prev.html index 0678e02fb1..a91f095ce4 100644 --- a/layouts/partials/topbar/button/prev.html +++ b/layouts/partials/topbar/button/prev.html @@ -8,15 +8,7 @@ {{- if eq (.Language.LanguageDirection | default (T "Reading-direction") | default "ltr") "rtl" }} {{- $startarrow = "🡒" }} {{- end }} - {{- $prev := .Scratch.Get "relearnPrevPage" }} - {{- if eq .Page.Kind "term" }} - {{- /* go to previous term page or taxonomy page if it is the first term */}} - {{- $taxonomy_page := .Site.GetPage .Data.Plural }} - {{- $pages := partialCached "partials/_relearn/pagesTaxonomy.gotmpl" $taxonomy_page $taxonomy_page.Path }} - {{- $prev = partial "partials/_relearn/pagePrev.gotmpl" (dict "collection" $pages "item" .) | default $taxonomy_page }} - {{- else if eq .Page.Kind "taxonomy" }} - {{- $prev = .Site.Home }} - {{- end }} + {{- $prev := partialCached "_relearn/pagePrev.gotmpl" . .Path }} {{- $prevTitle := partial "title.gotmpl" (dict "page" $prev "outputFormat" "html") }} {{- partial "topbar/func/button.html" (dict "page" .