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