Last Updated: July 25, 2019
·
654
· scornelius

Fix leading zeros when migrating a blog to Jekyll

If you're migrating an existing blog to Jekyll then you can set a permalink structure in your _config.yml file like thus:

/posts/:year/:month/:day/:title

However if the year or the month has a single digit Jekyll will pad this with a leading zero, so you get /2013/07/25/title rather than /2013/7/25/title. If your previous blog didn't pad with leading zeros you'll get a 404 on /2013/07/25/title - a Jekyll site is just a bunch of flat pages so it's too dumb to do anything clever with URLs.

Fortunately it's easy to fix. To build without leading zeros use:

/posts/:year/:i_month/:i_day/:title

Of course this is right there in the Jekyll documentation, but it took me a while to spot it!