diff --git a/assets/_relearn_searchindex.js b/assets/_relearn_searchindex.js index 2d35acddc5..e0f603f66a 100644 --- a/assets/_relearn_searchindex.js +++ b/assets/_relearn_searchindex.js @@ -1,4 +1,3 @@ -{{- partialCached "relearn-meta.gotmpl" . .Path }} {{- $pages := slice }} {{- range .Site.Pages }} {{- if partial "_relearn/pageIsSpecial.gotmpl" . }} diff --git a/layouts/404.html b/layouts/404.html index 047eaaca58..e4fc3b4188 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -1,4 +1,3 @@ -{{- partialCached "relearn-meta.gotmpl" . .Path -}} {{- .Store.Set "relearnOutputFormat" "notfound" }} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 7b05b1674e..8b6ee47fce 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,4 +1,3 @@ -{{- partialCached "relearn-meta.gotmpl" . .Path -}} {{- block "storeOutputFormat" . }}{{ end }} {{- if .IsHome }} diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml index b351518cb6..9c78cfeb63 100644 --- a/layouts/_default/rss.xml +++ b/layouts/_default/rss.xml @@ -1,5 +1,4 @@ {{- /* based on Hugo 0.125.5 rss.xml */}} -{{- partialCached "relearn-meta.gotmpl" . .Path }} {{- /* Deprecate site.Author.email in favor of site.Params.author.email */}} {{- $authorEmail := "" }} {{- if and .Site.Params.author (reflect.IsMap .Site.Params.author) .Site.Params.author.email }} diff --git a/layouts/_default/sitemap.xml b/layouts/_default/sitemap.xml index 2063ce2da1..b44d1be888 100644 --- a/layouts/_default/sitemap.xml +++ b/layouts/_default/sitemap.xml @@ -1,5 +1,4 @@ {{- /* based on Hugo 0.125.5 sitemap.xml */}} -{{- partialCached "relearn-meta.gotmpl" . .Path }} {{- printf "" | safeHTML }} {{- range where .Pages "Sitemap.Disable" "ne" true }} diff --git a/layouts/partials/_relearn/pageNext.gotmpl b/layouts/partials/_relearn/pageNext.gotmpl index 97dc7ba432..4d5c6a08ea 100644 --- a/layouts/partials/_relearn/pageNext.gotmpl +++ b/layouts/partials/_relearn/pageNext.gotmpl @@ -9,7 +9,7 @@ {{- $pages := partialCached "partials/_relearn/pagesTaxonomy.gotmpl" . .Path }} {{- $next = (index $pages 0).Page }} {{- else }} - {{- $next = .Scratch.Get "relearnNextPage" }} + {{- $next = partial "inline/next-page" . }} {{- end }} {{- return $next }} @@ -27,4 +27,93 @@ {{- end }} {{- end }} {{- return $result }} +{{- 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) }} + {{- if $nextVisible }} + {{- $nextSibling = partial "inline/leftmost_descendant" $nextVisible }} + {{- if not $nextSibling }} + {{- $nextSibling = partial "inline/next_sibling_or_ancestor" $parent }} + {{- end }} + {{- else }} + {{- $nextSibling = partial "inline/next_sibling_or_ancestor" $parent }} + {{- 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 }} {{- end }} \ No newline at end of file diff --git a/layouts/partials/_relearn/pagePrev.gotmpl b/layouts/partials/_relearn/pagePrev.gotmpl index c54c6c096f..fe94343978 100644 --- a/layouts/partials/_relearn/pagePrev.gotmpl +++ b/layouts/partials/_relearn/pagePrev.gotmpl @@ -9,7 +9,7 @@ {{- else if eq .Page.Kind "home" }} {{- /* no prev here */}} {{- else }} - {{- $prev = .Scratch.Get "relearnPrevPage" }} + {{- $prev = or (partial "inline/prev_page" .) .Site.Home }} {{- end }} {{- return $prev }} @@ -26,4 +26,81 @@ {{- $last = .Page.Page }} {{- end }} {{- return $result }} +{{- end }} + +{{- define "partials/inline/prev_page" }} + {{- $previousVisible := "" }} + {{- $currentNode := . }} + {{- with partial "inline/parent" $currentNode }} + {{- $parent := . }} + {{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" $parent) $parent.Path }} + {{- $previousSibling := partial "inline/prev_sibling" (dict "siblings" $pages "currentNode" $currentNode) }} + {{- if $previousSibling }} + {{- $previousVisible = partial "inline/rightmost_descendant" $previousSibling }} + {{- if not $previousVisible }} + {{- if $previousSibling.RelPermalink }} + {{- $previousVisible = $previousSibling }} + {{- else }} + {{- $previousVisible = partial "inline/prev_page" $previousSibling }} + {{- end }} + {{- end }} + {{- else }} + {{- if $parent.RelPermalink }} + {{- $previousVisible = $parent }} + {{- else }} + {{- $previousVisible = partial "inline/prev_page" $parent }} + {{- end }} + {{- end }} + {{- end }} + {{- return $previousVisible }} +{{- end }} + +{{- define "partials/inline/prev_sibling" }} + {{- $previousSibling := "" }} + {{- $siblings := .siblings }} + {{- $currentNode := .currentNode }} + {{- range $siblings }} + {{- if eq . $currentNode }} + {{- break }} + {{- else if not (or (.Params.hidden) (eq .Title "")) }} + {{- $previousSibling = . }} + {{- end }} + {{- end }} + {{- return $previousSibling }} +{{- end }} + +{{- define "partials/inline/rightmost_descendant" }} + {{- $rightmostVisible := . }} + {{- $pages := (partialCached "_relearn/pages.gotmpl" (dict "page" $rightmostVisible) $rightmostVisible.Path) | collections.Reverse }} + {{- range $pages }} + {{- if not (or (.Params.hidden) (eq .Title "")) }} + {{- with partial "inline/rightmost_descendant" . }} + {{- if .RelPermalink }} + {{- $rightmostVisible = . }} + {{- break }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- return $rightmostVisible }} +{{- 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 }} {{- end }} \ No newline at end of file diff --git a/layouts/partials/relearn-meta.gotmpl b/layouts/partials/relearn-meta.gotmpl deleted file mode 100644 index c89e54edba..0000000000 --- a/layouts/partials/relearn-meta.gotmpl +++ /dev/null @@ -1,62 +0,0 @@ - -{{- $currentNode := . }} -{{- $forceContent := $currentNode.WordCount }} -{{- $currentNode.Scratch.Delete "relearnIsSelfFound" }} -{{- $currentNode.Scratch.Delete "relearnPrevPage" }} -{{- $currentNode.Scratch.Delete "relearnNextPage" }} -{{- if (and (not .Params.disableNextPrev) (not .Site.Params.disableNextPrev)) }} - {{- template "relearn-structure" dict "node" .Site.Home "currentnode" $currentNode "hiddenstem" false "hiddencurrent" false }} - {{- if not ($currentNode.Scratch.Get "relearnIsSelfFound") }} - {{- if not $currentNode.IsHome }} - {{- $currentNode.Scratch.Set "relearnPrevPage" .Site.Home }} - {{- end }} - {{- end }} -{{- end }} - -{{- define "relearn-structure" }} - {{- $currentNode := .currentnode }} - {{- $isSelf := eq $currentNode .node }} - {{- $isDescendant := and (not $isSelf) (.node.IsDescendant $currentNode) }} - {{- $isAncestor := and (not $isSelf) (.node.IsAncestor $currentNode) }} - {{- $isOther := and (not $isDescendant) (not $isSelf) (not $isAncestor) }} - {{- $isChildren := eq $currentNode .node.Parent }} - {{- if $isSelf }} - {{- $currentNode.Scratch.Set "relearnIsSelfFound" true }} - {{- end }} - {{- $isSelfFound := eq ($currentNode.Scratch.Get "relearnIsSelfFound") true }} - {{- $isPreSelf := and (not $isSelfFound) (not $isSelf) }} - {{- $isPostSelf := and ($isSelfFound) (not $isSelf) }} - - {{- $hidden_node := or (.node.Params.hidden) (eq .node.Title "") }} - {{- $hidden_stem := or $hidden_node .hiddenstem }} - {{- $hidden_from_current := or (and $hidden_node (not $isAncestor) (not $isSelf) ) (and .hiddencurrent (or $isPreSelf $isPostSelf $isDescendant) ) }} - - {{- if or (eq $currentNode.Kind "home") (eq $currentNode.Kind "section") (eq $currentNode.Kind "page") }} - {{- if not $hidden_from_current }} - {{- if and $isPreSelf .node.RelPermalink }} - {{- $currentNode.Scratch.Set "relearnPrevPage" .node }} - {{- else if and $isPostSelf .node.RelPermalink (eq ($currentNode.Scratch.Get "relearnNextPage") nil) }} - {{- $currentNode.Scratch.Set "relearnNextPage" .node }} - {{- end }} - {{- end }} - {{- end }} - - {{- if not ($currentNode.Scratch.Get "relearnNextPage") }} - {{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" .node) .node.Path }} - {{- range $pages }} - {{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hiddenstem" $hidden_stem "hiddencurrent" $hidden_from_current }} - {{- if $currentNode.Scratch.Get "relearnNextPage" }} - {{- break }} - {{- end }} - {{- end }} - {{- end }} -{{- end }} \ No newline at end of file