mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
Merge commit 'b3d87dd0fd746f07f9afa6e6a2969aea41da6a38'
This commit is contained in:
69
docs/layouts/_shortcodes/list-pages-in-section.html
Normal file
69
docs/layouts/_shortcodes/list-pages-in-section.html
Normal file
@@ -0,0 +1,69 @@
|
||||
{{- /*
|
||||
Renders a description list of the pages in the given section.
|
||||
|
||||
Render a subset of the pages in the section by specifying a predefined filter,
|
||||
and whether to include those pages.
|
||||
|
||||
Filters are defined in the data directory, in the file named page_filters. Each
|
||||
filter is an array of paths to a file, relative to the root of the content
|
||||
directory. Hugo will throw an error if the specified filter does not exist, or
|
||||
if any of the pages in the filter do not exist.
|
||||
|
||||
@param {string} path The path to the section.
|
||||
@param {string} [filter=""] The name of filter list.
|
||||
@param {string} [filterType=""] The type of filter, either include or exclude.
|
||||
@param {string} [titlePrefix=""] The string to prepend to the link title.
|
||||
|
||||
@example {{< list-pages-in-section path=/methods/resources >}}
|
||||
@example {{< list-pages-in-section path=/functions/images filter=some_filter filterType=exclude >}}
|
||||
@example {{< list-pages-in-section path=/functions/images filter=some_filter filterType=exclude titlePrefix=foo >}}
|
||||
*/}}
|
||||
|
||||
{{/* Initialize. */}}
|
||||
{{ $filter := or "" (.Get "filter" | lower) }}
|
||||
{{ $filterType := or (.Get "filterType") "none" | lower }}
|
||||
{{ $filteredPages := slice }}
|
||||
{{ $titlePrefix := or (.Get "titlePrefix") "" }}
|
||||
|
||||
{{/* Build slice of filtered pages. */}}
|
||||
{{ with $filter }}
|
||||
{{ with index site.Data.page_filters . }}
|
||||
{{ range . }}
|
||||
{{ with site.GetPage . }}
|
||||
{{ $filteredPages = $filteredPages | append . }}
|
||||
{{ else }}
|
||||
{{ errorf "The %q shortcode was unable to find %q as specified in the page_filters data file. See %s" $.Name . $.Position }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ errorf "The %q shortcode was unable to find the %q filter in the page_filters data file. See %s" $.Name . $.Position }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Render. */}}
|
||||
{{ with $sectionPath := .Get "path" }}
|
||||
{{ with site.GetPage . }}
|
||||
{{ with .RegularPages }}
|
||||
{{ range $page := .ByTitle }}
|
||||
{{ if or
|
||||
(and (eq $filterType "include") (in $filteredPages $page))
|
||||
(and (eq $filterType "exclude") (not (in $filteredPages $page)))
|
||||
(eq $filterType "none")
|
||||
}}
|
||||
{{ $linkTitle := .LinkTitle }}
|
||||
{{ with $titlePrefix }}
|
||||
{{ $linkTitle = printf "%s%s" . $linkTitle }}
|
||||
{{ end }}
|
||||
[{{ $linkTitle }}]({{ $page.RelPermalink }}){{/* Do not indent. */}}
|
||||
: {{ $page.Description }}{{/* Do not indent. */}}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ warnf "The %q shortcode found no pages in the %q section. See %s" $.Name $sectionPath $.Position }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ errorf "The %q shortcode was unable to find %q. See %s" $.Name $sectionPath $.Position }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ errorf "The %q shortcode requires a 'path' parameter indicating the path to the section. See %s" $.Name $.Position }}
|
||||
{{ end }}
|
Reference in New Issue
Block a user