Fredrik P
Fredrik P

Reputation: 694

How to enter a YYYYMM date in Jekyll?

How should dates be entered in Jekyll?

I would like to enter the date "August 2018" in a YAML file to be used in Jekyll. I find lots of information on how to format already-existing dates, but pretty much nothing on how to enter them.

The best I have managed to find is Date formatting, which implies that dates entered in ISO 8601 format should be valid. If I run with this, then Wikipedia explicitly states

"2004-05" is a valid ISO 8601 date, which indicates May (the fifth month) 2004.

This implies that "August 2018" could be entered as 2018-08.

However, when I use my YAML file my_data.yml in my _data folder

date: 2018-08

then Jekyll doesn't recognize it as a date as

{{ site.data.my_data.date | time: '%B %Y' }}

outputs "2018-08" and not "August 2018".

Upvotes: 2

Views: 354

Answers (1)

Fredrik P
Fredrik P

Reputation: 694

TL;DR: Enter YYYYMM dates such as "August 2018" as Aug 2018.

Searching through the Jekyll repo, I found the date filters. The Ruby on Rails method .to_formatted_s (source) seem to be key to most of them. In the source to that method dates are written as Tue, 04 Dec 2007 00:00:00 +0000 from which I guessed that I should write Aug 2018. Doing so in my_data.yml, the code outputs the expected “August 2018”.

Upvotes: 2

Related Questions