mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-01-18 10:50:24 +00:00
dependencies: optimize #891
This commit is contained in:
parent
e79541352b
commit
825f547781
5 changed files with 35 additions and 46 deletions
25
layouts/partials/_relearn/articleWalker.html
Normal file
25
layouts/partials/_relearn/articleWalker.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
{{- $html := "" }}
|
||||
{{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" .) .Path }}
|
||||
{{- range $pages }}
|
||||
{{- if not (partialCached "_relearn/pageIsHidden.gotmpl" . .Path) }}
|
||||
{{- $html = printf "%s%s" $html (partialCached "_relearn/articleWalker.html" . .Path) }}
|
||||
{{- $child := . }}
|
||||
{{- range .Site.Params.relearn.dependencies }}
|
||||
{{- $has := printf "has%s" .name }}
|
||||
{{- $hasnested := printf "relearnHasNested%s" .name }}
|
||||
{{- $.Store.Set $hasnested (or ($.Store.Get $hasnested) ($child.Store.Get $hasnested) ($child.Store.Get $has)) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- $article := partialCached "_relearn/nestedContent.gotmpl" . .Path }}
|
||||
{{- if len $html }}
|
||||
{{- $title := partial "title.gotmpl" (dict "page" . "linkTitle" true) }}
|
||||
{{- $html = printf `%s
|
||||
<section>
|
||||
<h1 class="a11y-only">%s</h1>%s
|
||||
</section>` $article (T "Subsections" $title | htmlEscape) $html }}
|
||||
{{- else }}
|
||||
{{- $html = $article }}
|
||||
{{- end }}
|
||||
{{- return $html }}
|
8
layouts/partials/_relearn/dependencies.gotmpl
Normal file
8
layouts/partials/_relearn/dependencies.gotmpl
Normal file
|
@ -0,0 +1,8 @@
|
|||
{{- range .Site.Params.relearn.dependencies }}
|
||||
{{- $has := printf "has%s" .name }}
|
||||
{{- $disable := printf "disable%s" .name }}
|
||||
{{- $wants := or (and (ne (index $.Params $disable) nil) (not (index $.Params $disable))) (and (ne (index $.Site.Params $disable) nil) (not (index $.Site.Params $disable))) }}
|
||||
{{- if $wants }}
|
||||
{{- $.Store.Set $has true }}
|
||||
{{- end }}
|
||||
{{- end }}
|
|
@ -1,39 +1,2 @@
|
|||
{{- .Store.Set "relearnIsNested" true }}
|
||||
{{- template "section-tree-print" dict "sect" . "currentnode" . }}
|
||||
{{- define "section-tree-print" }}
|
||||
{{- $currentNode := .currentnode }}
|
||||
{{- $currentFileRelPermalink := .currentnode.RelPermalink }}
|
||||
{{- with .sect }}
|
||||
{{- $isSelf := eq .RelPermalink $currentFileRelPermalink }}
|
||||
{{- $isAncestor := and (not $isSelf) (.IsAncestor $currentNode) }}
|
||||
{{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" .) .Path }}
|
||||
{{- $relearnIsHiddenFrom := index ($currentNode.Scratch.Get "relearnIsHiddenFrom") .RelPermalink }}
|
||||
{{- $hidden := and $relearnIsHiddenFrom (not $.showhidden) (not $isSelf) (not $isAncestor) }}
|
||||
{{- if $hidden }}
|
||||
{{- else }}
|
||||
{{- template "section-print" dict "sect" . "currentnode" $currentNode }}
|
||||
{{- if $pages }}
|
||||
<section>
|
||||
<h1 class="a11y-only">{{ T "Subsections" .Title }}</h1>
|
||||
{{- end }}
|
||||
{{- range $pages }}
|
||||
{{- template "section-tree-print" dict "sect" . "currentnode" $currentNode }}
|
||||
{{- end }}
|
||||
{{- if $pages }}
|
||||
</section>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- define "section-print" }}
|
||||
{{- $currentNode := .currentnode }}
|
||||
{{- with .sect }}
|
||||
{{- $page := . }}
|
||||
{{- partialCached "_relearn/nestedContent.gotmpl" $page $page.Path }}
|
||||
{{- range $page.Site.Params.relearn.dependencies }}
|
||||
{{- $has := printf "has%s" .name }}
|
||||
{{- $hasnested := printf "relearnHasNested%s" .name }}
|
||||
{{- $currentNode.Page.Store.Set $hasnested (or ($currentNode.Page.Store.Get $hasnested) ($page.Page.Store.Get $has)) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- partialCached "_relearn/articleWalker.html" . .Path | safeHTML }}
|
|
@ -1,5 +1,6 @@
|
|||
{{- $page := .page }}
|
||||
{{- $location := .location }}
|
||||
{{- partialCached "_relearn/dependencies.gotmpl" $page $page.Path }}
|
||||
{{- range $k, $v := $page.Site.Params.relearn.dependencies }}
|
||||
{{- $has := printf "has%s" $v.name }}
|
||||
{{- $hasnested := printf "relearnHasNested%s" $v.name }}
|
||||
|
|
|
@ -16,14 +16,6 @@ section: {{- .Section }}
|
|||
{{- $currentNode.Scratch.Delete "relearnIsHiddenNode" }}{{/* the node itself is flagged as hidden */}}
|
||||
{{- $currentNode.Scratch.Delete "relearnIsHiddenStem" }}{{/* the node or one of its parents is flagged as hidden */}}
|
||||
{{- $currentNode.Scratch.Delete "relearnIsHiddenFrom" }}{{/* the node is hidden from the current page */}}
|
||||
{{- range $currentNode.Site.Params.relearn.dependencies }}
|
||||
{{- $has := printf "has%s" .name }}
|
||||
{{- $disable := printf "disable%s" .name }}
|
||||
{{- $wants := or (and (ne (index $currentNode.Params $disable) nil) (not (index $currentNode.Params $disable))) (and (ne (index $currentNode.Site.Params $disable) nil) (not (index $currentNode.Site.Params $disable))) }}
|
||||
{{- if $wants }}
|
||||
{{- $currentNode.Store.Set $has true }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- template "relearn-structure" dict "node" .Site.Home "currentnode" $currentNode "hiddenstem" false "hiddencurrent" false }}
|
||||
{{- if not ($currentNode.Scratch.Get "relearnIsSelfFound") }}
|
||||
{{- if not $currentNode.IsHome }}
|
||||
|
|
Loading…
Reference in a new issue