| 1 |
{{/* gotmplfmt-ignore-all */ -}} |
| 2 |
|
| 3 |
{{/* |
| 4 |
Renders a table 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 |
@param {string} [headingColumn1="Item"] The heading for the first column of the table. |
| 19 |
@param {string} [headingColumn2="Description"] The heading for the second column of the table. |
| 20 |
|
| 21 |
@example |
| 22 |
|
| 23 |
{{% render-table-of-pages-in-section |
| 24 |
path=/methods/resource |
| 25 |
filter=methods_resource_image_processing |
| 26 |
filterType=include |
| 27 |
headingColumn1=Method |
| 28 |
headingColumn2=Description |
| 29 |
%}} |
| 30 |
|
| 31 |
*/}} |
| 32 |
|
| 33 |
{{- /* Initialize. */}} |
| 34 |
{{- $filter := or "" (.Get "filter" | lower) }} |
| 35 |
{{- $filterType := or (.Get "filterType") "none" | lower }} |
| 36 |
{{- $filteredPages := slice }} |
| 37 |
{{- $titlePrefix := or (.Get "titlePrefix") "" }} |
| 38 |
{{- $headingColumn1 := or (.Get "headingColumn1") "Item" }} |
| 39 |
{{- $headingColumn2 := or (.Get "headingColumn2") "Description" }} |
| 40 |
|
| 41 |
{{- /* Build slice of filtered pages. */}} |
| 42 |
{{- with $filter }} |
| 43 |
{{- with index hugo.Data.page_filters . }} |
| 44 |
{{- range . }} |
| 45 |
{{- with site.GetPage . }} |
| 46 |
{{- $filteredPages = $filteredPages | append . }} |
| 47 |
{{- else }} |
| 48 |
{{- errorf "The %q shortcode was unable to find %q as specified in the page_filters data file. See %s" $.Name . $.Position }} |
| 49 |
{{- end }} |
| 50 |
{{- end }} |
| 51 |
{{- else }} |
| 52 |
{{- errorf "The %q shortcode was unable to find the %q filter in the page_filters data file. See %s" $.Name . $.Position }} |
| 53 |
{{- end }} |
| 54 |
{{- end }} |
| 55 |
|
| 56 |
{{- /* Render. */}} |
| 57 |
{{- with $sectionPath := .Get "path" }} |
| 58 |
{{- with site.GetPage . }} |
| 59 |
{{- with .RegularPages }} |
| 60 |
{{ $headingColumn1 }}|{{ $headingColumn2 }}{{/* Do not indent. */}} |
| 61 |
:--|:--{{/* Do not indent. */}} |
| 62 |
{{- range $page := .ByTitle }} |
| 63 |
{{- if or |
| 64 |
(and (eq $filterType "include") (in $filteredPages $page)) |
| 65 |
(and (eq $filterType "exclude") (not (in $filteredPages $page))) |
| 66 |
(eq $filterType "none") |
| 67 |
}} |
| 68 |
{{- $linkTitle := .LinkTitle }} |
| 69 |
{{- with $titlePrefix }} |
| 70 |
{{- $linkTitle = printf "%s%s" . $linkTitle }} |
| 71 |
{{- end }} |
| 72 |
{{- /* Use page Path as the link destination for render hook to resolve correctly. */}} |
| 73 |
{{- if $page.Params.isFunctionOrMethod }} |
| 74 |
[`{{ $linkTitle }}`]({{ $page.Path }})|{{ $page.Description }}{{/* Do not indent. */}} |
| 75 |
{{- else }} |
| 76 |
[{{ $linkTitle }}]({{ $page.Path }})|{{ $page.Description }}{{/* Do not indent. */}} |
| 77 |
{{- end }} |
| 78 |
{{- end }} |
| 79 |
{{- end }} |
| 80 |
{{- else }} |
| 81 |
{{- warnf "The %q shortcode found no pages in the %q section. See %s" $.Name $sectionPath $.Position }} |
| 82 |
{{- end }} |
| 83 |
{{- else }} |
| 84 |
{{- errorf "The %q shortcode was unable to find %q. See %s" $.Name $sectionPath $.Position }} |
| 85 |
{{- end }} |
| 86 |
{{- else }} |
| 87 |
{{- errorf "The %q shortcode requires a 'path' parameter indicating the path to the section. See %s" $.Name $.Position }} |
| 88 |
{{- end }} |