|
| 1 | +{{ $bookSection := default "posts" .Site.Params.BookSection }} |
| 2 | +{{ if eq $bookSection "*" }} |
| 3 | + {{ $bookSection = "/" }}{{/* Backward compatibility */}} |
| 4 | +{{ end }} |
| 5 | + |
| 6 | +{{ with .Site.GetPage $bookSection .CurrentSection.Title }} |
| 7 | + {{ template "book-section-children" (dict "Section" . "CurrentPage" $) }} |
| 8 | +{{ end }} |
| 9 | + |
| 10 | +{{ define "book-section-children" }}{{/* (dict "Section" .Section "CurrentPage" .CurrentPage) */}} |
| 11 | + <ul> |
| 12 | + {{ range (where .Section.Pages "Params.bookhidden" "ne" true) }} |
| 13 | + {{ if .IsSection }} |
| 14 | + <li {{- if .Params.BookFlatSection }} class="book-section-flat" {{ end -}}> |
| 15 | + {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }} |
| 16 | + {{ template "book-section-children" (dict "Section" . "CurrentPage" $.CurrentPage) }} |
| 17 | + </li> |
| 18 | + {{ else if and .IsPage .Content }} |
| 19 | + <li> |
| 20 | + {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }} |
| 21 | + </li> |
| 22 | + {{ end }} |
| 23 | + {{ end }} |
| 24 | + </ul> |
| 25 | +{{ end }} |
| 26 | + |
| 27 | +{{ define "book-page-link" }}{{/* (dict "Page" .Page "CurrentPage" .CurrentPage) */}} |
| 28 | + {{ $current := eq .CurrentPage .Page }} |
| 29 | + {{ $ancestor := .Page.IsAncestor .CurrentPage }} |
| 30 | + |
| 31 | + {{ if .Page.Params.bookCollapseSection }} |
| 32 | + <input type="checkbox" id="section-{{ md5 .Page }}" class="toggle" {{ if or $current $ancestor }}checked{{ end }} /> |
| 33 | + <label for="section-{{ md5 .Page }}" class="flex justify-between"> |
| 34 | + <a {{ if .Page.Content }}href="{{ .Page.Permalink }}"{{ else }}role="button"{{ end }} class="{{ if $current }}active{{ end }}"> |
| 35 | + {{- partial "title" .Page -}} |
| 36 | + </a> |
| 37 | + </label> |
| 38 | + {{ else if .Page.Content }} |
| 39 | + <a href="{{ .Page.Permalink }}" class="{{ if $current }} active{{ end }}"> |
| 40 | + {{- partial "title" .Page -}} |
| 41 | + </a> |
| 42 | + {{ else }} |
| 43 | + <span>{{- partial "title" .Page -}}</span> |
| 44 | + {{ end }} |
| 45 | +{{ end }} |
0 commit comments