Sectionless

Hi,

After perusing the documentation I’m unsure whether it’s possible to not have section (i.e. top level directories) at all.

“By default, all the first-level directories under content/ form their own sections ( root sections ).” might suggest that it’s possible to get rid of them, but it might not. Is it possible?

If not: I can still configure permalinks to have URLs like https://example.com/my-first-post, https://example.com/my-second-post, and so on. Is that correct?

Thank you.

Hi and welcome!

I’m not quite sure I understood your question. But you can do something like this:

[permalinks]
blog = "/:slug/"

The blog path will be /blog/, but blog post will live in the root directory /my-first-post/. This way you won’t need multiple ‘fake sections’.

For normal pages you don’t need a section at all. Just use something like /content/about/index.md (not _index.md).


By the way: This is what I also use:

[frontmatter]
date = [
  ":filename",
  ":default"
]
publishDate = [
  ":filename",
  ":default"
]

Then Hugo will be able to get the slug and the date from the file or folder name of you post. /content/blog/2020-06-07-my-first-post will automatically become /my-first-post/ including the correct post date.

1 Like

Yes it’s possible.

If you want to configure permalinks for your root dir, this is how{

[permalinks]
"/" = "/:slug/"

See https://gohugo.io/content-management/urls/#permalinks-configuration-example

1 Like

That’s good and I’ll try it.

So when the documentation says " While Hugo supports content nested at any level, the top levels (i.e. content/<DIRECTORIES> ) are special in Hugo and are considered the content type used to determine layouts etc." I don’t need to worry about leaving out that special top level layer and Hugo won’t get confused trying to determine the content type?

I guess there’s not much use in debating this, I’ll just have to try it. :slight_smile:

No…