Skip to content

Commit

Permalink
arrownav: optimize #891
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Oct 11, 2024
1 parent 825f547 commit 07cd94c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 43 deletions.
41 changes: 29 additions & 12 deletions layouts/partials/_relearn/pageNext.gotmpl
Original file line number Diff line number Diff line change
@@ -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 }}
{{- 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 }}
39 changes: 28 additions & 11 deletions layouts/partials/_relearn/pagePrev.gotmpl
Original file line number Diff line number Diff line change
@@ -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 }}
{{- 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 }}
12 changes: 1 addition & 11 deletions layouts/partials/topbar/button/next.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" .
Expand Down
10 changes: 1 addition & 9 deletions layouts/partials/topbar/button/prev.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" .
Expand Down

0 comments on commit 07cd94c

Please sign in to comment.