Describe the bug
NetlifyCMS breaks trying to parse dates of the format YYYY-MM-DD in the front-matter.
To Reproduce
Have a collections config like this:
collections:
- name: "blog" # Used in routes, e.g., /admin/collections/blog
label: "Blog" # Used in the UI
folder: "content/blog" # The path to the folder where the documents are stored
format: toml-frontmatter
create: true # Allow users to create new documents in this collection
fields: # The fields for each document, usually in front matter
- {label: "Title", name: "title", widget: "string"}
- {label: "Date", name: "date", widget: "date", format: "YYYY-MM-DD"}
- {label: "Body", name: "body", widget: "markdown"}
Have a blog article with the following front matter:
title = "An Example Blog"
date = 2018-12-14
+++
This is an example blog
You will see this in the console:
Object { message: "Expected \"T\" but \"\\n\" found.", line: 3, column: 18, stack: "" }
Expected behavior
The collection date is parsed correctly.
@cetra3 I think the issue here is the frontmatter. The right format should look like so:
title = "An Example Blog"
date = "2018-12-14"
+++
May I ask, was the frontmatter generated via the CMS?
The frontmatter was not generated by netlify, it was an existing blog that wasn't read.
According to the TOML spec dates do not require quotes:
Local Date
If you include only the date portion of an RFC 3339 formatted date-time, it will represent that entire day without any relation to an offset or timezone.
ld1 = 1979-05-27
@cetra3 investigated this issue further and the error seems to be coming from toml-j0.4 parser we are using to parse toml files. The parser only recognizes datetime format https://jakwings.github.io/toml-j0.4/. The simple workaround at the moment is to inclose your values in quotes.
Good point @barthc. @cetra3 if you're up for opening an issue in the toml parser repo, that would be the place for a fix to occur.
Actually, this isn't a bug so much as an improvement request: Netlify CMS currently supports TOML 0.4, which doesn't support this. The linked spec is for TOML 0.5, which doesn't yet have a stable release.
Ah, that makes sense. The error message makes it look like it's coming from moment.js though.
Isn't https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.5.0.md a stable release from 2018?
It has a pre-release tag on the GH release page but so does every versions.
Looks like Netlify CMS is using toml-j0.4 as its parser, which does not support TOML 0.5, and has not seen active development for two years. Thus, resolving this likely means replacing the parser with another library.
Yep, it's about the library we're using, not the spec.