From 16b346c6463652b04439e0d2e0d3b70624eb27d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Mon, 27 Sep 2021 22:03:10 +0200 Subject: [PATCH] menu: frontmatter option to change sort predicate #98 --- .../content/basics/configuration/_index.en.md | 3 ++- exampleSite/content/cont/pages/_index.en.md | 2 ++ .../content/shortcodes/children/_index.en.md | 2 +- layouts/partials/menu.html | 8 ++++-- layouts/partials/page-meta.go | 4 ++- layouts/shortcodes/children.html | 26 +++++++++++-------- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/exampleSite/content/basics/configuration/_index.en.md b/exampleSite/content/basics/configuration/_index.en.md index b048313d4b..eefbb1af38 100644 --- a/exampleSite/content/basics/configuration/_index.en.md +++ b/exampleSite/content/basics/configuration/_index.en.md @@ -55,7 +55,8 @@ Note that some of these parameters are explained in details in other sections of mermaidInitialize = "{ \"theme\": \"default\" }" # Hide Next and Previous page buttons normally displayed full height beside content disableNextPrev = true - # Order sections in menu by "weight" or "title". Default to "weight" + # Order sections in menu by "weight" or "title". Default to "weight"; + # this can be overridden in the pages frontmatter ordersectionsby = "weight" # Change default color scheme with a variant one. Can be "red", "blue", "green". themeVariant = "" diff --git a/exampleSite/content/cont/pages/_index.en.md b/exampleSite/content/cont/pages/_index.en.md index 8d37d45934..b1a161bc22 100644 --- a/exampleSite/content/cont/pages/_index.en.md +++ b/exampleSite/content/cont/pages/_index.en.md @@ -103,6 +103,8 @@ disableToc = "false" menuTitle = "" # If set, this will explicitly override common rules for the expand state of a page's menu entry alwaysopen = true +# If set, this will explicitly override common rules for the sorting order of a page's submenu entries +ordersectionsby = "title" # The title of the page in menu will be prefixed by this HTML content pre = "" # The title of the page in menu will be postfixed by this HTML content diff --git a/exampleSite/content/shortcodes/children/_index.en.md b/exampleSite/content/shortcodes/children/_index.en.md index 490f1efeed..b9410796e9 100644 --- a/exampleSite/content/shortcodes/children/_index.en.md +++ b/exampleSite/content/shortcodes/children/_index.en.md @@ -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 | [ordersectionsby]({{% relref "basics/configuration#global-site-parameters" %}}) | Sort children by **weight** - to sort on menu order, **title** - to sort alphabetically on menu label | +| sort | [ordersectionsby]({{% relref "basics/configuration#global-site-parameters" %}}) | Sort children by **weight**, to sort on menu order - **title**, to sort alphabetically on menu label. If not set it is sorted by the `ordersectionsby` setting of the site and the pages frontmatter | ## Demo diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html index aae5934b8e..2177a545d1 100644 --- a/layouts/partials/menu.html +++ b/layouts/partials/menu.html @@ -21,8 +21,10 @@ {{- end }}