Skip to content

Commit

Permalink
dependencies: optimize #891
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Sep 13, 2024
1 parent 1d452b3 commit e1405ba
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 46 deletions.
25 changes: 25 additions & 0 deletions layouts/partials/_relearn/articleWalker.html
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions layouts/partials/_relearn/dependencies.gotmpl
Original file line number Diff line number Diff line change
@@ -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 }}
39 changes: 1 addition & 38 deletions layouts/partials/bodys/tree.html
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions layouts/partials/dependencies.html
Original file line number Diff line number Diff line change
@@ -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 }}
Expand Down
8 changes: 0 additions & 8 deletions layouts/partials/relearn-meta.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit e1405ba

Please sign in to comment.