I am using the page bundles feature in Hugo.
But as I am writing more and more posts, I fear that it will find my posts according to the date I have written them.
Should I create folders for each year and month for organizing my posts?
I donβt understand your concern.
This is a matter of personal preference. If you create one post per month, this level of organization seems unnecessary. If you create 10 posts each month, it is probably a good idea.
Example
content
βββ blog/
β βββ 2020/
β β βββ 09/
β β β βββ bar/
β β β β βββ index.md
β β β βββ foo/
β β β β βββ index.md
β β β βββ _index.md
β β βββ 10/
β β β βββ baz/
β β β β βββ index.md
β β β βββ quz/
β β β β βββ index.md
β β β βββ _index.md
β β βββ 11/
β β β βββ wibble/
β β β βββ index.md
β β βββ 12/
β β β βββ wobble/
β β β β βββ index.md
β β β βββ wubble/
β β β β βββ index.md
β β β βββ _index.md
β β βββ _index.md
β βββ 2021/
β β βββ 01/
β β β βββ duey/
β β β β βββ index.md
β β β βββ huey/
β β β β βββ index.md
β β β βββ _index.md
β β βββ 02/
β β β βββ louie/
β β β β βββ index.md
β β β βββ _index.md
β β βββ _index.md
β βββ _index.md
βββ _index.md
Is there any way the folders will be automatically created when I run hugo new blog/my-blog-name?
No, there is not. You would have to write a wrapper script. In Linux this would be something like:
hugo new blog/$(date +%Y/%m)/foo.md
How can I use the wraper script?
Something like:
#!/usr/bin/env bash
main() {
if [[ $# -eq 0 ]]; then
echo "Error: missing path to new content."
echo "Example: $0 blog/mypost.md"
exit 1
fi
declare path=$1
hugo new "${path%%/*}/$(date +%Y/%m)/${path#*/}"
}
set -euo pipefail
main "$@"
1 Like