From 8cd64b1bc99e40bb090631fd4975981cebaf2035 Mon Sep 17 00:00:00 2001
From: Christopher Greaves <28542943+Chris-Greaves@users.noreply.github.com>
Date: Tue, 12 Mar 2019 19:30:32 +0000
Subject: [PATCH] Fix issue where all pages appear on root level if children
keyword is used on home page.
---
layouts/shortcodes/children.html | 114 ++++++++++++++++---------------
1 file changed, 59 insertions(+), 55 deletions(-)
diff --git a/layouts/shortcodes/children.html b/layouts/shortcodes/children.html
index fe208398c5..bff5a32b77 100644
--- a/layouts/shortcodes/children.html
+++ b/layouts/shortcodes/children.html
@@ -4,13 +4,20 @@
{{ $withDescription := .Get "description" | default false }}
{{ $sortTerm := .Get "sort" | default "Weight" }}
-
{{ .Scratch.Set "pages" .Page.Pages }}
- {{ if .Page.Sections}}
- {{ .Scratch.Set "pages" (.Page.Pages | union .Page.Sections) }}
- {{end}}
- {{ $pages := (.Scratch.Get "pages") }}
+
+ {{if .Page.IsHome}}
+
+ {{ $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"}}
{{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 }}
{{ if and .Params.hidden (not $.showhidden) }}
{{else}}
-
+ {{if not .IsHome}}
+ {{if hasPrefix $.style "h"}}
+ {{$num := sub ( int (trim $.style "h") ) 1 }}
+ {{$numn := add $num $.count }}
-{{if hasPrefix $.style "h"}}
- {{$num := sub ( int (trim $.style "h") ) 1 }}
- {{$numn := add $num $.count }}
+ {{(printf "" $numn)|safeHTML}}
+ {{ .Title }}
+ {{(printf "" $numn)|safeHTML}}
-{{(printf "" $numn)|safeHTML}}
-{{ .Title }}
-{{(printf "" $numn)|safeHTML}}
-
-{{else}}
-{{(printf "<%s>" $.style)|safeHTML}}
-{{ .Title }}
-{{(printf "%s>" $.style)|safeHTML}}
-{{end}}
-
-
-
-
-
- {{if $.description}}
- {{if .Description}}
-{{.Description}}
{{else}}
-{{.Summary}}
+ {{(printf "<%s>" $.style)|safeHTML}}
+ {{ .Title }}
+ {{(printf "%s>" $.style)|safeHTML}}
+ {{end}}
+
+ {{if $.description}}
+ {{if .Description}}
+ {{.Description}}
+ {{else}}
+ {{.Summary}}
+ {{end}}
{{end}}
{{end}}
-
-
-
{{ if lt $.count $.depth}}
-{{if eq $.style "li"}}
-
-{{end}}
- {{ .Scratch.Set "pages" .Pages }}
- {{ if .Sections}}
- {{ .Scratch.Set "pages" (.Pages | union .Sections) }}
- {{end}}
- {{ $pages := (.Scratch.Get "pages") }}
- {{if eq $.sortTerm "Weight"}}
- {{template "childs" dict "menu" $pages.ByWeight "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
- {{else if eq $.sortTerm "Name"}}
- {{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"}}
-
-{{end}}
+ {{if eq $.style "li"}}
+
+ {{end}}
+
+ {{ if .Sections}}
+ {{ .Scratch.Set "pages" (.Pages | union .Sections) }}
+ {{else}}
+ {{ .Scratch.Set "pages" .Pages }}
+ {{end}}
+
+ {{ $pages := (.Scratch.Get "pages") }}
+
+ {{if eq $.sortTerm "Weight"}}
+ {{template "childs" dict "menu" $pages.ByWeight "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
+ {{else if eq $.sortTerm "Name"}}
+ {{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"}}
+
+ {{end}}
{{end}}
-
{{end}}
{{end}}
{{end}}
\ No newline at end of file