List all pages in sub folder


I have the following structure of content:

- content
-- news
-- blog
--- tips
--- tutorials

I don’t have neither, nor in tips subfolder because I don’t want page to be created.
How can I get list of pages inside blog/tips directory to output it somewhere on the site as a list of links?

{{ range where (where .Site.RegularPages "Type" "blog") "File.Dir" "blog/tips/" }}



Thanks for your reply!

Is it possible to get list of folders (tips, tutorials …) to build an ordered list of links?
I could do it by using with order parameter for each section (tips, tutorials …), but as I mentioned I don’t want the pages like to be created.

Maybe there is a more elegant solution to this requirement?

{{ range (readDir "content/blog/") }}
  {{ if .IsDir }}
    <p>{{ .Name | title }}</p>
    {{ $path := printf "blog/%s/" .Name }}
    {{ range where (where $.Site.RegularPages "Type" "blog") "File.Dir" $path }}
        <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
    {{ end }}
  {{ end }}
{{ end }}

But I’m also beginning to question your content structure.

First, keep in mind that the structure of your site, from the perspective of visitors, does not need to match the structure of your content directory. See permalinks.

Second, the first level directory under the content directory determines a content’s type. In my view:

  • A tip is a “type” of content
  • A tutorial is a “type” of content
  • A news article is a “type” of content

So you could do this:

├── news
│   ├──
│   └──
├── tips
│   ├──
│   └──
└── tutorials

with config.toml

tips = "/blog/tips/:title/"
tutorials = "/blog/tutorials/:title/"

You might also consider using Hugo’s taxonomy system to categorize your blogs posts as either tips or tutorials.

Just some alternatives to consider…


A post was split to a new topic: Directory listing by weight