Index.html in every (Sub) Folder of Content

Hay,
is there a way to let HUGO generate index.html files for every sub folder of Content (and their sub folders), as if an index.md was in there?

Preferably, this index.html should be generated from an separate template i define.

Thanks in advance

Silver

Not sure about what you want exactly, but you can try setting uglyURLs = true in your config.toml

Thank’s a lot for your replay!

Sadly, that won’t cut it.
I am gonna dump some Files into my Content folder, i don’t know how Many, how many folder s etc, and i don’t want to manually add index.md files to every one of them, so that i could acces via baseURL/Folder.

I need that step automated, that in every folder is an index.html with the content of one central template.md file.

If you start with this:

content
└── posts/
    β”œβ”€β”€ post-1/
    β”‚   β”œβ”€β”€ a.jpg
    β”‚   └── b.jpg
    β”œβ”€β”€ post-2/
    β”‚   β”œβ”€β”€ a.jpg
    β”‚   └── b.jpg
    └── post-3/
        β”œβ”€β”€ a.jpg
        └── b.jpg

And do this:

find content/posts/ -mindepth 1 -maxdepth 1 -type d -exec hugo new {}/index.md \;

You will get this:

content
└── posts/
    β”œβ”€β”€ post-1/
    β”‚   β”œβ”€β”€ a.jpg
    β”‚   β”œβ”€β”€ b.jpg
    β”‚   └── index.md
    β”œβ”€β”€ post-2/
    β”‚   β”œβ”€β”€ a.jpg
    β”‚   β”œβ”€β”€ b.jpg
    β”‚   └── index.md
    └── post-3/
        β”œβ”€β”€ a.jpg
        β”œβ”€β”€ b.jpg
        └── index.md

The index.md files will be created from the _default.md archetype. To create the index.md from a different archetype:

archetypes/
β”œβ”€β”€ _default.md
└── posts.md      <-- create from this one
find content/posts/ -mindepth 1 -maxdepth 1 -type d -exec hugo -k posts new {}/index.md \;
1 Like

Hay, Thanks a lot! That is really helpful!

Is it possible to use the templates out of the Themes Archetypes Folder?

Yes.

themes/mytheme/archetypes/
β”œβ”€β”€ default.md
└── foo.md         <-- use this one
find content/posts/ -mindepth 1 -maxdepth 1 -type d -exec hugo -k foo new {}/index.md \;
1 Like

Taking a moment to appreciate shell one-liners by @jmooring

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