mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
menu: frontmatter option to change sort predicate #98
This commit is contained in:
parent
f35e2336aa
commit
16b346c646
6 changed files with 29 additions and 16 deletions
|
@ -55,7 +55,8 @@ Note that some of these parameters are explained in details in other sections of
|
||||||
mermaidInitialize = "{ \"theme\": \"default\" }"
|
mermaidInitialize = "{ \"theme\": \"default\" }"
|
||||||
# Hide Next and Previous page buttons normally displayed full height beside content
|
# Hide Next and Previous page buttons normally displayed full height beside content
|
||||||
disableNextPrev = true
|
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"
|
ordersectionsby = "weight"
|
||||||
# Change default color scheme with a variant one. Can be "red", "blue", "green".
|
# Change default color scheme with a variant one. Can be "red", "blue", "green".
|
||||||
themeVariant = ""
|
themeVariant = ""
|
||||||
|
|
|
@ -103,6 +103,8 @@ disableToc = "false"
|
||||||
menuTitle = ""
|
menuTitle = ""
|
||||||
# If set, this will explicitly override common rules for the expand state of a page's menu entry
|
# If set, this will explicitly override common rules for the expand state of a page's menu entry
|
||||||
alwaysopen = true
|
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
|
# The title of the page in menu will be prefixed by this HTML content
|
||||||
pre = ""
|
pre = ""
|
||||||
# The title of the page in menu will be postfixed by this HTML content
|
# The title of the page in menu will be postfixed by this HTML content
|
||||||
|
|
|
@ -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 |
|
| 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/) |
|
| 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 |
|
| 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
|
## Demo
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,10 @@
|
||||||
{{- end }}
|
{{- end }}
|
||||||
<div class="highlightable">
|
<div class="highlightable">
|
||||||
<ul class="topics">
|
<ul class="topics">
|
||||||
|
{{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
|
||||||
|
{{- $currentOrdersectionsby := .Site.Home.Params.ordersectionsby | default $defaultOrdersectionsby }}
|
||||||
{{- $defaultAlwaysopen := .Site.Params.alwaysopen | default false }}
|
{{- $defaultAlwaysopen := .Site.Params.alwaysopen | default false }}
|
||||||
{{- if eq .Site.Params.ordersectionsby "title" }}
|
{{- if eq $currentOrdersectionsby "title" }}
|
||||||
{{- range .Site.Home.Sections.ByTitle }}
|
{{- range .Site.Home.Sections.ByTitle }}
|
||||||
{{- template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen }}
|
{{- template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
@ -105,6 +107,8 @@
|
||||||
{{- if $hidden }}
|
{{- if $hidden }}
|
||||||
{{- else if .IsSection }}
|
{{- else if .IsSection }}
|
||||||
{{- safeHTML .Params.head }}
|
{{- safeHTML .Params.head }}
|
||||||
|
{{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
|
||||||
|
{{- $currentOrdersectionsby := .Params.ordersectionsby | default $defaultOrdersectionsby }}
|
||||||
{{- $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }}
|
{{- $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }}
|
||||||
<li data-nav-id="{{.RelPermalink}}" title="{{.Title}}" class="dd-item{{if eq .File.UniqueID $currentFileUniqueID}} active{{end}}{{if .IsAncestor $currentNode }} parent{{end}}{{if $currentAlwaysopen}} alwaysopen{{end}}"><a href="{{.RelPermalink}}">
|
<li data-nav-id="{{.RelPermalink}}" title="{{.Title}}" class="dd-item{{if eq .File.UniqueID $currentFileUniqueID}} active{{end}}{{if .IsAncestor $currentNode }} parent{{end}}{{if $currentAlwaysopen}} alwaysopen{{end}}"><a href="{{.RelPermalink}}">
|
||||||
{{- partial "menu-pre.html" . }}{{ or .Params.menuTitle .LinkTitle .Title }}{{ partial "menu-post.html" . }}
|
{{- partial "menu-pre.html" . }}{{ or .Params.menuTitle .LinkTitle .Title }}{{ partial "menu-post.html" . }}
|
||||||
|
@ -116,7 +120,7 @@
|
||||||
{{- $pages = (.Pages | union .Sections) }}
|
{{- $pages = (.Pages | union .Sections) }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $defaultAlwaysopen := .Site.Params.alwaysopen | default true }}
|
{{- $defaultAlwaysopen := .Site.Params.alwaysopen | default true }}
|
||||||
{{- if eq .Site.Params.ordersectionsby "title" }}
|
{{- if eq $currentOrdersectionsby "title" }}
|
||||||
{{- range $pages.ByTitle }}
|
{{- range $pages.ByTitle }}
|
||||||
{{- template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen }}
|
{{- template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
|
@ -42,7 +42,9 @@
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $pages := ($currentNode.Scratch.Get "relearnSubPages") }}
|
{{- $pages := ($currentNode.Scratch.Get "relearnSubPages") }}
|
||||||
|
|
||||||
{{- if eq .Site.Params.ordersectionsby "title"}}
|
{{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
|
||||||
|
{{- $currentOrdersectionsby := .node.Params.ordersectionsby | default $defaultOrdersectionsby }}
|
||||||
|
{{- if eq $currentOrdersectionsby "title"}}
|
||||||
{{- range $pages.ByTitle }}
|
{{- range $pages.ByTitle }}
|
||||||
{{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hiddenstem" $hidden_stem "hiddencurrent" $hidden_from_current }}
|
{{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hiddenstem" $hidden_stem "hiddencurrent" $hidden_from_current }}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{{- $style := .Get "style" | default "li" }}
|
{{- $style := .Get "style" | default "li" }}
|
||||||
{{- $depth := .Get "depth" | default 1 }}
|
{{- $depth := .Get "depth" | default 1 }}
|
||||||
{{- $withDescription := .Get "description" | default false }}
|
{{- $withDescription := .Get "description" | default false }}
|
||||||
{{- $sortTerm := .Get "sort" | default (.Site.Params.ordersectionsby | default "weight") | lower }}
|
{{- $sortTerm := .Get "sort" | lower }}
|
||||||
{{- $containerstyle := .Get "containerstyle" | default "ul" }}
|
{{- $containerstyle := .Get "containerstyle" | default "ul" }}
|
||||||
|
|
||||||
{{ (printf "<%s class=\"children children-%s children-sort-%s\">" $containerstyle $style $sortTerm)|safeHTML }}
|
{{ (printf "<%s class=\"children children-%s children-sort-%s\">" $containerstyle $style $sortTerm)|safeHTML }}
|
||||||
|
@ -14,15 +14,17 @@
|
||||||
{{- $pages = (.Page.Pages | union .Page.Sections) }}
|
{{- $pages = (.Page.Pages | union .Page.Sections) }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
{{- if eq $sortTerm "weight" }}
|
{{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
|
||||||
|
{{- $currentOrdersectionsby := $sortTerm | default (.Page.Params.ordersectionsby | default $defaultOrdersectionsby) }}
|
||||||
|
{{- if eq $currentOrdersectionsby "weight" }}
|
||||||
{{- template "childs" dict "menu" $pages.ByWeight "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
|
{{- 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 or (eq $sortTerm "name") (eq $sortTerm "title") }}
|
{{- else if or (eq $currentOrdersectionsby "name") (eq $currentOrdersectionsby "title") }}
|
||||||
{{- template "childs" dict "menu" $pages.ByTitle "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
|
{{- 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 $currentOrdersectionsby "publishdate" }}
|
||||||
{{- template "childs" dict "menu" $pages.ByPublishDate "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
|
{{- 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 $currentOrdersectionsby "date" }}
|
||||||
{{- template "childs" dict "menu" $pages.ByDate "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
|
{{- 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 $currentOrdersectionsby "length" }}
|
||||||
{{- template "childs" dict "menu" $pages.ByLength "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
|
{{- template "childs" dict "menu" $pages.ByLength "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{{- template "childs" dict "menu" $pages "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
|
{{- template "childs" dict "menu" $pages "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
|
||||||
|
@ -69,15 +71,17 @@
|
||||||
{{- $pages = (.Page.Pages | union .Page.Sections) }}
|
{{- $pages = (.Page.Pages | union .Page.Sections) }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
{{- if eq $.sortTerm "weight" }}
|
{{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
|
||||||
|
{{- $currentOrdersectionsby := $.sortTerm | default (.Page.Params.ordersectionsby | default $defaultOrdersectionsby) }}
|
||||||
|
{{- if eq $currentOrdersectionsby "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 }}
|
{{- 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 or (eq $.sortTerm "name") (eq $.sortTerm "title") }}
|
{{- else if or (eq $.currentOrdersectionsby "name") (eq $.currentOrdersectionsby "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 }}
|
{{- 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 $.currentOrdersectionsby "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 }}
|
{{- 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 $.currentOrdersectionsby "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 }}
|
{{- 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 $.currentOrdersectionsby "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 }}
|
{{- 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 }}
|
{{- else }}
|
||||||
{{- template "childs" dict "menu" $pages "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }}
|
{{- template "childs" dict "menu" $pages "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }}
|
||||||
|
|
Loading…
Reference in a new issue