I have an almost single page Hugo site, which consists of an index that lists all of my posts (under content) sorted by date.
However, I’m finding that as it grows, having all the files under /content is getting rather messy. Is there a way to have the archetype add the date to the filename and configure hugo to ignore that when generating URL’s?
i.e. go from:
content
eggs.md
other.md
rain.md
To
content
2020-01-01_rain.md
2019-10-05_other.md
2019-09-05_eggs.md
I’ve tried searching the documentation on both archetypes and organization and see no mention of how to name files.
No. Archetypes don’t name files, they are called when creating a file, but require the filename in the operation (hugo new 2020-01-01_rain.md).
What is your goal? You said you have too many files in the directory, but your solution to rename files is not obvious to me. What are you trying to do?
Simply to make the long list of files easier to grok, ordered by something consistent like date of post rather than the (effectively random) title of the post. A number that increments would be equally as valuable!
For example: Right now when trying to find the most recently written article I either need to look at the output of Hugo, work out what markdown file that would be and open it, or manually go into all files and check their dates.
I do think it would be cool to have some capability to adjust / automate post/markdown naming conventions and or folder structures. I think there’s just too many variables to try make everyone happy.
In the end, I’m doing hugo new post/2020/06/12/post-slug/index.md to take advantage of image processing in shortcodes. It’s a lot to type out to make a new post and I’d love to automate or script some sort of shorter solution somehow. Just haven’t invested any time into what the best way to go about that is.
I agree!
Ultimately I created an npm script for creating new posts. I thought I’d share maybe it helps someone coming across this thread. Doesn’t really matter if you use bash or npm scripts.
{
"scripts": "hugo new --kind post posts/$(date \"+%F\")-new-post"
}
$ npm run new
/content/posts/2020-08-29-new-post created