Organizing posts according to date

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