Improve side menu rendering
This commit is contained in:
parent
561659ed53
commit
8678e82154
6 changed files with 41 additions and 36 deletions
|
@ -43,6 +43,10 @@ Given you have this file structure
|
|||
|
||||
Create file `content/docs/menu/index.md` with content
|
||||
```md
|
||||
---
|
||||
headless: true
|
||||
---
|
||||
|
||||
- [Book Example](/docs/)
|
||||
- [Page One](/docs/page-one)
|
||||
- [Page Two](/docs/page-two)
|
||||
|
@ -87,7 +91,7 @@ type: docs
|
|||
weight: 10
|
||||
|
||||
# (Optional) Set to mark page as top level section in file-tree menu (if BookMenuBundle not set)
|
||||
bookTopSection: true
|
||||
bookRootSection: true
|
||||
|
||||
# (Optional) Set to hide table of contents, overrides global value
|
||||
bookShowToC: false
|
||||
|
|
|
@ -6,6 +6,10 @@ $block-border-radius: 0.15rem;
|
|||
h1, h2, h3, h4, h5 {
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
b, optgroup, strong {
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
|
|
|
@ -25,6 +25,7 @@ a {
|
|||
|
||||
.book-brand {
|
||||
padding: 0 $padding-16;
|
||||
margin-bottom: $padding-8;
|
||||
font-weight: 400;
|
||||
|
||||
a {
|
||||
|
@ -73,7 +74,7 @@ a {
|
|||
}
|
||||
}
|
||||
|
||||
// class used for sections with bookTopSection: true
|
||||
// class used for sections with bookRootSection: true
|
||||
.book-nav-section {
|
||||
margin-bottom: $padding-16;
|
||||
> a { font-weight: 600; }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
<!-- {{ partial "docs/shared" }} -->
|
||||
{{- partial "docs/shared" -}}
|
||||
<html>
|
||||
<head>
|
||||
{{ partial "docs/html-head" . }}
|
||||
|
|
|
@ -1,51 +1,47 @@
|
|||
<!-- Put configured sections list to .Scratch -->
|
||||
{{ template "book-get-root-section" . }}
|
||||
{{ template "book-get-root-section" . }}
|
||||
|
||||
<ul>
|
||||
{{ range .Scratch.Get "BookSections" }}
|
||||
{{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{- range .Scratch.Get "BookSections" -}}
|
||||
{{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }}
|
||||
{{- end -}}
|
||||
|
||||
<!-- Single section of menu (recursive) -->
|
||||
{{ define "book-section" }}
|
||||
<li {{ if .Section.Params.booktopsection }}class="book-nav-section"{{ end }}>
|
||||
|
||||
{{ with .Section}}
|
||||
{{ define "book-section" }} <!-- Single section of menu (recursive) -->
|
||||
<ul>
|
||||
{{ range .Section.Sections }}
|
||||
<li>
|
||||
{{- if .Content -}}
|
||||
<a href="{{ .RelPermalink }}">{{- template "title" . -}}</a>
|
||||
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
|
||||
{{- else -}}
|
||||
{{- template "title" . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
|
||||
</li>
|
||||
{{ end }}
|
||||
|
||||
<ul>
|
||||
{{ range .Section.Sections }}
|
||||
{{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
|
||||
{{ end }}
|
||||
{{ range .Section.Pages }}
|
||||
<li>
|
||||
<a href="{{ .RelPermalink }}" class="{{ if eq $.CurrentPage .Permalink }}active{{ end }}">
|
||||
{{- template "title" . -}}
|
||||
</a>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</li>
|
||||
{{ range .Section.Pages }}
|
||||
<li>
|
||||
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
|
||||
{{ define "book-page-link" }}
|
||||
{{- with .Page -}}
|
||||
<a href="{{ .RelPermalink }}" {{- if eq $.CurrentPage .Permalink }} class="active"{{ end }}>
|
||||
{{- template "title" . -}}
|
||||
</a>
|
||||
{{- end -}}
|
||||
{{ end }}
|
||||
|
||||
{{ define "book-get-root-section" }}
|
||||
<!-- Complex logic to guess page title without .Title specified -->
|
||||
<!-- Complex logic to guess page title without .Title specified -->
|
||||
{{ $bookSection := default "docs" .Site.Params.BookSection }}
|
||||
{{ if eq $bookSection "*" }}
|
||||
{{ .Scratch.Set "BookSections" .Site.Sections }}
|
||||
{{ else }}
|
||||
{{ $bookSections := where .Site.Sections "Section" $bookSection }}
|
||||
{{ .Scratch.Set "BookSections" $bookSections }}
|
||||
|
||||
{{ if eq (len $bookSections) 1 }}
|
||||
{{ $singleSection := index $bookSections 0 }}
|
||||
{{ .Scratch.Set "BookSections" $singleSection.Sections }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
|
@ -3,9 +3,9 @@
|
|||
{{- if .Pages -}}
|
||||
{{ $sections := split (trim .Dir "/") "/" }}
|
||||
{{ $title := index ($sections | last 1) 0 | humanize | title }}
|
||||
{{- default .Title $title -}}
|
||||
{{- default $title .Title -}}
|
||||
{{- else -}}
|
||||
{{ $title := .File | humanize | title }}
|
||||
{{- default .Title $title -}}
|
||||
{{- default $title .Title -}}
|
||||
{{- end -}}
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in a new issue