Skip to content

Commit

Permalink
children: default sorting ignores ordersectionsby #62
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Aug 26, 2021
1 parent dff23d8 commit 3995738
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion exampleSite/content/shortcodes/children/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Use the children shortcode to list the child pages of a page and the further des
| showhidden | "false" | When true, child pages hidden from the menu will be displayed |
| description | "false" | Allows you to include a short text under each page in the list. When no description exists for the page, children shortcode takes the first 70 words of your content. [Read more info about summaries on gohugo.io](https://gohugo.io/content/summaries/) |
| depth | 1 | Enter a number to specify the depth of descendants to display. For example, if the value is 2, the shortcode will display 2 levels of child pages. **Tips:** set 999 to get all descendants |
| sort | none | Sort children by **Weight** - to sort on menu order, **Name** - to sort alphabetically on menu label, **Identifier** - to sort alphabetically on identifier set in frontmatter, and **URL** - to sort by URL |
| sort | [ordersectionsby]({{% relref "basics/configuration#global-site-parameters" %}}) | Sort children by **weight** - to sort on menu order, **title** - to sort alphabetically on menu label |

## Demo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
alwaysopen = false
description = "This is a demo child page"
title = "page 1"
weight = 10
+++

This is a demo child page.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
+++
alwaysopen = false
title = "page 2"
weight = 20
+++

This is a demo child page with no description.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
+++
description = "This is a demo child page"
title = "page 3"
weight = 30
+++

This is a demo child page.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ alwaysopen = false
description = "This is a hidden demo child page"
hidden = true
title = "page 4 (hidden)"
weight = 40
+++

This is a **hidden** demo child page. This page and all its children are hidden in the menu, arrow navigation and children shortcode as long as you aren't viewing this page or its children directly.
1 change: 1 addition & 0 deletions exampleSite/content/shortcodes/children/test.en.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
+++
description = "This is a plain page test"
title = "plain page test"
weight = 1
+++

This is a plain demo child page.
24 changes: 12 additions & 12 deletions layouts/shortcodes/children.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
{{ $style := .Get "style" | default "li" }}
{{ $depth := .Get "depth" | default 1 }}
{{ $withDescription := .Get "description" | default false }}
{{ $sortTerm := .Get "sort" | default "Weight" }}
{{ $sortTerm := .Get "sort" | default (.Site.Params.ordersectionsby | default "weight") | lower }}
{{ $containerstyle := .Get "containerstyle" | default "ul" }}

{{(printf "<%s class=\"children children-%s\">" $containerstyle $style)|safeHTML}}
{{(printf "<%s class=\"children children-%s children-sort-%s\">" $containerstyle $style $sortTerm)|safeHTML}}
{{ .Scratch.Set "pages" .Page.Pages }}

{{if .Page.IsHome}}
Expand All @@ -21,15 +21,15 @@

{{ $pages := (.Scratch.Get "pages") }}

{{if eq $sortTerm "Weight"}}
{{if eq $sortTerm "weight"}}
{{template "childs" dict "menu" $pages.ByWeight "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}}
{{else if eq $sortTerm "Name"}}
{{else if or (eq $sortTerm "name") (eq $sortTerm "title")}}
{{template "childs" dict "menu" $pages.ByTitle "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}}
{{else if eq $sortTerm "PublishDate"}}
{{else if eq $sortTerm "publishdate"}}
{{template "childs" dict "menu" $pages.ByPublishDate "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}}
{{else if eq $sortTerm "Date"}}
{{else if eq $sortTerm "date"}}
{{template "childs" dict "menu" $pages.ByDate "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}}
{{else if eq $sortTerm "Length"}}
{{else if eq $sortTerm "length"}}
{{template "childs" dict "menu" $pages.ByLength "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}}
{{else}}
{{template "childs" dict "menu" $pages "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm}}
Expand Down Expand Up @@ -77,15 +77,15 @@

{{ $pages := (.Scratch.Get "pages") }}

{{if eq $.sortTerm "Weight"}}
{{if eq $.sortTerm "weight"}}
{{template "childs" dict "menu" $pages.ByWeight "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{else if eq $.sortTerm "Name"}}
{{else if or (eq $.sortTerm "name") (eq $.sortTerm "title")}}
{{template "childs" dict "menu" $pages.ByTitle "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{else if eq $.sortTerm "PublishDate"}}
{{else if eq $.sortTerm "publishdate"}}
{{template "childs" dict "menu" $pages.ByPublishDate "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{else if eq $.sortTerm "Date"}}
{{else if eq $.sortTerm "date"}}
{{template "childs" dict "menu" $pages.ByDate "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{else if eq $.sortTerm "Length"}}
{{else if eq $.sortTerm "length"}}
{{template "childs" dict "menu" $pages.ByLength "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
{{else}}
{{template "childs" dict "menu" $pages "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm}}
Expand Down

0 comments on commit 3995738

Please sign in to comment.