From e1405ba29711dab13c57245c037e1080120fbf44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sun, 8 Sep 2024 00:11:36 +0200 Subject: [PATCH] dependencies: optimize #891 --- layouts/partials/_relearn/articleWalker.html | 25 ++++++++++++ layouts/partials/_relearn/dependencies.gotmpl | 8 ++++ layouts/partials/bodys/tree.html | 39 +------------------ layouts/partials/dependencies.html | 1 + layouts/partials/relearn-meta.gotmpl | 8 ---- 5 files changed, 35 insertions(+), 46 deletions(-) create mode 100644 layouts/partials/_relearn/articleWalker.html create mode 100644 layouts/partials/_relearn/dependencies.gotmpl diff --git a/layouts/partials/_relearn/articleWalker.html b/layouts/partials/_relearn/articleWalker.html new file mode 100644 index 0000000000..0a686e452b --- /dev/null +++ b/layouts/partials/_relearn/articleWalker.html @@ -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 +
+

%s

%s +
` $article (T "Subsections" $title | htmlEscape) $html }} +{{- else }} + {{- $html = $article }} +{{- end }} +{{- return $html }} \ No newline at end of file diff --git a/layouts/partials/_relearn/dependencies.gotmpl b/layouts/partials/_relearn/dependencies.gotmpl new file mode 100644 index 0000000000..c5d2817bc7 --- /dev/null +++ b/layouts/partials/_relearn/dependencies.gotmpl @@ -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 }} \ No newline at end of file diff --git a/layouts/partials/bodys/tree.html b/layouts/partials/bodys/tree.html index afebad93e0..cab2dbd5c5 100644 --- a/layouts/partials/bodys/tree.html +++ b/layouts/partials/bodys/tree.html @@ -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 }} -
-

{{ T "Subsections" .Title }}

- {{- end }} - {{- range $pages }} - {{- template "section-tree-print" dict "sect" . "currentnode" $currentNode }} - {{- end }} - {{- if $pages }} -
- {{- 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 }} \ No newline at end of file +{{- partialCached "_relearn/articleWalker.html" . .Path | safeHTML }} \ No newline at end of file diff --git a/layouts/partials/dependencies.html b/layouts/partials/dependencies.html index 6ad4e0cf02..1120892198 100644 --- a/layouts/partials/dependencies.html +++ b/layouts/partials/dependencies.html @@ -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 }} diff --git a/layouts/partials/relearn-meta.gotmpl b/layouts/partials/relearn-meta.gotmpl index 7b71ef979b..94f7b8b637 100644 --- a/layouts/partials/relearn-meta.gotmpl +++ b/layouts/partials/relearn-meta.gotmpl @@ -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 }}