mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 15:57:57 +00:00
83 lines
3.7 KiB
HTML
83 lines
3.7 KiB
HTML
|
{{- $isActive := .IsHome }}
|
||
|
{{- $currentNode := . }}
|
||
|
{{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
|
||
|
{{- $currentOrdersectionsby := .Site.Home.Params.ordersectionsby | default $defaultOrdersectionsby }}
|
||
|
{{- $pages := .Site.Home.Sections }}
|
||
|
{{- if $isActive }}
|
||
|
{{- template "section-print" dict "sect" . "currentnode" $currentNode }}
|
||
|
{{- if or .IsHome .Params.chapter $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 }}
|
||
|
{{- end }}
|
||
|
{{- end }}
|
||
|
{{- if $isActive }}
|
||
|
{{- if or .IsHome .Params.chapter $pages }}
|
||
|
</section>
|
||
|
{{- end }}
|
||
|
{{- end }}
|
||
|
{{- define "section-tree-print" }}
|
||
|
{{- $isActive := .isActive }}
|
||
|
{{- $currentNode := .currentnode }}
|
||
|
{{- $currentFileRelPermalink := .currentnode.RelPermalink }}
|
||
|
{{- with .sect }}
|
||
|
{{- $currentIsActive := eq .RelPermalink $currentFileRelPermalink }}
|
||
|
{{- $isActive = or $currentIsActive $isActive }}
|
||
|
{{- $relearnIsHiddenFrom := index ($currentNode.Scratch.Get "relearnIsHiddenFrom") .RelPermalink }}
|
||
|
{{- $hidden := and $relearnIsHiddenFrom (not $.showhidden) (not (.IsAncestor $currentNode)) }}
|
||
|
{{- if $hidden }}
|
||
|
{{- else if or .IsSection .IsHome }}
|
||
|
{{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
|
||
|
{{- $currentOrdersectionsby := .Params.ordersectionsby | default $defaultOrdersectionsby }}
|
||
|
{{- $pages := .Pages }}
|
||
|
{{- if .Page.IsHome }}
|
||
|
{{- $pages = .Sections }}
|
||
|
{{- else if .Page.Sections}}
|
||
|
{{- $pages = (.Pages | union .Sections) }}
|
||
|
{{- end }}
|
||
|
{{- if $isActive }}
|
||
|
{{- template "section-print" dict "sect" . "currentnode" $currentNode }}
|
||
|
{{- if or .IsHome .Params.chapter $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 }}
|
||
|
{{- end }}
|
||
|
{{- end }}
|
||
|
{{- if $isActive }}
|
||
|
{{- if or .IsHome .Params.chapter $pages }}
|
||
|
</section>
|
||
|
{{- end }}
|
||
|
{{- end }}
|
||
|
{{- else }}
|
||
|
{{- if $isActive }}
|
||
|
{{- template "section-print" dict "sect" . "currentnode" $currentNode }}
|
||
|
{{- end }}
|
||
|
{{- end }}
|
||
|
{{- end }}
|
||
|
{{- end }}
|
||
|
{{- define "section-print" }}
|
||
|
{{- $currentNode := .currentnode }}
|
||
|
{{- with .sect }}
|
||
|
{{- $currentNode.Page.Store.Set "printHasMermaid" (or ($currentNode.Page.Store.Get "printHasMermaid") (.Page.Store.Get "htmlHasMermaid")) }}
|
||
|
{{- $currentNode.Page.Store.Set "printHasSwagger" (or ($currentNode.Page.Store.Get "printHasSwagger") (.Page.Store.Get "htmlHasSwagger")) }}
|
||
|
{{/* 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 "article.html" (dict "page" . "content" $content) }}
|
||
|
{{- end }}
|
||
|
{{- end }}
|