Fix issue where all pages appear on root level if children keyword is used on home page.

This commit is contained in:
Christopher Greaves 2019-03-12 19:30:32 +00:00 committed by Matthew Taylor
parent 55b1b8ee83
commit 8cd64b1bc9

View file

@ -4,13 +4,20 @@
{{ $withDescription := .Get "description" | default false }} {{ $withDescription := .Get "description" | default false }}
{{ $sortTerm := .Get "sort" | default "Weight" }} {{ $sortTerm := .Get "sort" | default "Weight" }}
<ul class="children children-{{$style}}"> <ul class="children children-{{$style}}">
{{ .Scratch.Set "pages" .Page.Pages }} {{ .Scratch.Set "pages" .Page.Pages }}
{{ if .Page.Sections}}
{{ .Scratch.Set "pages" (.Page.Pages | union .Page.Sections) }} {{if .Page.IsHome}}
{{end}} <!-- Add pages that are in root dir -->
{{ $pages := (.Scratch.Get "pages") }} {{ $rootPage := where .Page.Pages "Dir" "" }}
{{ .Scratch.Set "pages" (.Page.Sections | union $rootPage)}}
{{else}}
{{ if .Page.Sections}}
{{ .Scratch.Set "pages" (.Page.Pages | union .Page.Sections) }}
{{end}}
{{end}}
{{ $pages := (.Scratch.Get "pages") }}
{{if eq $sortTerm "Weight"}} {{if eq $sortTerm "Weight"}}
{{template "childs" dict "menu" $pages.ByWeight "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}} {{template "childs" dict "menu" $pages.ByWeight "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}}
@ -33,64 +40,61 @@
{{ range .menu }} {{ range .menu }}
{{ if and .Params.hidden (not $.showhidden) }} {{ if and .Params.hidden (not $.showhidden) }}
{{else}} {{else}}
{{if not .IsHome}}
{{if hasPrefix $.style "h"}}
{{$num := sub ( int (trim $.style "h") ) 1 }}
{{$numn := add $num $.count }}
{{(printf "<h%d>" $numn)|safeHTML}}
<a href="{{.URL}}" >{{ .Title }}</a>
{{(printf "</h%d>" $numn)|safeHTML}}
{{if hasPrefix $.style "h"}}
{{$num := sub ( int (trim $.style "h") ) 1 }}
{{$numn := add $num $.count }}
{{(printf "<h%d>" $numn)|safeHTML}}
<a href="{{.URL}}" >{{ .Title }}</a>
{{(printf "</h%d>" $numn)|safeHTML}}
{{else}}
{{(printf "<%s>" $.style)|safeHTML}}
<a href="{{.URL}}" >{{ .Title }}</a>
{{(printf "</%s>" $.style)|safeHTML}}
{{end}}
{{if $.description}}
{{if .Description}}
<p>{{.Description}}</p>
{{else}} {{else}}
<p>{{.Summary}}</p> {{(printf "<%s>" $.style)|safeHTML}}
<a href="{{.URL}}" >{{ .Title }}</a>
{{(printf "</%s>" $.style)|safeHTML}}
{{end}}
{{if $.description}}
{{if .Description}}
<p>{{.Description}}</p>
{{else}}
<p>{{.Summary}}</p>
{{end}}
{{end}} {{end}}
{{end}} {{end}}
{{ if lt $.count $.depth}} {{ if lt $.count $.depth}}
{{if eq $.style "li"}}
<ul>
{{end}}
{{ .Scratch.Set "pages" .Pages }}
{{ if .Sections}}
{{ .Scratch.Set "pages" (.Pages | union .Sections) }}
{{end}}
{{ $pages := (.Scratch.Get "pages") }}
{{if eq $.sortTerm "Weight"}} {{if eq $.style "li"}}
{{template "childs" dict "menu" $pages.ByWeight "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}} <ul>
{{else if eq $.sortTerm "Name"}} {{end}}
{{template "childs" dict "menu" $pages.ByTitle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{else if eq $.sortTerm "PublishDate"}} {{ if .Sections}}
{{template "childs" dict "menu" $pages.ByPublishDate "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}} {{ .Scratch.Set "pages" (.Pages | union .Sections) }}
{{else if eq $.sortTerm "Date"}} {{else}}
{{template "childs" dict "menu" $pages.ByDate "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}} {{ .Scratch.Set "pages" .Pages }}
{{else if eq $.sortTerm "Length"}} {{end}}
{{template "childs" dict "menu" $pages.ByLength "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{else}} {{ $pages := (.Scratch.Get "pages") }}
{{template "childs" dict "menu" $pages "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{end}} {{if eq $.sortTerm "Weight"}}
{{if eq $.style "li"}} {{template "childs" dict "menu" $pages.ByWeight "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
</ul> {{else if eq $.sortTerm "Name"}}
{{end}} {{template "childs" dict "menu" $pages.ByTitle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{else if eq $.sortTerm "PublishDate"}}
{{template "childs" dict "menu" $pages.ByPublishDate "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{else if eq $.sortTerm "Date"}}
{{template "childs" dict "menu" $pages.ByDate "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{else if eq $.sortTerm "Length"}}
{{template "childs" dict "menu" $pages.ByLength "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{else}}
{{template "childs" dict "menu" $pages "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{end}}
{{if eq $.style "li"}}
</ul>
{{end}}
{{end}} {{end}}
{{end}} {{end}}
{{end}} {{end}}
{{end}} {{end}}