add option to override sort

This commit is contained in:
Robert Kaussow 2024-01-12 11:36:47 +01:00
parent 2050905981
commit 7014954bee
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
3 changed files with 20 additions and 5 deletions

View File

@ -8,10 +8,18 @@ The `toc-tree` shortcode will generate a Table of Content from a section file tr
<!-- prettier-ignore-start -->
```tpl
{{</* toc-tree */>}}
{{</* toc-tree [sortBy="title"] */>}}
```
<!-- prettier-ignore-end -->
### Attributes
<!-- prettier-ignore-start -->
<!-- spellchecker-disable -->
{{< propertylist name=shortcode-toc-tree sort=name order=asc >}}
<!-- spellchecker-enable -->
<!-- prettier-ignore-end -->
## 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.

View File

@ -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

View File

@ -1,9 +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 }}
<div class="gdoc-toc gdoc-toc__level--{{ $tocLevels }}">
{{ template "toc-tree" dict "sect" .Page.Pages "current" $current }}
{{ template "toc-tree" dict "sect" .Page.Pages "current" $current "sort" $sortBy }}
</div>
{{- end }}
@ -11,7 +12,7 @@
<!-- templates -->
{{- define "toc-tree" }}
<ul>
{{ $sortBy := (default "title" .current.Site.Params.geekdocFileTreeSortBy | lower) }}
{{ $sortBy := .sort }}
{{ range .sect.GroupBy "Weight" }}
{{ $rangeBy := .ByTitle }}
@ -41,8 +42,6 @@
{{ $rangeBy = .ByLastmod.Reverse }}
{{ end }}
{{ $sortBy }}
{{ range $rangeBy }}
{{- if or (not .Params.geekdocHidden) (not (default true .Params.geekdocHiddenTocTree)) }}
<li>