| 1 |
{{/* gotmplfmt-ignore-all */ -}} |
| 2 |
|
| 3 |
{{/* |
| 4 |
Renders a description list of the pages in the given section. |
| 5 |
|
| 6 |
Render a subset of the pages in the section by specifying a predefined filter, |
| 7 |
and whether to include those pages. |
| 8 |
|
| 9 |
Filters are defined in the data directory, in the file named page_filters. Each |
| 10 |
filter is an array of paths to a file, relative to the root of the content |
| 11 |
directory. Hugo will throw an error if the specified filter does not exist, or |
| 12 |
if any of the pages in the filter do not exist. |
| 13 |
|
| 14 |
@param {string} path The path to the section. |
| 15 |
@param {string} [filter=""] The name of filter list. |
| 16 |
@param {string} [filterType=""] The type of filter, either include or exclude. |
| 17 |
@param {string} [titlePrefix=""] The string to prepend to the link title. |
| 18 |
|
| 19 |
@example {{% render-list-of-pages-in-section path=/methods/resource %}} |
| 20 |
@example {{% render-list-of-pages-in-section path=/functions/images filter=some_filter filterType=exclude %}} |
| 21 |
@example {{% render-list-of-pages-in-section path=/functions/images filter=some_filter filterType=exclude titlePrefix=foo %}} |
| 22 |
*/}} |
| 23 |
|
| 24 |
{{- /* Initialize. */}} |
| 25 |
{{- $filter := or "" (.Get "filter" | lower) }} |
| 26 |
{{- $filterType := or (.Get "filterType") "none" | lower }} |
| 27 |
{{- $filteredPages := slice }} |
| 28 |
{{- $titlePrefix := or (.Get "titlePrefix") "" }} |
| 29 |
|
| 30 |
{{- /* Build slice of filtered pages. */}} |
| 31 |
{{- with $filter }} |
| 32 |
{{- with index hugo.Data.page_filters . }} |
| 33 |
{{- range . }} |
| 34 |
{{- with site.GetPage . }} |
| 35 |
{{- $filteredPages = $filteredPages | append . }} |
| 36 |
{{- else }} |
| 37 |
{{- errorf "The %q shortcode was unable to find %q as specified in the page_filters data file. See %s" $.Name . $.Position }} |
| 38 |
{{- end }} |
| 39 |
{{- end }} |
| 40 |
{{- else }} |
| 41 |
{{- errorf "The %q shortcode was unable to find the %q filter in the page_filters data file. See %s" $.Name . $.Position }} |
| 42 |
{{- end }} |
| 43 |
{{- end }} |
| 44 |
|
| 45 |
{{- /* Render. */}} |
| 46 |
{{- with $sectionPath := .Get "path" }} |
| 47 |
{{- with site.GetPage . }} |
| 48 |
{{- with .RegularPages }} |
| 49 |
{{- range $page := .ByTitle }} |
| 50 |
{{- if or |
| 51 |
(and (eq $filterType "include") (in $filteredPages $page)) |
| 52 |
(and (eq $filterType "exclude") (not (in $filteredPages $page))) |
| 53 |
(eq $filterType "none") |
| 54 |
}} |
| 55 |
{{- $linkTitle := .LinkTitle }} |
| 56 |
{{- with $titlePrefix }} |
| 57 |
{{- $linkTitle = printf "%s%s" . $linkTitle }} |
| 58 |
{{- end }} |
| 59 |
{{- /* Use page Path as the link destination for render hook to resolve correctly. */}} |
| 60 |
{{- if $page.Params.isFunctionOrMethod }} |
| 61 |
[`{{ $linkTitle }}`]({{ $page.Path }}){{/* Do not indent. */}} |
| 62 |
{{- else }} |
| 63 |
[{{ $linkTitle }}]({{ $page.Path }}){{/* Do not indent. */}} |
| 64 |
{{- end }} |
| 65 |
: {{ $page.Description }}{{/* Do not indent. */}} |
| 66 |
{{ end }} |
| 67 |
{{- end }} |
| 68 |
{{- else }} |
| 69 |
{{- warnf "The %q shortcode found no pages in the %q section. See %s" $.Name $sectionPath $.Position }} |
| 70 |
{{- end }} |
| 71 |
{{- else }} |
| 72 |
{{- errorf "The %q shortcode was unable to find %q. See %s" $.Name $sectionPath $.Position }} |
| 73 |
{{- end }} |
| 74 |
{{- else }} |
| 75 |
{{- errorf "The %q shortcode requires a 'path' parameter indicating the path to the section. See %s" $.Name $.Position }} |
| 76 |
{{- end }} |