Skip to content
Snippets Groups Projects
Commit db84993c authored by Sietze van Buuren's avatar Sietze van Buuren Committed by Sietze van Buuren
Browse files

Add short-code to list (nested) pages of the current section


Adds a new short-code to display all (nested) section pages in a link list (with
header title) with nested link lists for nested page sections. The order of the
list items resembles the page order in the navigation menu.

Usage:

Use the short-code in the markdown page the represents a subsection (a
subsection is represented by a markdown page and a subsection directory
(identically named) that resides in the same directory as the markdown page).

```
{{< section-toc title="Contents">}}
```

Note that the named input argument `title` is optional and defaults to
`Contents`.

Signed-off-by: default avatarSietze van Buuren <Sietze.vanBuuren@de.bosch.com>
parent 31679f08
No related branches found
No related tags found
1 merge request!589Add short-code to list (nested) pages of the current section
Pipeline #667577 passed with warnings
{{- $order := cond $.sort_by_weight "weight" "sort_title" -}}
{{- range sort $.files $order -}}
{{- $show_page := (cond $.sort_by_weight (cond $.weighted_top (and (lt .weight 100) (ne .weight nil) ) (gt .weight 100) ) (or (eq .weight 100) (eq .weight nil) ) ) -}}
{{- if $show_page -}}
{{- if not (in (slice "index" "_index") .file) -}}
<li><a href="{{ .link }}">{{ .title }}</a></li>
{{- end -}}
{{- range (where $.dirs "Name" "eq" .file) }}
{{- partial "subsection-pages.html" (dict "context" $.context "site" $.site "link" (print $.path .Name "/")) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $path := $.link -}}
{{- $ls := readDir (print "content/" $path) -}}
{{- $dirs := where $ls "IsDir" true -}}
{{- $files := slice -}}
{{- range (where $ls "IsDir" false) }}
{{- $file := strings.TrimSuffix ".md" .Name -}}
{{- $fpath := print $path .Name -}}
{{- $link := strings.TrimSuffix ".md" $fpath -}}
{{- with $.context.Site.GetPage "filepath" $fpath -}}
{{$files = $files | append (dict "name" .Name "title" .Title "sort_title" (print "sort_" .Title) "weight" (cond (eq .Weight 0) nil .Weight) "file" $file "fpath" $fpath "link" $link) }}
{{- else -}}
{{- end -}}
{{- end -}}
<ul>
{{- partial "subsection-listing.html" (dict "context" $.context "files" $files "path" $path "dirs" $dirs "sort_by_weight" true "weighted_top" true) -}}
{{- partial "subsection-listing.html" (dict "context" $.context "files" $files "path" $path "dirs" $dirs "sort_by_weight" false "weighted_top" false) -}}
{{- partial "subsection-listing.html" (dict "context" $.context "files" $files "path" $path "dirs" $dirs "sort_by_weight" true "weighted_top" false) -}}
</ul>
\ No newline at end of file
{{- $title := .Get "title" | default "Contents" -}}
<h3>{{ $title }}</h3>
{{- partial "subsection-pages.html" (dict "context" . "link" .Page.RelPermalink) -}}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment