mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-01-19 03:10:24 +00:00
theme: rework logic for nested dependencies #308
This commit is contained in:
parent
33947ae861
commit
3d20008b8e
7 changed files with 78 additions and 68 deletions
|
@ -1,3 +1,3 @@
|
|||
{{- $page := .page }}
|
||||
{{- $content := .content }}
|
||||
{{- partial "output-partial.html" (dict "base" "article" "page" $page "parameter" (dict "page" $page "content" $content)) }}
|
||||
{{- partial "single-article.html" (dict "page" $page "content" $content) }}
|
|
@ -1,3 +1,3 @@
|
|||
{{- $page := .page }}
|
||||
{{- $content := .content }}
|
||||
{{- partial "nestedArticle.html" $page }}
|
||||
{{- partial "nested-article.html" (dict "page" $page) }}
|
|
@ -7,7 +7,7 @@
|
|||
<script src="{{"js/clipboard.min.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}" defer></script>
|
||||
<script src="{{"js/perfect-scrollbar.min.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}" defer></script>
|
||||
<script src="{{"js/featherlight.min.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}" defer></script>
|
||||
{{- $wantsMathJax := or (and (eq (.Scratch.Get "relearnOutputFormat") "HTML") (.Page.Store.Get "selfHasMathJax")) (and (eq (.Scratch.Get "relearnOutputFormat") "PRINT") (.Page.Store.Get "nestedHasMathJax")) }}
|
||||
{{- $wantsMathJax := or (.Page.Store.Get "selfHasMathJax") (and (.Page.Store.Get (printf "%sIsNested" ((.Scratch.Get "relearnOutputFormat") | lower))) (.Page.Store.Get "nestedHasMathJax")) }}
|
||||
{{- if $wantsMathJax }}
|
||||
{{- if isset .Params "mathjaxinitialize" }}
|
||||
{{- $.Scratch.Set "mathJaxInitialize" .Params.mathJaxInitialize }}
|
||||
|
@ -48,7 +48,7 @@
|
|||
<script id="MathJax-script" async src="{{"js/mathjax/tex-mml-chtml.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $wantsMermaid := or (and (eq (.Scratch.Get "relearnOutputFormat") "HTML") (.Page.Store.Get "selfHasMermaid")) (and (eq (.Scratch.Get "relearnOutputFormat") "PRINT") (.Page.Store.Get "nestedHasMermaid")) }}
|
||||
{{- $wantsMermaid := or (.Page.Store.Get "selfHasMermaid") (and (.Page.Store.Get (printf "%sIsNested" ((.Scratch.Get "relearnOutputFormat") | lower))) (.Page.Store.Get "nestedHasMermaid")) }}
|
||||
{{- if $wantsMermaid }}
|
||||
<script src="{{"js/jquery.svg.pan.zoom.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}" defer></script>
|
||||
{{- if isset .Params "custommermaidurl" }}
|
||||
|
@ -78,7 +78,7 @@
|
|||
useMermaid( JSON.parse({{ $.Scratch.Get "mermaidInitialize" }}) );
|
||||
</script>
|
||||
{{- end }}
|
||||
{{- $wantsSwagger := or (and (eq (.Scratch.Get "relearnOutputFormat") "HTML") (.Page.Store.Get "selfHasSwagger")) (and (eq (.Scratch.Get "relearnOutputFormat") "PRINT") (.Page.Store.Get "nestedHasSwagger")) }}
|
||||
{{- $wantsSwagger := or (.Page.Store.Get "selfHasSwagger") (and (.Page.Store.Get (printf "%sIsNested" ((.Scratch.Get "relearnOutputFormat") | lower))) (.Page.Store.Get "nestedHasSwagger")) }}
|
||||
{{- if $wantsSwagger }}
|
||||
{{- if isset .Params "customswaggerurl" }}
|
||||
<script src="{{ .Params.customSwaggerURL }}" defer></script>
|
||||
|
|
|
@ -1,39 +1,43 @@
|
|||
{{- $currentNode := . }}
|
||||
{{- $isActive := .IsHome }}
|
||||
{{- $isShortcut := false }}
|
||||
{{- $r_url := .RelPermalink }}
|
||||
{{- with .Site.Menus.shortcuts }}
|
||||
{{- range sort . "Weight" }}
|
||||
{{- $s_url := .URL | relLangURL }}
|
||||
{{- if (eq $s_url $r_url) }}
|
||||
{{- $isShortcut = true }}
|
||||
{{- $page := .page }}
|
||||
{{- $page.Page.Store.Set (printf "%sIsNested" (($page.Scratch.Get "relearnOutputFormat") | lower)) true }}
|
||||
{{- with $page }}
|
||||
{{- $currentNode := . }}
|
||||
{{- $isActive := .IsHome }}
|
||||
{{- $isShortcut := false }}
|
||||
{{- $r_url := .RelPermalink }}
|
||||
{{- with .Site.Menus.shortcuts }}
|
||||
{{- range sort . "Weight" }}
|
||||
{{- $s_url := .URL | relLangURL }}
|
||||
{{- if (eq $s_url $r_url) }}
|
||||
{{- $isShortcut = true }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $pages := .Site.Home.Sections }}
|
||||
{{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
|
||||
{{- $currentOrdersectionsby := .Site.Home.Params.ordersectionsby | default $defaultOrdersectionsby }}
|
||||
{{- if $isShortcut }}
|
||||
{{- template "section-print" dict "sect" . "currentnode" $currentNode }}
|
||||
{{- else }}
|
||||
{{- if $isActive }}
|
||||
{{- $pages := .Site.Home.Sections }}
|
||||
{{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
|
||||
{{- $currentOrdersectionsby := .Site.Home.Params.ordersectionsby | default $defaultOrdersectionsby }}
|
||||
{{- if $isShortcut }}
|
||||
{{- template "section-print" dict "sect" . "currentnode" $currentNode }}
|
||||
{{- if or $pages }}
|
||||
<section>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if eq $currentOrdersectionsby "title" }}
|
||||
{{- range $pages.ByTitle }}
|
||||
{{- template "section-tree-print" dict "sect" . "currentnode" $currentNode "isActive" $isActive }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
{{- range $pages.ByWeight }}
|
||||
{{- template "section-tree-print" dict "sect" . "currentnode" $currentNode "isActive" $isActive }}
|
||||
{{- if $isActive }}
|
||||
{{- template "section-print" dict "sect" . "currentnode" $currentNode }}
|
||||
{{- if or $pages }}
|
||||
<section>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if $isActive }}
|
||||
{{- if $pages }}
|
||||
</section>
|
||||
{{- if eq $currentOrdersectionsby "title" }}
|
||||
{{- range $pages.ByTitle }}
|
||||
{{- template "section-tree-print" dict "sect" . "currentnode" $currentNode "isActive" $isActive }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
{{- range $pages.ByWeight }}
|
||||
{{- template "section-tree-print" dict "sect" . "currentnode" $currentNode "isActive" $isActive }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if $isActive }}
|
||||
{{- if $pages }}
|
||||
</section>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
@ -87,13 +91,7 @@
|
|||
{{- define "section-print" }}
|
||||
{{- $currentNode := .currentnode }}
|
||||
{{- with .sect }}
|
||||
{{- $currentNode.Page.Store.Set "nestedHasMathJax" (or ($currentNode.Page.Store.Get "nestedHasMathJax") (.Page.Store.Get "selfHasMathJax")) }}
|
||||
{{- $currentNode.Page.Store.Set "nestedHasMermaid" (or ($currentNode.Page.Store.Get "nestedHasMermaid") (.Page.Store.Get "selfHasMermaid")) }}
|
||||
{{- $currentNode.Page.Store.Set "nestedHasSwagger" (or ($currentNode.Page.Store.Get "nestedHasSwagger") (.Page.Store.Get "selfHasSwagger")) }}
|
||||
{{/* if we have a relative link in a print page, our print URL is one level to deep; so we are making it absolute to our page by prepending the page's permalink */}}
|
||||
{{- $link_prefix := strings.TrimRight "/" .Page.RelPermalink }}
|
||||
{{- $content := partial "content.html" . }}
|
||||
{{- $content = replaceRE "((?:src|href)\\s*=(?:\\s*[\"']\\s*)?)(\\.[^\"'\\s>]*|[\\w]+[^\"'\\s>:]*)([\"'\\s>])" (printf "${1}%s/${2}${3}" $link_prefix) $content }}
|
||||
{{- partial "output-partial.html" (dict "base" "article" "page" . "parameter" (dict "page" . "content" $content)) }}
|
||||
{{- partial "output-partial.html" (dict "base" "output-article" "page" . "parameter" (dict "page" . "content" $content)) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
12
layouts/partials/output-article.html
Normal file
12
layouts/partials/output-article.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
{{- $page := .page }}
|
||||
{{- $content := .content }}
|
||||
{{- $r_url := .RelPermalink }}
|
||||
{{- with $page.OutputFormats.Get (($page.Scratch.Get "relearnOutputFormat") | lower) }}
|
||||
{{- $s_url := .RelPermalink }}
|
||||
{{- if not (eq $s_url $r_url) }}
|
||||
{{/* if we have a relative link in output formats with a path setting, our URLs are one level to deep; so we are making them absolute to our page by prepending the page's permalink */}}
|
||||
{{- $link_prefix := strings.TrimRight "/" $page.Page.RelPermalink }}
|
||||
{{- $content = replaceRE "((?:src|href)\\s*=(?:\\s*[\"']\\s*)?)(\\.[^\"'\\s>]*|[\\w]+[^\"'\\s>:]*)([\"'\\s>])" (printf "${1}%s/${2}${3}" $link_prefix) $content }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- partial "output-partial.html" (dict "base" "article" "page" $page "parameter" (dict "page" $page "content" $content)) }}
|
|
@ -2,22 +2,9 @@
|
|||
{{- $currentNode.Scratch.Delete "relearnIsSelfFound" }}
|
||||
{{- $currentNode.Scratch.Delete "relearnPrevPage" }}
|
||||
{{- $currentNode.Scratch.Delete "relearnNextPage" }}
|
||||
{{- $currentNode.Scratch.Delete "relearnSubPages" }}
|
||||
{{- $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 */}}
|
||||
{{- $wantsMathjax := or (and (ne $currentNode.Params.disableMathjax nil) (not $currentNode.Params.disableMathjax)) (and (ne .Site.Params.disableMathjax nil) (not .Site.Params.disableMathjax)) }}
|
||||
{{- if $wantsMathjax }}
|
||||
{{- $currentNode.Page.Store.Set "selfHasMathjax" true }}
|
||||
{{- end }}
|
||||
{{- $wantsMermaid := or (and (ne $currentNode.Params.disableMermaid nil) (not $currentNode.Params.disableMermaid)) (and (ne .Site.Params.disableMermaid nil) (not .Site.Params.disableMermaid)) }}
|
||||
{{- if $wantsMermaid }}
|
||||
{{- $currentNode.Page.Store.Set "selfHasMermaid" true }}
|
||||
{{- end }}
|
||||
{{- $wantsSwagger := or (and (ne .Params.disableSwagger nil) (not .Params.disableSwagger)) (and (ne .Site.Params.disableSwagger nil) (not .Site.Params.disableSwagger)) }}
|
||||
{{- if $wantsSwagger }}
|
||||
{{- $currentNode.Page.Store.Set "selfHasSwagger" true }}
|
||||
{{- end }}
|
||||
{{- template "relearn-structure" dict "node" .Site.Home "currentnode" $currentNode "hiddenstem" false "hiddencurrent" false "defaultOrdersectionsby" .Site.Params.ordersectionsby }}
|
||||
{{- define "relearn-structure" }}
|
||||
{{- $currentNode := .currentnode }}
|
||||
|
@ -26,6 +13,7 @@
|
|||
{{- $isAncestor := and (not $isSelf) (.node.IsAncestor $currentNode) }}
|
||||
{{- $isOther := and (not $isDescendant) (not $isSelf) (not $isAncestor) }}
|
||||
|
||||
{{- $isChildren := and (.node.Parent) (eq $currentNode.RelPermalink .node.Parent.RelPermalink) }}
|
||||
{{- if $isSelf }}
|
||||
{{- $currentNode.Scratch.Set "relearnIsSelfFound" true }}
|
||||
{{- end}}
|
||||
|
@ -49,24 +37,32 @@
|
|||
{{- end}}
|
||||
{{- end }}
|
||||
|
||||
{{- $currentNode.Scratch.Set "relearnSubPages" .node.Pages }}
|
||||
{{- $pages := .node.Pages }}
|
||||
{{- if .node.IsHome }}
|
||||
{{- $currentNode.Scratch.Set "relearnSubPages" .node.Sections }}
|
||||
{{- $pages = .node.Sections }}
|
||||
{{- else if .node.Sections }}
|
||||
{{- $currentNode.Scratch.Set "relearnSubPages" (.node.Pages | union .node.Sections) }}
|
||||
{{- $pages = (.node.Pages | union .node.Sections) }}
|
||||
{{- end }}
|
||||
{{- $pages := ($currentNode.Scratch.Get "relearnSubPages") }}
|
||||
|
||||
{{- $defaultOrdersectionsby := .defaultOrdersectionsby }}
|
||||
{{- $currentOrdersectionsby := .node.Params.ordersectionsby | default $defaultOrdersectionsby }}
|
||||
|
||||
{{- if eq $currentOrdersectionsby "title"}}
|
||||
{{- range $pages.ByTitle }}
|
||||
{{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hiddenstem" $hidden_stem "hiddencurrent" $hidden_from_current "defaultOrdersectionsby" $defaultOrdersectionsby }}
|
||||
{{- end}}
|
||||
{{- $pages := $pages.ByTitle }}
|
||||
{{- else}}
|
||||
{{- range $pages.ByWeight }}
|
||||
{{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hiddenstem" $hidden_stem "hiddencurrent" $hidden_from_current "defaultOrdersectionsby" $defaultOrdersectionsby }}
|
||||
{{- end}}
|
||||
{{- $pages := $pages.ByWeight }}
|
||||
{{- end }}
|
||||
{{- 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 }}
|
4
layouts/partials/single-article.html
Normal file
4
layouts/partials/single-article.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
{{- $page := .page }}
|
||||
{{- $content := .content }}
|
||||
{{- $page.Page.Store.Set (printf "%sIsNested" (($page.Scratch.Get "relearnOutputFormat") | lower)) false }}
|
||||
{{- partial "output-partial.html" (dict "base" "output-article" "page" $page "parameter" (dict "page" $page "content" $content)) }}
|
Loading…
Reference in a new issue