I’m trying to find all pages below a certain word count and trying to determine whether it’s possible to use where
to do so.
I’ve got logic that pulls all pages that looks like this:
{{ $pages := .Site.GetPage "/some-pages" }}
{{ $pages := where $pages.Resources "Draft" false }}
This correctly works.
Where the directory structure is:
some-pages/
index.md
page-1.md
page-2.md
I’m then trying to use where on .WordCount
which is available in each subpage ie {{ (index $pages 0).WordCount }}
.
What I’ve tried are things like:
{{ $wc := 100 }}
{{ where $pages "WordCount" "le" $wc }}
{{ where $pages ".WordCount" "le" $wc }}
// other variations
Is it possible to use where
in this fashion?
EDIT: This does work, but requires a new slice and looping, my question about where
still stands:
{{ $pageSet := .Site.GetPage "/some-pages" }}
{{ $pageSet := where $pageSet.Resources "Draft" false }}
{{ $pages := slice }}
{{ range $pageSet }}
{{ if lt .WordCount 100 }}
{{ $pages = $pages | append . }}
{{ end }}
{{ end }}