Replies: 2 comments 1 reply
-
Interesting, I haven't looked at this in a long time, but I have some wild theories… I think this is less of an Eleventy issue and more of a "YAML parses dates" issue. https://www.11ty.dev/docs/dates/ might be a good starting point. It has a link to https://yaml.org/type/timestamp.html which is mildly interesting. I'm struggling to find some other good YAML specs/docs for dates specifically, but I did find https://symfony.com/doc/current/reference/formats/yaml.html#dates which says:
I think I might lean towards adding some other special front matter date string for your date purposes and wrap it with a custom filter that determines the format that you want to use. Like maybe if you convert it to a Date object and the hour:minute is midnight, you just display the date only but if it has a time then you can do whatever locale date formatting you want. 🤷 |
Beta Was this translation helpful? Give feedback.
-
I think in that case |
Beta Was this translation helpful? Give feedback.
-
I'd like to choose a date format in my njk templates depending on its form in the front matter. If it's just a date, e.g.,
2023-08-15
, then I'd like to display August 15, 2023; if the front matter date includes time info, e.g.,2023-08-15T10:00
, then I'd like to display August 15, 2023 10:00. Several approaches are possible, but none are very appealing.date
andtime
front matter items. But that would break sorting posts by date in collections.showTimeInPageDate
, but that seems repetitive (I already know I want to display the time because the timestamp includes time)One possible solution would be to check the date front matter item, and if it's longer than 10 characters, or contains a "T" or ":" there's time. But I can't figure out how to access the date as it appears in my front matter, that is, as a string. Can this be cone?
Or is there a better way to accomplish my goal?
Beta Was this translation helpful? Give feedback.
All reactions