Excluding a nested section's posts from list

content

content/
├── albums/
│   ├── album-1.md
│   ├── album-2.md
│   └── _index.md
├── books/
│   ├── fiction/
│   │   ├── fiction-1.md
│   │   ├── fiction-2.md
│   │   └── _index.md
│   ├── non-fiction/
│   │   ├── _index.md
│   │   ├── non-fiction-1.md
│   │   └── non-fiction-2.md
│   ├── book-1.md
│   ├── book-2.md
│   └── _index.md
└── _index.md

To list all regular pages, but exclude the non-fiction section:

{{ $p1 := site.RegularPages }}
{{ $p2 := (site.GetPage "books/non-fiction").Pages }}
{{ $p := $p1 | complement $p2 }}
{{ range $p.ByTitle }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}

This assumes you have created content/books/non-fiction/_index.md.

3 Likes