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
|
Create file `content/docs/menu/index.md` with content
|
||||||
```md
|
```md
|
||||||
|
---
|
||||||
|
headless: true
|
||||||
|
---
|
||||||
|
|
||||||
- [Book Example](/docs/)
|
- [Book Example](/docs/)
|
||||||
- [Page One](/docs/page-one)
|
- [Page One](/docs/page-one)
|
||||||
- [Page Two](/docs/page-two)
|
- [Page Two](/docs/page-two)
|
||||||
|
@ -87,7 +91,7 @@ type: docs
|
||||||
weight: 10
|
weight: 10
|
||||||
|
|
||||||
# (Optional) Set to mark page as top level section in file-tree menu (if BookMenuBundle not set)
|
# (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
|
# (Optional) Set to hide table of contents, overrides global value
|
||||||
bookShowToC: false
|
bookShowToC: false
|
||||||
|
|
|
@ -7,6 +7,10 @@ $block-border-radius: 0.15rem;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b, optgroup, strong {
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ a {
|
||||||
|
|
||||||
.book-brand {
|
.book-brand {
|
||||||
padding: 0 $padding-16;
|
padding: 0 $padding-16;
|
||||||
|
margin-bottom: $padding-8;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
|
|
||||||
a {
|
a {
|
||||||
|
@ -73,7 +74,7 @@ a {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// class used for sections with bookTopSection: true
|
// class used for sections with bookRootSection: true
|
||||||
.book-nav-section {
|
.book-nav-section {
|
||||||
margin-bottom: $padding-16;
|
margin-bottom: $padding-16;
|
||||||
> a { font-weight: 600; }
|
> a { font-weight: 600; }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<!-- {{ partial "docs/shared" }} -->
|
{{- partial "docs/shared" -}}
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
{{ partial "docs/html-head" . }}
|
{{ partial "docs/html-head" . }}
|
||||||
|
|
|
@ -1,37 +1,38 @@
|
||||||
<!-- Put configured sections list to .Scratch -->
|
<!-- Put configured sections list to .Scratch -->
|
||||||
{{ template "book-get-root-section" . }}
|
{{ template "book-get-root-section" . }}
|
||||||
|
|
||||||
<ul>
|
{{- range .Scratch.Get "BookSections" -}}
|
||||||
{{ range .Scratch.Get "BookSections" }}
|
|
||||||
{{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }}
|
{{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }}
|
||||||
{{ end }}
|
{{- end -}}
|
||||||
</ul>
|
|
||||||
|
|
||||||
<!-- Single section of menu (recursive) -->
|
{{ define "book-section" }} <!-- Single section of menu (recursive) -->
|
||||||
{{ define "book-section" }}
|
<ul>
|
||||||
<li {{ if .Section.Params.booktopsection }}class="book-nav-section"{{ end }}>
|
{{ range .Section.Sections }}
|
||||||
|
<li>
|
||||||
{{ with .Section}}
|
|
||||||
{{- if .Content -}}
|
{{- if .Content -}}
|
||||||
<a href="{{ .RelPermalink }}">{{- template "title" . -}}</a>
|
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
{{- template "title" . -}}
|
{{- template "title" . -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
|
{{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
|
||||||
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<ul>
|
|
||||||
{{ range .Section.Sections }}
|
|
||||||
{{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
|
|
||||||
{{ end }}
|
|
||||||
{{ range .Section.Pages }}
|
{{ range .Section.Pages }}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ .RelPermalink }}" class="{{ if eq $.CurrentPage .Permalink }}active{{ end }}">
|
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
|
||||||
{{- template "title" . -}}
|
|
||||||
</a>
|
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
{{ end }}
|
||||||
|
|
||||||
|
{{ define "book-page-link" }}
|
||||||
|
{{- with .Page -}}
|
||||||
|
<a href="{{ .RelPermalink }}" {{- if eq $.CurrentPage .Permalink }} class="active"{{ end }}>
|
||||||
|
{{- template "title" . -}}
|
||||||
|
</a>
|
||||||
|
{{- end -}}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ define "book-get-root-section" }}
|
{{ define "book-get-root-section" }}
|
||||||
|
@ -42,10 +43,5 @@
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ $bookSections := where .Site.Sections "Section" $bookSection }}
|
{{ $bookSections := where .Site.Sections "Section" $bookSection }}
|
||||||
{{ .Scratch.Set "BookSections" $bookSections }}
|
{{ .Scratch.Set "BookSections" $bookSections }}
|
||||||
|
|
||||||
{{ if eq (len $bookSections) 1 }}
|
|
||||||
{{ $singleSection := index $bookSections 0 }}
|
|
||||||
{{ .Scratch.Set "BookSections" $singleSection.Sections }}
|
|
||||||
{{ end }}
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
|
@ -3,9 +3,9 @@
|
||||||
{{- if .Pages -}}
|
{{- if .Pages -}}
|
||||||
{{ $sections := split (trim .Dir "/") "/" }}
|
{{ $sections := split (trim .Dir "/") "/" }}
|
||||||
{{ $title := index ($sections | last 1) 0 | humanize | title }}
|
{{ $title := index ($sections | last 1) 0 | humanize | title }}
|
||||||
{{- default .Title $title -}}
|
{{- default $title .Title -}}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
{{ $title := .File | humanize | title }}
|
{{ $title := .File | humanize | title }}
|
||||||
{{- default .Title $title -}}
|
{{- default $title .Title -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in a new issue