Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept more readable date-time format in front matter #822

Closed
DemianX0 opened this issue Dec 13, 2019 · 3 comments
Closed

Accept more readable date-time format in front matter #822

DemianX0 opened this issue Dec 13, 2019 · 3 comments

Comments

@DemianX0
Copy link

Is your feature request related to a problem? Please describe.
I'm migrating a blog from Hugo to 11ty. The date: front-matter fields include timestamp in the format "2019-07-02 22:39:39 +0200" (Hugo accepts it), while 11ty expects iso8601 ("2019-07-02T22:39:39+02:00") in Template.js.

While deploying to netlify this is the error message:

2:58:11 PM: Problem writing Eleventy templates: (more in DEBUG output)
2:58:11 PM: > date front matter value (2019-07-02 22:39:39 +0200) is invalid for ./src/<...>.md (Error):
2:58:11 PM:     Error: date front matter value (2019-07-02 22:39:39 +0200) is invalid for ./src/<...>.md
2:58:11 PM:         at Template.getMappedDate (/opt/build/repo/node_modules/@11ty/eleventy/src/Template.js:611:19)

Note: There's no difference in the date syntax, therefore this does not affect dates without a timestamp.

Describe the solution you'd like
For easier readability and migration is it possible to accept the following date: front-matter format: "2019-07-02 22:39:39 +0200"?

Describe alternatives you've considered

  • An automatic migration script to convert all date: front-matter in a site to iso8601. If there is such a script, please inform.
  • Modifying Template.js only for this deployment. Is this possible with netlify, eg. in the .node-modules folder in the git repo?

Additional context

@okitavera
Copy link

okitavera commented Dec 18, 2019

Alternative approach; the "automatic migration script"

On linux, you can use sed to replace it :

sed -i -e "s/^date: \([0-9\-]\+\) \([0-9\:]\+\) +\([0-9]\+\)/date: \1T\2+\3/g" /path/to/post.md

and then, you can use file and sed to make a batch changes across multiple child folders :

find "$(pwd)" -type f -iname '*.md' -exec sed -i -e "s/^date: \([0-9\-]\+\) \([0-9\:]\+\) +\([0-9]\+\)/date: \1T\2+\3/g" "{}" \;  

PS: That's if your date value is not quoted like this :

date: 2019-07-02 22:39:39 +0200

@zachleat
Copy link
Member

Note if it isn’t a string it does the YAML parsing and if it is a string it does Luxon fromISO https://moment.github.io/luxon/#/parsing?id=iso-8601

via https://www.11ty.dev/docs/dates/

Does eleventyComputed help here? https://www.11ty.dev/docs/data-computed/
The other thing I’d look into is gray-matter options for front matter parsing: https://www.11ty.dev/docs/data-frontmatter-customize/

(sorry for the super late reply!) It does seem unlikely that we’ll add additional date formats for this—sorry!

@zachleat
Copy link
Member

Seeing this issue and #867 has me thinking maybe another config hook is needed. Follow along over there!

andreas-mausch added a commit to andreas-mausch/eleventy-sample that referenced this issue Aug 12, 2022
Unfortunately, readable datetimes and IANA timezones are not supported:
11ty/eleventy#822
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants