"Hugo way" to create new content in year/month/subfolders?

I looked into having some form of hugo new that ends up having new content in a folder content/2022/01/new-title. It seems that is not possible via frontmatter. Is that right or is there a way to use hugo new WITHOUT looking at the calendar, just the title (slug) of the final folder?

I know how to do it via bash script (for example), so it’s not something like a feature request, just trying to not re-do work already done.

[aside]I could have sworn I’d seen an answer to this before, but I searched and apparently not.[/aside]

EDIT: I eventually found Dates in post filenames - #7 by zwacky if that is any value.

I don’t have an answer, but I do have a reason you might want to reconsider that kind of directory structure:

It rather breaks Hugo’s section / content-type based on subdir. You could have content/section/2022/01/new-title, but I don’t know if that is something that will work for you.

Of course frontmatter can allow using non-standard content model, but I’m thinking if you do that you are looking at a lot of extra work.

I’m guessing you are trying to make it easier to crossover between WordPress and Hugo and I would be surprised if you didn’t already know about:

The upshot is that I would ask: “are you sure this directory structure is really going to work for you, if you can figure out how to do the hugo new part?”

Actually, I missed that. Of course it’s content/section/year/month.

The reason I want monthly subfolders is the number of items in there if something like multiple daily posts is happening. I also think that a solution like content/section/year-month-title is appropriate, but that too will lead to hundreds of subfolders in the end (If I do a folder per item).

This is mostly an aesthetic issue, think of looking up the item of June 20th 2021 in VSCode in a single-folder-structure or in Netlify CMS. Lots of scrolling. With monthly subfolders it would be 2 more clicks but a better visual folding.

I am not too concerned about calendar stuff and structure for my links.

@davidsneighbour Sorry, I should have realized it was a typo. I understand about the need for content organization; I don’t have all that many posts and my directories get full enough as it is.

Would you be more interested in keeping your bash script solution or something like the post I found using npm scripts, only with some kind of mkdir npm thing happening?

Or, are you looking at the possibility of contributing some ‘Go’ code to Hugo core, but want to know if there is anything that would make that moot?

Basically, if there isn’t anything already out there, is there something I can do to help (doubting it, but just in case…).

I am going with my shell script if it’s not available via Hugo. I don’t think that is something easily implemented, because the current template system does not allow anything else than changes inside of the resulting content. I guess it’s not that easy to implement something that influences content in the other direction (file system paths).

1 Like