Organizing content directory based on year and month

Here’s how my content/ looks like:

  • content/
    • posts/
      • post1/index.md
      • post2/index.md
      • post3/index.md

So it’s basically page bundles all in one place. In order to organize them better, I’d like to put all of them in separate subdirectories of years and months like this:

  • content/
    • posts/
      • 2025/01/post1/index.md
      • 2025/02/post2/index.md
      • 2024/05/post3/index.md

But at the same time keep the url the same so it’s not affecting my URLs, so they’re all accessible via example.com/p/post1, example.com/p/post2 and so on…

Is this a “tips and tricks” posting or are you asking for help?

I’m actually looking for tips and tricks.

https://gohugo.io/configuration/permalinks

[permalinks]
posts = '/p/:slug'
1 Like

Thanks.

Wouldn’t it be cumbersome if I had like 100,000 posts all within my public/ directory(not spread out in different directories) for the OS or the web server? I mean to handle this huge number of inodes in just one directory…?

Ideally you would split it up, perhaps by year.

I just put all of my posts in my content/ based on years and months, this is fine so far, but after compilation they all went under public/p/ with no separations at all. So now imagine if I had 100,000 subdirectories in public/p, it would hit the inodes threshold, wouldn’t it?

That number is going to vary by system, and 100k is a small number. On my laptop…

$ df -i

Filesystem       Inodes   IUsed   IFree IUse% Mounted on
/dev/sda3      10010624 2149525 7861099   22% /

In the above, there are 2.1 million inodes on /dev/sda with about 8 million more available.

You’re referring to a post written 15 years ago.

I suggest you look at something a little more current:
https://en.wikipedia.org/wiki/Ext4

ext4 does not limit the number of subdirectories in a single directory, except by the inherent size limit of the directory itself

Yes, you’re right BUT I think I can’t know for sure unless I test it for myself. Otherwise, one way would be to simply forget about clean urls like: /p/post-title and use:

[permalinks]
posts = ‘/:year/:month/:slug’

This way I have everything well structured in the public/ directory under year/month/ subs as well so the performance is guaranteed. Do you agree?

Sure.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.