diff options
Diffstat (limited to 'layouts/partials/utils/get-keywords.html')
-rw-r--r-- | layouts/partials/utils/get-keywords.html | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/layouts/partials/utils/get-keywords.html b/layouts/partials/utils/get-keywords.html new file mode 100644 index 0000000..cbfa8e6 --- /dev/null +++ b/layouts/partials/utils/get-keywords.html @@ -0,0 +1,36 @@ +{{/* + Parameters: + - type: "tags" or "categories" + - context: (.) + - scratch: (Scratch) + - removeDuplicates: BOOL +*/}} + +{{/* Get all the "tags" or "categories" from a page (and its descendents) */}} +{{ if eq .context.Kind "section" }} + {{ range .context.Sections }} + {{ partial "utils/get-keywords.html" (dict "type" $.type "context" . "scratch" $.scratch) }} + {{ end }} + {{ range .context.Pages }} + {{ partial "utils/get-keywords.html" (dict "type" $.type "context" . "scratch" $.scratch) }} + {{ end }} +{{ else }} + {{ if eq .type "tags" }} + {{ range .context.Params.tags }} + {{ if not (eq . "") }} + {{ $.scratch.Add $.type (slice .) }} + {{ end }} + {{ end }} + {{ else if eq .type "categories" }} + {{ range .context.Params.categories }} + {{ if not (eq . "") }} + {{ $.scratch.Add $.type (slice .) }} + {{ end }} + {{ end }} + {{ end }} +{{ end }} + +{{/* Only available for first occurrence of method */}} +{{ if .removeDuplicates }} + {{ .scratch.Set .type (uniq (.scratch.Get .type)) }} +{{ end }} |