How do I select same level pages without pulling second-level index.md?

What I want to have is a simple blog that will display a list of all posts split by year by default and will have a couple of “special” pages (e.g. About me, Projects). Here’s what my content/ layout looks like:

├── content
│   ├── about
│   │   └── index.md
│   ├── lorem-ipsum.md
│   ├── projects
│   │   └── index.md
│   └── another-post.md

So, for index.html I would like to have something like

{{ define "main" }}
  {{ range .Pages }}
    <article>
      <div>
        <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
        ReadingTime: {{ .ReadingTime }}
        <br>
        {{ .Summary }}
      </div>
    </article>
  {{ end }}
{{ end }}

However, this would select both about/index.md and projects/index.md which is not what I want. I know I can make these indices hidden: true and check for {{ if not .Params.hidden }} in home.html but this sounds like the solution that wouldn’t be idiomatic. Is there any clean way of

  • Selecting the first-level pages (not indices under second level)?
  • Making a bunch of “special” pages (not listed anywhere except in the main menu on the right)? These don’t necessarily have to be under their own directory each, I might want a single directory for all of them and maybe just having a set of “special” files in there, separating them from the blog posts.

You can filter a list as you wish.

See collections.Where | Hugo

Either exclude the section you don’t need.

Use the .Pages variable that holds the:

Collection of regular pages and only first-level section pages under the current list page.

Or assign front matter parameters to related content (as you mentioned) and filter as needed.

There are several examples about filtering and limiting posts in the forum and in the documentation.

Thanks! This sounds like a solution but I thought it’s not what people mostly do :frowning:

Also, from your description it looks like .Pages would hold only content/index.md under index.html, not about/index.md. Am I missing something or is it a bug/doc problem?

For example if you call .Pages directly under the root of /content/ (and not from within a Section) then the top level sections/branch bundles (i.e. the info contained in an _index.md) and regular pages that reside at the same top level would populate the list.

Ah, okay, got it. Then this is quite inconvenient but looks to be correct. Thanks!

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