From 0b30289d9f3520144bb37caa009d8953cde0e3d6 Mon Sep 17 00:00:00 2001 From: Alex Shpak Date: Mon, 22 Apr 2019 19:17:39 +0200 Subject: #43, Update tree menu rendering to support multiple sections --- layouts/partials/docs/menu-filetree.html | 76 ++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 32 deletions(-) (limited to 'layouts/partials/docs/menu-filetree.html') diff --git a/layouts/partials/docs/menu-filetree.html b/layouts/partials/docs/menu-filetree.html index 8530656..b0f28c0 100644 --- a/layouts/partials/docs/menu-filetree.html +++ b/layouts/partials/docs/menu-filetree.html @@ -1,47 +1,59 @@ - -{{ template "book-get-root-section" . }} +{{ $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 }} +{{ end }} -{{- range .Scratch.Get "BookSections" -}} - {{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }} -{{- end -}} -{{ define "book-section" }} +{{ $sections := .Scratch.Get "BookSections" }} +{{/* If there is only one section to render then render its children, else render all sections */}} +{{ if eq (len $sections) 1 }} + {{ with index $sections 0 }} + {{ template "book-section-children" (dict "Section" . "CurrentPage" $.Permalink) }} + {{ end }} +{{ else }} +{{ end }} - {{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }} - +{{ define "book-section" }} +{{ with .Section }} +
  • + {{ if .Content }} + {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }} + {{ else }} + {{ template "title" . }} {{ end }} - {{ range .Section.Pages }} + {{ template "book-section-children" (dict "Section" . "CurrentPage" $.CurrentPage) }} +
  • +{{ end }} +{{ end }} + +{{ define "book-section-children" }} +{{ with .Section }} + {{ end }} +{{ end }} {{ define "book-page-link" }} -{{- with .Page -}} - - {{- template "title" . -}} - -{{- end -}} +{{ with .Page }} + + {{ template "title" . }} + +{{ end }} {{ end }} - -{{ define "book-get-root-section" }} - - {{ $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 }} - {{ end }} -{{ end }} \ No newline at end of file -- cgit v1.2.3