Permalinks or directories for website with blog section?

Iā€™m in the process of setting up Hugo to create a website with several article sections and a blog section.

I would like the blog posts to be created in directories named after years, so that posts written this year would be in /blog/2020/ and those written next year would be in /blog/2021/

Having read through the docs I have found that Hugo will allow me to either place each markdown file in separate year directories within /content/blog/ or place them all directly in /content/blog/ and use a permalink definition of blog: /blog/:year/:title/ so Hugo can decide where to build each post based on the date defined in the front matter.

My question is, what are the reasons for choosing one method over another?

The benefits of organizing by directory include:

  1. Manageability. If you post every day, you will will have 1000+ files in a single directory after three years.
  2. Visibility. With everything in a single directory, you must inspect the front matter of each article to determine the year in which it was written. This assumes that your file names do not include a datetime stamp, which is another option to consider.
  3. Archive URLs. For example, if you want to see a list of articles from 2019, you can create a _index.md file in 'content/blog/2019/`. Then visit https://example.com/blog/2019 to see the list. There are other ways to handle the creation of archive lists, but this one is simple.

The benefits of controlling the URL structure via [permalinks] in config.toml include:

  1. URL structure is independent of directory structure, obviously.
  2. You can alter your URL structure by changing one line in your configuration file. In reality, once your site is in production, this has (in my view) little value because your URLs should be stable.

You can also do both:

content/
ā”œā”€ā”€ articles
ā”‚   ā”œā”€ā”€ 2018
ā”‚   ā”‚   ā”œā”€ā”€ article-1.md
ā”‚   ā”‚   ā””ā”€ā”€ article-2.md
ā”‚   ā”œā”€ā”€ 2019
ā”‚   ā”‚   ā”œā”€ā”€ article-3.md
ā”‚   ā”‚   ā””ā”€ā”€ article-4.md
ā”‚   ā””ā”€ā”€ 2020
ā”‚       ā”œā”€ā”€ article-5.md
ā”‚       ā””ā”€ā”€ article-6.md
ā””ā”€ā”€ _index.md

config.toml

[permalinks]
articles = "/blog/:year/:month/:title"
1 Like

Thanks.

It seems that I had a reasonable grasp of how each method works. I was mostly wondering if either method allowed for extra functionality.

I will likely only be writing posts every two to four weeks, so organising the content by year would make more sense than by month.

I had planned to have a list of the most recent 5 or 10 posts at /blog/ and then a list of all posts for a particular year in each subdirectory. A description or summary would be shown for each post in these lists, rather than the whole text.

I agree that changing URLs is usually not a good idea.