From b750f4ab5392231783b556f25f4a444251084c30 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Fri, 12 Jan 2024 11:56:06 +0100 Subject: [PATCH] fix: respect `geekdocFileTreeSortBy` parameter while creating the toc tree (#771) --- exampleSite/content/en/shortcodes/toc-tree.md | 10 +++++- .../data/properties/shortcode-toc-tree.yaml | 8 +++++ layouts/shortcodes/toc-tree.html | 36 +++++++++++++++++-- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 exampleSite/data/properties/shortcode-toc-tree.yaml diff --git a/exampleSite/content/en/shortcodes/toc-tree.md b/exampleSite/content/en/shortcodes/toc-tree.md index 27de09ed..e0b4e253 100644 --- a/exampleSite/content/en/shortcodes/toc-tree.md +++ b/exampleSite/content/en/shortcodes/toc-tree.md @@ -8,10 +8,18 @@ The `toc-tree` shortcode will generate a Table of Content from a section file tr ```tpl -{{}} +{{}} ``` +### Attributes + + + +{{< propertylist name=shortcode-toc-tree sort=name order=asc >}} + + + ## Example As said, the root will be the site on which the shortcode was used, you can see a demo including nesting in the [ToC Tree](/toc-tree/) section. diff --git a/exampleSite/data/properties/shortcode-toc-tree.yaml b/exampleSite/data/properties/shortcode-toc-tree.yaml new file mode 100644 index 00000000..8122126c --- /dev/null +++ b/exampleSite/data/properties/shortcode-toc-tree.yaml @@ -0,0 +1,8 @@ +--- +properties: + - name: sortBy + type: string + description: | + Override the default sort parameter set by [`geekdocFileTreeSortBy`](/usage/configuration/#site-configuration). + required: false + defaultValue: .Site.Params.geekdocFileTreeSortBy diff --git a/layouts/shortcodes/toc-tree.html b/layouts/shortcodes/toc-tree.html index 13148ba1..4c81b5b5 100644 --- a/layouts/shortcodes/toc-tree.html +++ b/layouts/shortcodes/toc-tree.html @@ -1,8 +1,10 @@ +{{- $current := . }} {{- $tocLevels := default (default 6 .Site.Params.geekdocToC) .Page.Params.geekdocToC }} +{{- $sortBy := (default (default "title" .Site.Params.geekdocFileTreeSortBy) (.Get "sortBy") | lower) }} {{- if $tocLevels }}
- {{ template "toc-tree" dict "sect" .Page.Pages }} + {{ template "toc-tree" dict "sect" .Page.Pages "current" $current "sortBy" $sortBy }}
{{- end }} @@ -10,8 +12,36 @@ {{- define "toc-tree" }}