Simplify partials

This commit is contained in:
Alex Shpak 2018-09-12 14:36:16 +02:00
parent ca37d7488c
commit 80cca5b1be
4 changed files with 29 additions and 36 deletions

View file

@ -10,7 +10,18 @@
<div class="pure-g"> <div class="pure-g">
<div class="pure-u book-nav"> <div class="pure-u book-nav">
{{ partial "docs/nav" . }} <nav role="navigation">
{{ partial "docs/nav-brand" . }}
{{ partial "docs/inject/nav-before" . }}
{{ if .Site.Params.BookMenuBundle }}
{{ partial "docs/nav-bundle" . }}
{{ else }}
{{ partial "docs/nav-filetree" . }}
{{ end }}
{{ partial "docs/inject/nav-after" . }}
</nav>
</div> </div>
<div class="pure-u book-content"> <div class="pure-u book-content">
<div class="pure-g"> <div class="pure-g">

View file

@ -1,8 +1,3 @@
<nav role="navigation"> {{ with .Site.GetPage .Site.Params.BookMenuBundle }}
{{ partial "docs/nav-brand" . }}
{{ partial "docs/inject/nav-before" . }}
{{ with .Site.GetPage .Site.Params.BookMenuBundle }}
{{- .Content -}} {{- .Content -}}
{{ end }} {{ end }}
{{ partial "docs/inject/nav-after" . }}
</nav>

View file

@ -9,21 +9,13 @@
{{ $singleSection := index $bookSections 0 }} {{ $singleSection := index $bookSections 0 }}
{{ .Scratch.Set "BookSections" $singleSection.Sections }} {{ .Scratch.Set "BookSections" $singleSection.Sections }}
{{ end }} {{ end }}
{{ end }} {{ end }}
<nav role="navigation"> <ul>
{{ partial "docs/nav-brand" . }}
{{ partial "docs/inject/nav-before" . }}
<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> </ul>
{{ partial "docs/inject/nav-after" . }}
</nav>
<!-- Single section of menu (recursive) --> <!-- Single section of menu (recursive) -->
{{ define "book-section" }} {{ define "book-section" }}
@ -47,18 +39,18 @@
<!-- Menu Heading --> <!-- Menu Heading -->
{{ define "book-heading" }} {{ define "book-heading" }}
{{ $sections := split (trim .Dir "/") "/" }} {{ $sections := split (trim .Dir "/") "/" }}
{{ $title := index ($sections | last 1) 0 | humanize | title }} {{ $title := index ($sections | last 1) 0 | humanize | title }}
{{ $title := default .Title $title }} {{ $title := default .Title $title }}
{{ if .Content }} {{ if .Content }}
<a href="{{ .RelPermalink }}"> <a href="{{ .RelPermalink }}">
{{- $title -}} {{- $title -}}
</a> </a>
{{ else }} {{ else }}
<a> <a>
{{- $title -}} {{- $title -}}
</a> </a>
{{ end }} {{ end }}
{{ end }} {{ end }}

View file

@ -1,5 +0,0 @@
{{ if .Site.Params.BookMenuBundle }}
{{ partial "docs/nav-bundle" . }}
{{ else }}
{{ partial "docs/nav-tree" . }}
{{ end }}