mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-22 23:37:53 +00:00
theme: optimize relearn-meta and menu caching #685
This commit is contained in:
parent
d2c86cc8da
commit
56c1f6a841
8 changed files with 96 additions and 68 deletions
|
@ -1,25 +0,0 @@
|
|||
{{- $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 }}
|
|
@ -1,3 +0,0 @@
|
|||
{{- if .Title }}
|
||||
{{- .Render "views/article" }}
|
||||
{{- end }}
|
|
@ -1 +1,4 @@
|
|||
{{- return or (.Params.hidden) (eq .Title "") }}
|
||||
{{- return or
|
||||
.Params.hidden
|
||||
(and .RelPermalink (not (or .Title (partial "title.gotmpl" (dict "page" . "linkTitle" true)))))
|
||||
}}
|
|
@ -1 +1,16 @@
|
|||
{{- return .Scratch.Get "relearnIsHiddenStem" }}
|
||||
{{- $ret := false }}
|
||||
{{- with .page }}
|
||||
{{- $ret = partialCached "_relearn/pageIsHidden.gotmpl" . .Path }}
|
||||
{{- if not $ret }}
|
||||
{{- with .Parent }}
|
||||
{{- if eq . $.to }}
|
||||
{{- /* stop if we reach the top */}}
|
||||
{{- else if partialCached "_relearn/pageIsHidden.gotmpl" . .Path }}
|
||||
{{- $ret = true }}
|
||||
{{- else }}
|
||||
{{- $ret = partialCached "_relearn/pageIsHiddenSelfOrAncestor.gotmpl" (dict "page" . "to" $.to) .Path $.to.Path }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- return $ret }}
|
|
@ -1,2 +1,33 @@
|
|||
{{- .Store.Set "relearnIsNested" true }}
|
||||
{{- partialCached "_relearn/articleWalker.html" . .Path | safeHTML }}
|
||||
{{- partialCached "inline/article-walker" . .Path | safeHTML }}
|
||||
|
||||
{{- define "partials/inline/article-walker" }}
|
||||
{{- $html := "" }}
|
||||
{{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" .) .Path }}
|
||||
{{- range $pages }}
|
||||
{{- if not (partialCached "_relearn/pageIsHidden.gotmpl" . .Path) }}
|
||||
{{- $html = printf "%s%s" $html (partialCached "inline/article-walker" . .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 := "" }}
|
||||
{{- if .Title }}
|
||||
{{- $article = .Render "views/article" }}
|
||||
{{- end }}
|
||||
{{- 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 }}
|
||||
{{- end }}
|
|
@ -26,7 +26,14 @@
|
|||
{{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" .Site.Home) .Site.Home.Path }}
|
||||
{{- $defaultAlwaysopen := .Site.Params.alwaysopen | default false }}
|
||||
{{- range $pages }}
|
||||
{{- partial "inline/menu-walker" (dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen) }}
|
||||
{{- $isSubSelf := eq . $currentNode }}
|
||||
{{- $isSubAncestor := and (not $isSubSelf) (.IsAncestor $currentNode) }}
|
||||
{{- $isSubHidden := or (.Params.hidden) (eq .Title "") }}
|
||||
{{- if or $isSubSelf $isSubAncestor }}
|
||||
{{- partial "partials/inline/menu-walker" (dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen "isSelf" $isSubSelf "isAncestor" $isSubAncestor "isHidden" $isSubHidden ) }}
|
||||
{{- else if not $isSubHidden }}
|
||||
{{- partialCached "partials/inline/menu-walker" (dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen "isSelf" $isSubSelf "isAncestor" $isSubAncestor "isHidden" $isSubHidden) .Path }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -118,42 +125,47 @@
|
|||
{{- $showvisitedlinks := .showvisitedlinks }}
|
||||
{{- $alwaysopen := .alwaysopen }}
|
||||
{{- $currentFileRelPermalink := .currentnode.RelPermalink }}
|
||||
{{- $isSelf := .isSelf }}
|
||||
{{- $isAncestor := .isAncestor }}
|
||||
{{- $isHidden := .isHidden }}
|
||||
{{- with .sect }}
|
||||
{{- $isSelf := eq .RelPermalink $currentFileRelPermalink }}
|
||||
{{- $isAncestor := and (not $isSelf) (.IsAncestor $currentNode) }}
|
||||
{{- $isHidden := or (.Params.hidden) (eq .Title "") }}
|
||||
{{- if or $isAncestor $isSelf (not $isHidden) }}
|
||||
{{- $isActive := $isSelf }}
|
||||
{{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" .) .Path }}
|
||||
{{- $hasVisibleChildren := false }}
|
||||
{{- $isActive := $isSelf }}
|
||||
{{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" .) .Path }}
|
||||
{{- $hasVisibleChildren := false }}
|
||||
{{- range $pages }}
|
||||
{{- $isSubSelf := eq . $currentNode }}
|
||||
{{- $isSubAncestor := and (not $isSubSelf) (.IsAncestor $currentNode) }}
|
||||
{{- $isSubHidden := or (.Params.hidden) (eq .Title "") }}
|
||||
{{- if or $isSubAncestor $isSubSelf (not $isSubHidden) }}
|
||||
{{- $hasVisibleChildren = true }}
|
||||
{{- break }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $title := partial "title.gotmpl" (dict "page" . "linkTitle" true) }}
|
||||
{{- $url := partial "permalink.gotmpl" (dict "to" .) }}
|
||||
{{- if $hasVisibleChildren }}
|
||||
{{- $isCollapsible := or (.Params.collapsibleMenu | default .Site.Params.collapsibleMenu) (not $url) }}
|
||||
{{- $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }}
|
||||
{{- $pageId := md5 .Page }}
|
||||
{{- $isOpen := or $currentAlwaysopen $isSelf $isAncestor }}
|
||||
<li class="{{if $isHidden }}hidden {{end}}{{if $isActive }}active {{end}}{{if (or $isSelf $isAncestor) }}parent {{end}}{{if $currentAlwaysopen}}alwaysopen {{end}}" data-nav-id="{{ $url }}">{{ if $isCollapsible }}<input type="checkbox" id="R-section-{{ $pageId }}" aria-controls="R-subsections-{{ $pageId }}"{{ if $isOpen }} checked{{ end }}><label for="R-section-{{ $pageId }}"><i class="fa-fw fas fa-chevron-down"></i><i class="fa-fw fas fa-chevron-right"></i><span class="a11y-only">{{ T "Submenu" $title }}</span></label>{{ end }}{{ if $url }}<a class="padding" href="{{ $url }}">{{ else }}<span class="padding">{{ end }}
|
||||
{{- partial "menu-pre.html" . }}{{ $title }}{{ partial "menu-post.html" . }}
|
||||
{{- if $url }}{{ if $showvisitedlinks }}<i class="fa-fw fas fa-check read-icon"></i>{{ end }}</a>{{ else }}</span>{{ end }}<ul id="R-subsections-{{ $pageId }}" class="collapsible-menu">
|
||||
{{- $defaultAlwaysopen := .Site.Params.alwaysopen | default true }}
|
||||
{{- range $pages }}
|
||||
{{- $isSubSelf := eq . $currentNode }}
|
||||
{{- $isSubAncestor := and (not $isSubSelf) (.IsAncestor $currentNode) }}
|
||||
{{- $isSubHidden := or (.Params.hidden) (eq .Title "") }}
|
||||
{{- if or $isSubAncestor $isSubSelf (not $isSubHidden) }}
|
||||
{{- $hasVisibleChildren = true }}
|
||||
{{- break }}
|
||||
{{- if or $isSubSelf $isSubAncestor }}
|
||||
{{- partial "partials/inline/menu-walker" (dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen "isSelf" $isSubSelf "isAncestor" $isSubAncestor "isHidden" $isSubHidden) }}
|
||||
{{- else if not $isSubHidden }}
|
||||
{{- partialCached "partials/inline/menu-walker" (dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen "isSelf" $isSubSelf "isAncestor" $isSubAncestor "isHidden" $isSubHidden) .Path }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $title := partial "title.gotmpl" (dict "page" . "linkTitle" true) }}
|
||||
{{- $url := partial "permalink.gotmpl" (dict "to" .) }}
|
||||
{{- if $hasVisibleChildren }}
|
||||
{{- $isCollapsible := or (.Params.collapsibleMenu | default .Site.Params.collapsibleMenu) (not $url) }}
|
||||
{{- $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }}
|
||||
{{- $pageId := md5 .Page }}
|
||||
{{- $isOpen := or $currentAlwaysopen $isSelf $isAncestor }}
|
||||
<li class="{{if $isHidden }}hidden {{end}}{{if $isActive }}active {{end}}{{if (or $isSelf $isAncestor) }}parent {{end}}{{if $currentAlwaysopen}}alwaysopen {{end}}" data-nav-id="{{ $url }}">{{ if $isCollapsible }}<input type="checkbox" id="R-section-{{ $pageId }}" aria-controls="R-subsections-{{ $pageId }}"{{ if $isOpen }} checked{{ end }}><label for="R-section-{{ $pageId }}"><i class="fa-fw fas fa-chevron-down"></i><i class="fa-fw fas fa-chevron-right"></i><span class="a11y-only">{{ T "Submenu" $title }}</span></label>{{ end }}{{ if $url }}<a class="padding" href="{{ $url }}">{{ else }}<span class="padding">{{ end }}
|
||||
{{- partial "menu-pre.html" . }}{{ $title }}{{ partial "menu-post.html" . }}
|
||||
{{- if $url }}{{ if $showvisitedlinks }}<i class="fa-fw fas fa-check read-icon"></i>{{ end }}</a>{{ else }}</span>{{ end }}<ul id="R-subsections-{{ $pageId }}" class="collapsible-menu">
|
||||
{{- $defaultAlwaysopen := .Site.Params.alwaysopen | default true }}
|
||||
{{- range $pages }}
|
||||
{{- partial "inline/menu-walker" (dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen) }}
|
||||
{{- end }}</ul></li>
|
||||
{{- else }}
|
||||
{{- end }}</ul></li>
|
||||
{{- else }}
|
||||
<li class="{{if $isHidden }}hidden {{end}}{{if $isActive }}active {{end}}" data-nav-id="{{ $url }}">{{ if $url }}<a class="padding" href="{{ $url }}">{{ else }}<span class="padding">{{ end }}
|
||||
{{- partial "menu-pre.html" . }}{{ $title }}{{ partial "menu-post.html" . }}
|
||||
{{- if $url }}{{ if $showvisitedlinks }}<i class="fa-fw fas fa-check read-icon"></i>{{ end }}</a>{{ else }}</span>{{ end }}</li>
|
||||
{{- end }}
|
||||
{{- partial "menu-pre.html" . }}{{ $title }}{{ partial "menu-post.html" . }}
|
||||
{{- if $url }}{{ if $showvisitedlinks }}<i class="fa-fw fas fa-check read-icon"></i>{{ end }}</a>{{ else }}</span>{{ end }}</li>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
|
@ -10,7 +10,8 @@
|
|||
{{- $ver := printf "<meta name=\"generator\" content=\"%s %s\">" "Relearn" $ver }}
|
||||
{{ $ver | safeHTML }}
|
||||
{{- end }}
|
||||
{{- if not (and .Title .RelPermalink (or (ne .Site.Params.disableSeoHiddenPages true) (not (partialCached "_relearn/pageIsHiddenSelfOrAncestor.gotmpl" (dict "page" . "to" .Site.Home) .Path .Site.Home.Path) ) ) ) }}
|
||||
{{- $title := partial "title.gotmpl" (dict "page" . "linkTitle" true) }}
|
||||
{{- if not (and $title .RelPermalink (or (ne .Site.Params.disableSeoHiddenPages true) (not (partialCached "_relearn/pageIsHiddenSelfOrAncestor.gotmpl" (dict "page" . "to" .Site.Home) .Path .Site.Home.Path) ) ) ) }}
|
||||
<meta name="robots" content="noindex, nofollow, noarchive, noimageindex">
|
||||
{{- end }}
|
||||
<meta name="description" content="{{ with trim (or .Description .Summary | plainify | htmlUnescape) "\n\r\t " }}{{ . }}{{ end }}">
|
||||
|
|
|
@ -13,8 +13,6 @@ section: {{- .Section }}
|
|||
{{- $currentNode.Scratch.Delete "relearnIsSelfFound" }}
|
||||
{{- $currentNode.Scratch.Delete "relearnPrevPage" }}
|
||||
{{- $currentNode.Scratch.Delete "relearnNextPage" }}
|
||||
{{- $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 */}}
|
||||
{{- template "relearn-structure" dict "node" .Site.Home "currentnode" $currentNode "hiddenstem" false "hiddencurrent" false }}
|
||||
{{- if not ($currentNode.Scratch.Get "relearnIsSelfFound") }}
|
||||
{{- if not $currentNode.IsHome }}
|
||||
|
@ -39,10 +37,6 @@ section: {{- .Section }}
|
|||
{{- $hidden_node := or (.node.Params.hidden) (eq .node.Title "") }}
|
||||
{{- $hidden_stem := or $hidden_node .hiddenstem }}
|
||||
{{- $hidden_from_current := or (and $hidden_node (not $isAncestor) (not $isSelf) ) (and .hiddencurrent (or $isPreSelf $isPostSelf $isDescendant) ) }}
|
||||
{{- if $isSelf }}
|
||||
{{- $currentNode.Scratch.Set "relearnIsHiddenNode" $hidden_node }}
|
||||
{{- $currentNode.Scratch.Set "relearnIsHiddenStem" $hidden_stem }}
|
||||
{{- end }}
|
||||
|
||||
{{- if or (eq $currentNode.Kind "home") (eq $currentNode.Kind "section") (eq $currentNode.Kind "page") }}
|
||||
{{- if not $hidden_from_current }}
|
||||
|
|
Loading…
Reference in a new issue