|
1 | 1 | {{ $currentUrl := .currentUrl }} |
2 | | -{{ $firstSection := .firstSection }} |
3 | 2 | {{ $currentPage := .currentPage }} |
| 3 | +{{ $firstSection := .firstSection }} |
| 4 | +{{ $idPrefix := .idPrefix }} |
4 | 5 |
|
5 | 6 | {{ with $firstSection }} |
6 | 7 | <ul class="sidebar__ul"> |
7 | | - {{ range .Pages.ByWeight }} |
8 | | - {{- $onPage := eq $currentUrl .Permalink -}} |
9 | | - {{- $isAncestor := .IsAncestor $currentPage -}} |
| 8 | + {{ $pages := .Pages.ByWeight }} |
| 9 | + {{ range $index, $p := $pages }} |
| 10 | + {{- $onPage := eq $currentUrl $p.Permalink -}} |
| 11 | + {{- $isAncestor := $p.IsAncestor $currentPage -}} |
10 | 12 | {{- $shouldExpand := or $onPage $isAncestor -}} |
11 | | - {{- $sectionID := printf "section-%s" (urlize .Permalink) -}} |
| 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" */}} |
| 15 | + {{- $sectionID := printf "%ssection-%s" $idPrefix (urlize $p.Permalink) -}} |
| 16 | + {{- $linkID := printf "%slink-%s" $idPrefix (urlize $p.Permalink) -}} |
| 17 | + {{- $nextIndex := add $index 1 -}} |
| 18 | + {{- $nextLink := index $pages $nextIndex -}} |
12 | 19 |
|
13 | | - {{ if eq .Kind "section" }} |
| 20 | + {{ if eq $p.Kind "section" }} |
14 | 21 | <li class="sidebar__section"> |
15 | 22 | <button |
| 23 | + id="{{ $linkID }}" |
16 | 24 | class="sidebar__toggle {{ if $isAncestor }}sidebar__toggle--ancestor{{ end }}" |
17 | 25 | aria-expanded="{{ $shouldExpand }}" |
18 | 26 | aria-controls="{{ $sectionID }}" |
19 | 27 | > |
20 | | - <span class="sidebar__toggle-text">{{ .Title }}</span> |
| 28 | + <span class="sidebar__toggle-text">{{ $p.Title }}</span> |
21 | 29 | <span class="sidebar__chevron {{ if $shouldExpand }}sidebar__chevron--open{{ end }}"> |
22 | 30 | {{ partial "lucide" (dict "context" . "icon" "chevron-right") }} |
23 | 31 | </span> |
|
28 | 36 | {{ if not $shouldExpand }}hidden{{ end }} |
29 | 37 | > |
30 | 38 | {{ partial "sidebar-list.html" (dict |
31 | | - "firstSection" . "currentUrl" $currentUrl "currentPage" $currentPage) |
32 | | - }} |
| 39 | + "firstSection" $p |
| 40 | + "currentUrl" $currentUrl |
| 41 | + "currentPage" $currentPage |
| 42 | + "idPrefix" (printf "%s%s-" $idPrefix (urlize $p.Title)) |
| 43 | + ) }} |
33 | 44 | </div> |
34 | 45 | </li> |
35 | 46 |
|
36 | | - {{ else if eq .Kind "page" }} |
| 47 | + {{ else if eq $p.Kind "page" }} |
| 48 | + {{- $tocHasItems := (in $p.TableOfContents "<li>") -}} |
| 49 | + {{- $pageHasTOC := (and $onPage $tocHasItems $p.Params.toc) -}} |
| 50 | + {{- $tocID := printf "%stoc-%s" $idPrefix (urlize $p.Permalink) -}} |
37 | 51 | <li class="sidebar__page"> |
38 | | - {{- $pageHasTOC := (and $onPage .TableOfContents) -}} |
39 | | - {{- $tocID := printf "toc-%s" (urlize .Permalink) -}} |
40 | | - {{- if $pageHasTOC }} |
| 52 | + {{ if $pageHasTOC }} |
41 | 53 | <button |
42 | 54 | class="sidebar__toggle sidebar__link sidebar__link--current" |
43 | 55 | aria-expanded="true" |
44 | 56 | aria-controls="{{ $tocID }}" |
| 57 | + id="{{ $linkID }}" |
45 | 58 | > |
46 | | - <span>{{ .Title }}</span> |
| 59 | + <span>{{ $p.Title }}</span> |
47 | 60 | <span class="sidebar__chevron sidebar__chevron--open"> |
48 | 61 | {{ partial "lucide" (dict "context" . "icon" "chevron-right") }} |
49 | 62 | </span> |
50 | 63 | </button> |
51 | 64 | <div id="{{ $tocID }}" class="sidebar__toc"> |
52 | | - {{ .TableOfContents }} |
| 65 | + {{ if $nextLink }} |
| 66 | + {{- $nextLinkID := printf "%slink-%s" $idPrefix (urlize $nextLink.Permalink) -}} |
| 67 | + <a class="skip-link" href="#{{ $nextLinkID }}">Skip Table of Contents</a> |
| 68 | + {{ else }} |
| 69 | + <a class="skip-link" href="#maincontent">Skip Table of Contents</a> |
| 70 | + {{ end }} |
| 71 | + {{ $p.TableOfContents }} |
53 | 72 | </div> |
54 | 73 | {{ else }} |
55 | 74 | <a |
56 | | - href="{{ .Permalink }}" |
| 75 | + href="{{ $p.Permalink }}" |
| 76 | + id="{{ $linkID }}" |
57 | 77 | class="sidebar__link {{ if $onPage }}sidebar__link--current{{ end }}" |
58 | 78 | {{ if $onPage }}aria-current="page"{{ end }} |
59 | 79 | > |
60 | | - {{ .Title }} |
| 80 | + {{ $p.Title }} |
61 | 81 | </a> |
62 | 82 | {{ end }} |
63 | 83 | </li> |
64 | 84 | {{ end }} |
| 85 | + |
65 | 86 | {{ end }} |
66 | 87 | </ul> |
67 | 88 | {{ end }} |
68 | 89 |
|
69 | | - |
70 | 90 | {{/* {{ if gt (.WordCount) 0 }} |
71 | 91 | <ul> |
72 | 92 | <li> |
|
0 commit comments