hugo-theme-relearn/layouts/partials/_relearn/pageNext.gotmpl

130 lines
4.1 KiB
Go Template
Raw Normal View History

2024-09-07 22:12:10 +00:00
{{- $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 }}
2024-09-11 08:12:14 +00:00
{{- $next = partial "inline/next-page" . }}
{{- end }}
2024-09-07 22:12:10 +00:00
{{- 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 }}
2024-09-11 08:12:14 +00:00
{{- end }}
{{- define "partials/inline/next-page" }}
{{- $nextVisible := "" }}
{{- $currentNode := . }}
{{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" $currentNode) $currentNode.Path }}
{{- range $pages }}
{{- $nextVisible = partial "inline/leftmost_descendant" . }}
{{- if $nextVisible }}
{{- break }}
{{- end }}
{{- end }}
{{- if not $nextVisible }}
{{- $nextVisible = partial "inline/next_sibling_or_ancestor" $currentNode }}
{{- end }}
{{- return $nextVisible }}
{{- end }}
{{- define "partials/inline/next_sibling_or_ancestor" }}
{{- $currentNode := . }}
{{- $nextSibling := "" }}
{{- with partial "inline/parent" $currentNode }}
{{- $parent := . }}
{{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" $parent) $parent.Path }}
{{- $nextVisible := partial "inline/next_sibling" (dict "siblings" $pages "currentNode" $currentNode) }}
{{- range $pages }}
{{- if not $nextVisible }}
{{- break }}
{{- end }}
2024-09-11 08:12:14 +00:00
{{- $nextSibling = partial "inline/leftmost_descendant" $nextVisible }}
{{- if $nextSibling }}
{{- break }}
{{- else }}
{{- $nextVisible = partial "inline/next_sibling" (dict "siblings" $pages "currentNode" $nextVisible) }}
{{- end }}
{{- end }}
{{- if not $nextSibling }}
{{- if $nextVisible }}
{{- $nextSibling = partial "inline/leftmost_descendant" $nextVisible }}
{{- end }}
2024-09-11 08:12:14 +00:00
{{- if not $nextSibling }}
{{- $nextSibling = partial "inline/next_sibling_or_ancestor" $parent }}
{{- end }}
{{- end }}
{{- end }}
{{- return $nextSibling }}
{{- end }}
{{- define "partials/inline/next_sibling" }}
{{- $siblings := .siblings }}
{{- $currentNode := .currentNode }}
{{- $nextSibling := "" }}
{{- $currentFound := false }}
{{- range $siblings }}
{{- if eq . $currentNode }}
{{- $currentFound = true }}
{{- else if $currentFound }}
{{- $nextSibling = . }}
{{- break }}
{{- end }}
{{- end }}
{{- return $nextSibling }}
{{- end }}
{{- define "partials/inline/leftmost_descendant" }}
{{- $leftmostVisible := "" }}
{{- if not (or (.Params.hidden) (eq .Title "")) }}
{{- if .RelPermalink }}
{{- $leftmostVisible = . }}
{{- else }}
{{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" .) .Path }}
{{- range $pages }}
{{- with partial "inline/leftmost_descendant" . }}
{{- $leftmostVisible = . }}
{{- break }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- return $leftmostVisible }}
{{- end }}
{{- define "partials/inline/parent" }}
{{- $nonheadless := "" }}
{{- $page := . }}
{{- $parent := .Parent }}
{{- if not (partial "_relearn/pageIsSpecial.gotmpl" $page) }}
{{- with $parent }}
{{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" .) .Path }}
{{- range $pages }}
{{- if eq . $page }}
{{- $nonheadless = $parent }}
{{- break }}
{{- end }}
{{- end }}
{{- else }}
{{- $nonheadless = $parent }}
{{- end }}
{{- end }}
{{- return $nonheadless }}
2024-09-07 22:12:10 +00:00
{{- end }}