mirror of
https://github.com/alex-shpak/hugo-book.git
synced 2024-12-03 08:25:17 +00:00
98d19b8e95
This change allows hugo to build pages correcly when `canonifyURLs = false` and `relativeURLs = true`. Otherwise the links on the menu will be canonicalized regardless of configuration. This results in broken sites in a number of situations, such as sites served behind a reverse-proxy that don't want to account for the prefix they're served under.
46 lines
1.8 KiB
HTML
46 lines
1.8 KiB
HTML
{{ $bookSection := default "docs" .Site.Params.BookSection }}
|
|
{{ if eq $bookSection "*" }}
|
|
{{ $bookSection = "/" }}{{/* Backward compatibility */}}
|
|
{{ end }}
|
|
|
|
{{ with .Site.GetPage $bookSection }}
|
|
{{ template "book-section-children" (dict "Section" . "CurrentPage" $) }}
|
|
{{ end }}
|
|
|
|
{{ define "book-section-children" }}{{/* (dict "Section" .Section "CurrentPage" .CurrentPage) */}}
|
|
<ul>
|
|
{{ range (where .Section.Pages "Params.bookhidden" "ne" true) }}
|
|
{{ if .IsSection }}
|
|
<li {{- if .Params.BookFlatSection }} class="book-section-flat" {{ end -}}>
|
|
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
|
|
{{ template "book-section-children" (dict "Section" . "CurrentPage" $.CurrentPage) }}
|
|
</li>
|
|
{{ else if and .IsPage .Content }}
|
|
<li>
|
|
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
|
|
</li>
|
|
{{ end }}
|
|
{{ end }}
|
|
</ul>
|
|
{{ end }}
|
|
|
|
{{ define "book-page-link" }}{{/* (dict "Page" .Page "CurrentPage" .CurrentPage) */}}
|
|
{{ $current := eq .CurrentPage .Page }}
|
|
{{ $ancestor := .Page.IsAncestor .CurrentPage }}
|
|
|
|
{{ if .Page.Params.bookCollapseSection }}
|
|
<input type="checkbox" id="section-{{ md5 .Page }}" class="toggle" {{ if or $current $ancestor }}checked{{ end }} />
|
|
<label for="section-{{ md5 .Page }}" class="flex justify-between">
|
|
<a {{ if .Page.Content }}href="{{ .Page.RelPermalink }}"{{ else }}role="button"{{ end }} class="{{ if $current }}active{{ end }}">
|
|
{{- partial "docs/title" .Page -}}
|
|
</a>
|
|
</label>
|
|
{{ else if .Page.Content }}
|
|
<a href="{{ .Page.RelPermalink }}" class="{{ if $current }} active{{ end }}">
|
|
{{- partial "docs/title" .Page -}}
|
|
</a>
|
|
{{ else }}
|
|
<span>{{- partial "docs/title" .Page -}}</span>
|
|
{{ end }}
|
|
{{ end }}
|