From d60c2988f2a642f1e2849c863962dcd2369c4880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sun, 10 Jul 2022 01:25:38 +0200 Subject: [PATCH] theme: fix dependencies for nested output formats #308 --- .../partials/archetypes/chapter/article.html | 3 ++- .../partials/archetypes/default/article.html | 3 ++- .../archetypes/deprecated-chapter/article.html | 3 ++- .../archetypes/deprecated-home/article.html | 3 ++- layouts/partials/archetypes/home/article.html | 3 ++- layouts/partials/footer.html | 6 +++--- layouts/partials/nested-article.html | 10 ++++++++-- layouts/partials/page-meta.hugo | 17 +++++------------ layouts/partials/shortcodes/math.html | 5 ++++- layouts/partials/shortcodes/mermaid.html | 5 ++++- layouts/partials/shortcodes/swagger.html | 5 ++++- 11 files changed, 38 insertions(+), 25 deletions(-) diff --git a/layouts/partials/archetypes/chapter/article.html b/layouts/partials/archetypes/chapter/article.html index fef69d96e9..9c9ce89d78 100644 --- a/layouts/partials/archetypes/chapter/article.html +++ b/layouts/partials/archetypes/chapter/article.html @@ -1,5 +1,6 @@ +{{- $page := .page }} {{- $content := .content }} -{{- with .page }} +{{- with $page }}
{{ partial "heading-pre.html" . }}
{{ T "Chapter" .Params.Weight }}

{{ .Title }}

{{ partial "heading-post.html" . }} diff --git a/layouts/partials/archetypes/default/article.html b/layouts/partials/archetypes/default/article.html index 85b44bddd9..f0a717534e 100644 --- a/layouts/partials/archetypes/default/article.html +++ b/layouts/partials/archetypes/default/article.html @@ -1,5 +1,6 @@ +{{- $page := .page }} {{- $content := .content }} -{{- with .page }} +{{- with $page }}
{{ partial "heading-pre.html" . }}

{{ .Title }}

{{ partial "heading-post.html" . }} diff --git a/layouts/partials/archetypes/deprecated-chapter/article.html b/layouts/partials/archetypes/deprecated-chapter/article.html index 809d76f28e..997383c03c 100644 --- a/layouts/partials/archetypes/deprecated-chapter/article.html +++ b/layouts/partials/archetypes/deprecated-chapter/article.html @@ -1,5 +1,6 @@ +{{- $page := .page }} {{- $content := .content }} -{{- with .page }} +{{- with $page }}
{{ $content | safeHTML }} diff --git a/layouts/partials/archetypes/deprecated-home/article.html b/layouts/partials/archetypes/deprecated-home/article.html index 16ccd303cf..b15e932f24 100644 --- a/layouts/partials/archetypes/deprecated-home/article.html +++ b/layouts/partials/archetypes/deprecated-home/article.html @@ -1,5 +1,6 @@ +{{- $page := .page }} {{- $content := .content }} -{{- with .page }} +{{- with $page }}
{{ $content | safeHTML }} diff --git a/layouts/partials/archetypes/home/article.html b/layouts/partials/archetypes/home/article.html index c680d08ae6..6e66a678cc 100644 --- a/layouts/partials/archetypes/home/article.html +++ b/layouts/partials/archetypes/home/article.html @@ -1,5 +1,6 @@ +{{- $page := .page }} {{- $content := .content }} -{{- with .page }} +{{- with $page }}
{{ partial "heading-pre.html" . }}

{{ .Title }}

{{ partial "heading-post.html" . }} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index fcff21a9d2..f690608a5a 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -7,7 +7,7 @@ -{{- $wantsMathJax := or (.Page.Store.Get "selfHasMathJax") (and (.Page.Store.Get (printf "%sIsNested" ((.Scratch.Get "relearnOutputFormat") | lower))) (.Page.Store.Get "nestedHasMathJax")) }} +{{- $wantsMathJax := .Scratch.Get (printf "%sHasMathJax" ((.Scratch.Get "relearnOutputFormat") | lower)) }} {{- if $wantsMathJax }} {{- if isset .Params "mathjaxinitialize" }} {{- $.Scratch.Set "mathJaxInitialize" .Params.mathJaxInitialize }} @@ -48,7 +48,7 @@ {{- end }} {{- end }} -{{- $wantsMermaid := or (.Page.Store.Get "selfHasMermaid") (and (.Page.Store.Get (printf "%sIsNested" ((.Scratch.Get "relearnOutputFormat") | lower))) (.Page.Store.Get "nestedHasMermaid")) }} +{{- $wantsMermaid := .Scratch.Get (printf "%sHasMermaid" ((.Scratch.Get "relearnOutputFormat") | lower)) }} {{- if $wantsMermaid }} {{- if isset .Params "custommermaidurl" }} @@ -78,7 +78,7 @@ useMermaid( JSON.parse({{ $.Scratch.Get "mermaidInitialize" }}) ); {{- end }} -{{- $wantsSwagger := or (.Page.Store.Get "selfHasSwagger") (and (.Page.Store.Get (printf "%sIsNested" ((.Scratch.Get "relearnOutputFormat") | lower))) (.Page.Store.Get "nestedHasSwagger")) }} +{{- $wantsSwagger := .Scratch.Get (printf "%sHasSwagger" ((.Scratch.Get "relearnOutputFormat") | lower)) }} {{- if $wantsSwagger }} {{- if isset .Params "customswaggerurl" }} diff --git a/layouts/partials/nested-article.html b/layouts/partials/nested-article.html index 55fcda8032..c323add11c 100644 --- a/layouts/partials/nested-article.html +++ b/layouts/partials/nested-article.html @@ -91,7 +91,13 @@ {{- define "section-print" }} {{- $currentNode := .currentnode }} {{- with .sect }} - {{- $content := partial "content.html" . }} - {{- partial "output-partial.html" (dict "base" "output-article" "page" . "parameter" (dict "page" . "content" $content)) }} + {{- $page := . }} + {{- $content := partial "content.html" $page }} + {{- partial "output-partial.html" (dict "base" "output-article" "page" $page "parameter" (dict "page" $page "content" $content)) }} + {{- range $page.OutputFormats }} + {{- $currentNode.Scratch.Set (printf "%sHasMathJax" (.Name | lower)) (or ($currentNode.Scratch.Get (printf "%sHasMathJax" (.Name | lower))) ($page.Scratch.Get (printf "%sHasMathJax" (.Name | lower)))) }} + {{- $currentNode.Scratch.Set (printf "%sHasMermaid" (.Name | lower)) (or ($currentNode.Scratch.Get (printf "%sHasMermaid" (.Name | lower))) ($page.Scratch.Get (printf "%sHasMermaid" (.Name | lower)))) }} + {{- $currentNode.Scratch.Set (printf "%sHasSwagger" (.Name | lower)) (or ($currentNode.Scratch.Get (printf "%sHasSwagger" (.Name | lower))) ($page.Scratch.Get (printf "%sHasSwagger" (.Name | lower)))) }} + {{- end }} {{- end }} {{- end }} \ No newline at end of file diff --git a/layouts/partials/page-meta.hugo b/layouts/partials/page-meta.hugo index 75ca38a4dd..c85ee6ebc6 100644 --- a/layouts/partials/page-meta.hugo +++ b/layouts/partials/page-meta.hugo @@ -5,6 +5,11 @@ {{- $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.OutputFormats }} + {{- $currentNode.Scratch.Delete (printf "%sHasMathJax" (.Name | lower)) }} + {{- $currentNode.Scratch.Delete (printf "%sHasMermaid" (.Name | lower)) }} + {{- $currentNode.Scratch.Delete (printf "%sHasSwagger" (.Name | lower)) }} +{{- end }} {{- template "relearn-structure" dict "node" .Site.Home "currentnode" $currentNode "hiddenstem" false "hiddencurrent" false "defaultOrdersectionsby" .Site.Params.ordersectionsby }} {{- define "relearn-structure" }} {{- $currentNode := .currentnode }} @@ -53,16 +58,4 @@ {{- range $pages }} {{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hiddenstem" $hidden_stem "hiddencurrent" $hidden_from_current "defaultOrdersectionsby" $defaultOrdersectionsby }} {{- end}} - - {{- if $isSelf }} - {{- $currentNode.Page.Store.Set "selfHasMathjax" (or ($currentNode.Page.Store.Get "selfHasMathJax") (and (ne $currentNode.Params.disableMathjax nil) (not $currentNode.Params.disableMathjax)) (and (ne .Site.Params.disableMathjax nil) (not .Site.Params.disableMathjax))) }} - {{- $currentNode.Page.Store.Set "selfHasMermaid" (or ($currentNode.Page.Store.Get "selfHasMermaid") (and (ne $currentNode.Params.disableMermaid nil) (not $currentNode.Params.disableMermaid)) (and (ne .Site.Params.disableMermaid nil) (not .Site.Params.disableMermaid))) }} - {{- $currentNode.Page.Store.Set "selfHasSwagger" (or ($currentNode.Page.Store.Get "selfHasSwagger") (and (ne $currentNode.Params.disableSwagger nil) (not $currentNode.Params.disableSwagger)) (and (ne .Site.Params.disableSwagger nil) (not .Site.Params.disableSwagger))) }} - {{- end }} - - {{- if $isChildren }} - {{- $currentNode.Page.Store.Set "nestedHasMathJax" (or ($currentNode.Page.Store.Get "nestedHasMathJax") (.node.Page.Store.Get "selfHasMathJax") (.node.Page.Store.Get "nestedfHasMathJax")) }} - {{- $currentNode.Page.Store.Set "nestedHasMermaid" (or ($currentNode.Page.Store.Get "nestedHasMermaid") (.node.Page.Store.Get "selfHasMermaid") (.node.Page.Store.Get "nestedfHasMermaid")) }} - {{- $currentNode.Page.Store.Set "nestedHasSwagger" (or ($currentNode.Page.Store.Get "nestedHasSwagger") (.node.Page.Store.Get "selfHasSwagger") (.node.Page.Store.Get "nestedHasSwagger")) }} - {{- end }} {{- end }} \ No newline at end of file diff --git a/layouts/partials/shortcodes/math.html b/layouts/partials/shortcodes/math.html index d7aa83f19c..531f58f90b 100644 --- a/layouts/partials/shortcodes/math.html +++ b/layouts/partials/shortcodes/math.html @@ -5,5 +5,8 @@ {{- $content | safeHTML -}} -{{- .Page.Store.Set "selfHasMathJax" true }} +{{- $page := .Page }} +{{- range $page.OutputFormats }} + {{- $page.Scratch.Set (printf "%sHasMathJax" (.Name | lower)) true }} +{{- end }} {{- end }} \ No newline at end of file diff --git a/layouts/partials/shortcodes/mermaid.html b/layouts/partials/shortcodes/mermaid.html index 63748e7686..e515bec0bc 100644 --- a/layouts/partials/shortcodes/mermaid.html +++ b/layouts/partials/shortcodes/mermaid.html @@ -5,5 +5,8 @@
{{- $content | safeHTML -}}
-{{- .Page.Store.Set "selfHasMermaid" true }} +{{- $page := .Page }} +{{- range $page.OutputFormats }} + {{- $page.Scratch.Set (printf "%sHasMermaid" (.Name | lower)) true }} +{{- end }} {{- end }} \ No newline at end of file diff --git a/layouts/partials/shortcodes/swagger.html b/layouts/partials/shortcodes/swagger.html index d2653bde65..052e176053 100644 --- a/layouts/partials/shortcodes/swagger.html +++ b/layouts/partials/shortcodes/swagger.html @@ -24,5 +24,8 @@ spec-url="{{ $src }}" sort-tags="true" > -{{- .Page.Store.Set "selfHasSwagger" true }} +{{- $page := .Page }} +{{- range $page.OutputFormats }} + {{- $page.Scratch.Set (printf "%sHasSwagger" (.Name | lower)) true }} +{{- end }} {{- end }} \ No newline at end of file