hugo-theme-relearn/layouts/partials/_relearn/pagePrev.gotmpl
2024-10-11 16:45:43 +02:00

29 lines
No EOL
968 B
Go Template

{{- $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 $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 }}