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