Skip to content
Snippets Groups Projects
Commit 2c5cd46e authored by Sietze van Buuren's avatar Sietze van Buuren Committed by Andre Moreira Magalhaes
Browse files

Nested recursive sections in nav bar

parent 115cd303
No related branches found
No related tags found
1 merge request!414Nested recursive sections in nav bar
Pipeline #371318 passed with warnings
......@@ -196,47 +196,23 @@
<!-- Previous Sidebar -->
<!-- Preparations for nested menus -->
{{- $children := partialCached "prep-nested-menu.html" . -}}
<nav class="sidebar sidebar-hidden" id="site-sidebar">
<ul>
{{ $section := .FirstSection }}
{{ range sort .Site.Sections.ByTitle }}
<li class="sidebar-section">
<a href="{{ .Permalink | relLangURL }}"
{{ if eq .FirstSection $section }}id="sidebar-focus" class="sidebar-focus"{{end}}>{{ .Title }}</a>
<div class="sidebar-pages">
<ul>
<!--
{{ range .Pages.ByTitle }}
<li class="sidebar-page">
<a href="{{ .Permalink | relLangURL }}">{{ .Name }}</a>
</li>
{{ end }}
-->
{{ range .Pages.ByWeight }}
{{ if and (lt .Params.weight 100) (ne .Params.weight nil) }}
{{ partial "nav_page_item.html" ( dict "dot" . "currentPage" $.Page.RelPermalink ) }}
{{end}}
{{end}}
{{ range .Pages.ByTitle }}
{{ if or (eq .Params.weight 100) (eq .Params.weight nil) }}
{{ partial "nav_page_item.html" ( dict "dot" . "currentPage" $.Page.RelPermalink ) }}
{{end}}
{{end}}
{{ range .Pages.ByWeight }}
{{ if gt .Params.weight 100 }}
{{ partial "nav_page_item.html" ( dict "dot" . "currentPage" $.Page.RelPermalink ) }}
{{end}}
{{end}}
</ul>
</div>
</li>
{{ end }}
</ul>
<ul>
{{- $section := .FirstSection -}}
{{- range sort .Site.Sections.ByTitle -}}
<li class="sidebar-section">
<a href="{{ .Permalink | relLangURL }}" {{ if eq .FirstSection $section }}id="sidebar-focus" class="sidebar-focus"{{end}}>{{ .Title }}</a>
<div class="sidebar-pages">
<ul class="nestedmenu">
{{- partialCached "ordered-nested-menu.html" (dict "context" . "pagecontext" $.Page "regularpages" .RegularPages "children" $children) .Section -}}
</ul>
</div>
</li>
{{- end -}}
</ul>
</nav>
<!-- end of Previous Sidebar -->
<!-- adapted from https://hugocodex.org/blog/creating-a-menu-with-nested-pages/ -->
{{- $section_children := (index $.children $.context.Section) -}}
{{- range $pg := (cond $.sort_by_weight $.regularpages.ByWeight $.regularpages.ByTitle) -}}
{{- $show_page := (cond $.sort_by_weight (cond $.weighted_top (and (lt .Params.weight 100) (ne .Params.weight nil) ) (gt .Params.weight 100) ) (or (eq .Params.weight 100) (eq .Params.weight nil) ) ) -}}
{{- if (and $show_page .File $.context.File $.pagecontext.File) -}}
{{- $filepath := replace (print .File.Dir (replace .File.BaseFileName "_index" "") "/") "//" "/" -}}
{{- $contextfilepath := replace (print $.context.File.Dir (replace $.context.File.BaseFileName "_index" "") "/") "//" "/" -}}
{{- $has_children := (in ($section_children) $filepath) -}}
{{- if eq (len (split $filepath "/")) (add (len (split $contextfilepath "/")) 1) -}}
{{- if and (in $filepath $contextfilepath) (ne $contextfilepath $filepath) -}}
<li class="sidebar-page{{ if $has_children }} haschildren{{ end }}">
<a href="{{ .Permalink }}">{{ .Title }}</a>
{{- if $has_children -}}
<ul class="nestedmenu">
{{- partial "ordered-nested-menu.html" (dict "context" . "pagecontext" $.pagecontext "regularpages" $.regularpages "children" $.children) -}}
</ul>
{{- end -}}
</li>
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- partial "nested-menu.html" (dict "context" $.context "pagecontext" $.pagecontext "regularpages" $.regularpages "children" $.children "sort_by_weight" true "weighted_top" true) -}}
{{- partial "nested-menu.html" (dict "context" $.context "pagecontext" $.pagecontext "regularpages" $.regularpages "children" $.children "sort_by_weight" false "weighted_top" false) -}}
{{- partial "nested-menu.html" (dict "context" $.context "pagecontext" $.pagecontext "regularpages" $.regularpages "children" $.children "sort_by_weight" true "weighted_top" false) -}}
\ No newline at end of file
<!-- see https://hugocodex.org/blog/creating-a-menu-with-nested-pages/-->
{{- $out := dict -}}
{{- range sort .Site.Sections.ByTitle -}}
{{- with .Site.GetPage (print "/" .Section "/_index.md") -}}
{{- $children := slice -}}
{{- range .RegularPages -}}
{{- if .File -}}
{{- $urlparts := split (print .File.Dir .File.BaseFileName) "/" -}}
{{- range $index, $value := (first (len $urlparts) $urlparts) -}}
{{- $children = $children | append (print (delimit (first $index $urlparts) "/") "/") -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $out = merge $out (dict .Section $children) -}}
{{- end -}}
{{- end -}}
{{- return $out -}}
\ No newline at end of file
{{- $page_link := (.Get 0) -}}
<a href="{{ ref . $page_link }}">{{ with .Site.GetPage $page_link }}{{ .Title }}{{ end }}</a>
\ No newline at end of file
......@@ -679,7 +679,7 @@ pre {
/* :not(.chroma) to make sure we don't apply this to code blocks, which will
have their padding added inside 'td'. */
pre:not(.chroma) {
padding: 8px;
padding: 8px;
}
pre code {
white-space: pre;
......@@ -699,8 +699,8 @@ td.gutter pre {
background-color: #fff;
}
.highlight > .chroma {
overflow-x: auto;
margin-bottom: 30px;
overflow-x: auto;
margin-bottom: 30px;
}
.highlight > pre {
padding: 0;
......@@ -901,10 +901,57 @@ div.notices.tip p:first-child:after {
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.sidebar-page-focus {
font-weight: bold !important;
ul.nestedmenu {
padding-left: 0;
margin-left: 0;
}
ul.nestedmenu li {
list-style: none;
padding-left: 1.5rem !important;
position: relative;
}
ul.nestedmenu li > ul {
display: none;
}
ul.nestedmenu li::before {
font-family: "Font Awesome 5 Free" !important;
left: 0;
position: absolute;
content: "•";
transform: translate(0%, 8%);
width: 1.25rem;
text-align: center;
font-weight: bold;
font-size: 10pt;
}
ul.nestedmenu li.haschildren::before {
font-family: "Font Awesome 5 Free" !important;
content: "\25BC";
transform: scaleX(0.75) rotate(-90deg) translate(-10%, -5%);
font-size: 9pt;
font-weight: bold;
}
ul.nestedmenu li.haschildren.expanded::before {
transform: scaleY(0.75) rotate(0deg) translate(0%, 0%);
}
ul.nestedmenu li.expanded > ul {
display: block;
margin-bottom: 0px !important;
}
ul.nestedmenu li > a {
color: #444444 !important;
}
ul.nestedmenu li.active > a {
color: #e67d1e !important;
font-weight: bold !important;
}
/* --- PDF Note --- */
div.pdflink {
......@@ -933,7 +980,7 @@ div.pdflink {
}
.pdflink a:hover {
text-decoration: none;
text-decoration: none;
border-color: #e67d1e;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment