mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
89 lines
3.3 KiB
HTML
89 lines
3.3 KiB
HTML
{{/* gotmplfmt-ignore-all */ -}}
|
|
|
|
{{/*
|
|
Renders a table 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.
|
|
@param {string} [headingColumn1="Item"] The heading for the first column of the table.
|
|
@param {string} [headingColumn2="Description"] The heading for the second column of the table.
|
|
|
|
@example
|
|
|
|
{{% render-table-of-pages-in-section
|
|
path=/methods/resource
|
|
filter=methods_resource_image_processing
|
|
filterType=include
|
|
headingColumn1=Method
|
|
headingColumn2=Description
|
|
%}}
|
|
|
|
*/}}
|
|
|
|
{{- /* Initialize. */}}
|
|
{{- $filter := or "" (.Get "filter" | lower) }}
|
|
{{- $filterType := or (.Get "filterType") "none" | lower }}
|
|
{{- $filteredPages := slice }}
|
|
{{- $titlePrefix := or (.Get "titlePrefix") "" }}
|
|
{{- $headingColumn1 := or (.Get "headingColumn1") "Item" }}
|
|
{{- $headingColumn2 := or (.Get "headingColumn2") "Description" }}
|
|
|
|
{{- /* Build slice of filtered pages. */}}
|
|
{{- with $filter }}
|
|
{{- with index hugo.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 }}
|
|
{{ $headingColumn1 }}|{{ $headingColumn2 }}{{/* Do not indent. */}}
|
|
:--|:--{{/* Do not indent. */}}
|
|
{{- 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 }}
|
|
{{- /* Use page Path as the link destination for render hook to resolve correctly. */}}
|
|
{{- if $page.Params.isFunctionOrMethod }}
|
|
[`{{ $linkTitle }}`]({{ $page.Path }})|{{ $page.Description }}{{/* Do not indent. */}}
|
|
{{- else }}
|
|
[{{ $linkTitle }}]({{ $page.Path }})|{{ $page.Description }}{{/* Do not indent. */}}
|
|
{{- end }}
|
|
{{- 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 }}
|