danurbanowicz/eleventy-netlify-boilerplate

'Invalid DateTime' in article

coderkind opened this issue · 6 comments

Describe the bug
Hi. I'm using the boilerplate to render a static version of a Wordpress site I'm wanting to mothball, but the outputted date seems to be different between the blog postslist page and an individual post.

On the postslist page, I think the boilerplate is using postlists.njk to output a post.date, whereas on an individual post/article, it uses post.njk and tries to use machineDate and readableDate (but outputs "Invalid DateTime").

date outputs a date on the individual post/article page, but not in the same format as the postslist page. I'm hoping to display the date in the same format on both types of page.

To Reproduce
Steps to reproduce the behaviour:

  1. Go to https://coderkind-eleventy.netlify.app/blog/
  2. See dates are in a format similar to "06 Aug 2019"
  3. Go to individual post page: https://coderkind-eleventy.netlify.app/2019/08/06/13-npm-tricks-for-faster-javascript-development/
  4. Date displays as "Invalid DateTime"

Expected behavior
The date should be in a similar format on postslists and individual post pages

Additional context
Markdown format of posts: https://github.com/coderkind/coderkind-eleventy-netlify/blob/master/posts/2019/08/06/13-npm-tricks-for-faster-javascript-development/index.md

Thanks for pointing out this little discrepancy.

In the individual post template, we really ought to be using page.date instead of date. Do you mind checking if changing this in your layouts/post.njk fixes the invalid datetime?

Thanks!

Thanks for replying!

This is what is output for each of the different dates when referenced in the layouts/post.njk file:

  • date: 2019-08-06
  • page.date: Tue Aug 06 2019 01:00:00 GMT+0100 (British Summer Time)
  • machineDate:
  • readableDate:

The last two being empty values. Neither of the first two match the date format on the postslist page.

Hmmm I've just noticed that in your post frontmatter you have your date value set as a string e.g.

date: "2019-08-06"

But the date filters are probably expecting a valid YAML date value e.g.

date: 2019-08-06

Hmm; there's no option in Wordpress to format dates in a particular way when exporting, so presumably the dates in quotes is the default format? I was following this tutorial by the way (which links to your boilerplate).

OK, so using {{ page.date | machineDate }} and {{ page.date | readableDate }} in layouts/post.njk with the post frontmatter date: "2019-08-06" as supplied by your Wordpress export is parsing correctly for me on a copy of your repo.

Can you try this if you haven't already? Thanks

Thanks; that's fixed it 👍

I thought I tried page. prefixing at some stage, but obviously not. Thanks once again :)