Eleventy has some pretty cool post dating features. For my blog
though, I added a draft feature which led me to add my own custom date property,
datePublished. This also let me avoid subtle bugs that could come up when the
filesystem or git database changed for reasons other than a post edit.
This system worked pretty well but there were a few drawbacks:
I had to add the datePublished to each post's frontmatter
Posts appear out of order in the file system
To solve these problems I configured 11ty to derive the post's datePublished
from an ISO date at the beginning of the file. One of the advantages of ISO-8601
date strings, and thus a reason why they are the only legit date format,
is that they are lexically sortable. That's a fancy way to say that if you sort
them character-by-character, you'll always end up sorting them by date.
So my solution involved parsing either the input path when computing the
datePublished and the permalink using a regular expression:
With this regex, I laid out my posts dir like so:
Next step is to extract the datePublished from the filename, and rewrite the
permalink to remove the date.
As a bonus, I wrote this sorting function for neo-tree to sort
only my posts directory in descending order: