So, I understand that Jekyll requires year, month, and day in the permalink and on posts to work, but I don’t understand why.
Is it to protect users against duplicate post titles?
Is it an SEO thing?
Was it an early attempt at pagination?
Does Jekyll rely on it to handle ordering?
Why was this a requirement/feature?
(Please no guesses - real answers only.)
You can override the permalink to just be name.
But…, you are bound to run into duplicate issues eventually if you aren’t careful in a few months or years and you won’t even notice so your site will break silently.
Jekyll protects us against ourselves in two ways:
- by making date compulsory in the filename. So hello.md and hello.md can’t exist together as identical filenames, but 2021-01-02-hello.md
2021-01-03-hello.md do.
- by making urls unique by including date. So /hello.html and /hello.html can’t coexist but /2021/01/02/hello.html and /2021/01/03/hello.html do.
If you want to make your permalink result as /2021-01-02-hello.html without folders then you can do that.
But I’d encourage keeping the date in.
And for neatness you can figure out how to put posts in /posts/ or /blog/ as a subdirectory
/blog/2021-01-02-hello.html
by setting permalink on posts collection instead of the root permalink, so they don’t exist at the root. But you’re still as risk of duplicates.
Crawlers don’t care about posts being on a certain date URL, just that the posts can be read and even better if they are in sitemap.
The Permalink docs don’t explain why date is used in the permalink, but it is logical see that you can choose to use date in permalink or not to, and that not using date is dangerous for duplicates while using a date is safe.
Jekyll doesn’t force you to use a date in permalink but almost all the presets do use date in some way.
ie you can use a preset like
permalink: pretty
To save writing it out in full.
That turns page /abc.html into /abc/ and the same for blog posts.
Or you can have something like /2021/365/… from the day preset or /2021/52/… for week preset
If you want to drop date in URL completely you can do…
permalink: none
Which is equivalent of doing
permalink: /:categories/:title:output_ext
–
My cheatsheet
Jekyll docs
One other thought.
The need for permalink in date arises from date needed in filename. Here’s why.
If you didn’t have the file name restriction then you have to keep track of names yourself by adding your own identifier to satisfy your IDE or shell.
hello.md
hello-1.md
Because at the file level, they can’t both be hello.md.
And then you would have got URLs as
/hello.html
/hello-1.html
That is how blog posts could have ended up and still have no risk of duplicates!
I mean that’s how non blog posts work.
But… because we do have Jekyll setting date as required in post names, you must do this
2021-01-02-hello.md
2021-01-03-hello.md
That alone would mean both output as /hello.html and collide as duplicates.
So as a consequence, we must put date in the permalink for posts, for most cases.
To safely get.
/2021/01/02/hello.html
/2021/01/03/hello.html