Not mainSections?

I’m using @budparr’s awesome Ananke theme as a base to build off and I’m wondering if there’s a way to exclude mainSections instead of including them?

mainSections are declared via params in the config.toml…
> {{/* Define a section to pull recent posts from. For Hugo 0.20 this will default to the section with the most number of pages. */}}

    {{ $mainSections := .Site.Params.mainSections | default (slice "tips") }}
    {{/* Create a variable with that section to use in multiple places. */}}
    {{ $section := where .Site.RegularPages "Section" "in" $mainSections }}
    {{/* Check to see if the section is defined for ranging through it */}}
    {{ $section_count := len $section }}
    {{ if ge $section_count 1 }}
    {{/* Derive the section name  */}}
    {{ $section_name := index (.Site.Params.mainSections) 0 }}

Is that to say you want to include a particular section?

It’s not documented, but mainSections allows you to define the section(s) in your config file. If there isn’t one defined, it automatically chooses the Section with the most documents.

1 Like

To exclude you would do:

{{ $section := where .Site.RegularPages "Section" "not in" $mainSections }}
2 Likes

A good theme’s the best documentation @budparr and thanks to yours I worked that. But I want my recent posts to come from all/any of my sections (except “Pages”) and I plan to be adding many, many new sections in the future so the thought of having to manually adjust the config file every time a new section is added seems laborious.

And it looks like @bep has made more Hugo magic (replying to this thread with a solution) so thank you both.

1 Like