Skip to content

Commit 2847033

Browse files
committed
Sidebar: Add overview page where _index.md has content
1 parent bcc8a24 commit 2847033

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

exampleSite/content/test-product/sidebar/nesting-1b/_index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
description: Nesting-1b
33
title: Nesting-1b
44
---
5+
6+
1b has some content, but also some nested stuff.
7+
This should cause an overview page to render.

layouts/partials/sidebar-list.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22
{{ $currentPage := .currentPage }}
33
{{ $firstSection := .firstSection }}
44
{{ $idPrefix := .idPrefix }}
5-
65
{{ with $firstSection }}
76
<ul class="sidebar__ul">
87
{{ $pages := .Pages.ByWeight }}
98
{{ range $index, $p := $pages }}
109
{{- $onPage := eq $currentUrl $p.Permalink -}}
1110
{{- $isAncestor := $p.IsAncestor $currentPage -}}
1211
{{- $shouldExpand := or $onPage $isAncestor -}}
13-
{{/* These variables are used to create a unique id to be attached to every link
14-
that accessibility users can correctly "Skip Table Of Contents" */}}
1512
{{- $sectionID := printf "%ssection-%s" $idPrefix (urlize $p.Permalink) -}}
1613
{{- $linkID := printf "%slink-%s" $idPrefix (urlize $p.Permalink) -}}
1714
{{- $nextIndex := add $index 1 -}}
1815
{{- $nextLink := index $pages $nextIndex -}}
19-
2016
{{ if eq $p.Kind "section" }}
2117
<li class="sidebar__section">
2218
<button
@@ -35,6 +31,20 @@
3531
class="sidebar__children"
3632
{{ if not $shouldExpand }}hidden{{ end }}
3733
>
34+
{{ if and .Content (gt (len .Pages) 0) }}
35+
<ul>
36+
<li class="sidebar__page">
37+
<a
38+
href="{{ $p.Permalink }}"
39+
class="sidebar__link {{ if $onPage }}sidebar__link--current{{ end }}"
40+
{{ if $onPage }}aria-current="page"{{ end }}
41+
>
42+
Overview
43+
</a>
44+
</li>
45+
</ul>
46+
{{ end }}
47+
3848
{{ partial "sidebar-list.html" (dict
3949
"firstSection" $p
4050
"currentUrl" $currentUrl
@@ -43,7 +53,6 @@
4353
) }}
4454
</div>
4555
</li>
46-
4756
{{ else if eq $p.Kind "page" }}
4857
{{- $tocHasItems := (in $p.TableOfContents "<li>") -}}
4958
{{- $pageHasTOC := (and $onPage $tocHasItems $p.Params.toc) -}}
@@ -82,15 +91,6 @@
8291
{{ end }}
8392
</li>
8493
{{ end }}
85-
8694
{{ end }}
8795
</ul>
88-
{{ end }}
89-
90-
{{/* {{ if gt (.WordCount) 0 }}
91-
<ul>
92-
<li>
93-
<a href="{{ .Permalink }}" style="color: purple; {{if $onPage}}font-weight: bold;{{end}}">{{ .Title }} - Overview</a>
94-
</li>
95-
</ul>
96-
{{ end }} */}}
96+
{{ end }}

0 commit comments

Comments
 (0)