Excluding a nested section's posts from list

Is this still the way to do it? Or is there a more condensed up-to-date version?

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.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.