-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
Disable date parsing? #62
Comments
From this issue they point to these options which show that you can use a different schema. By default Unfortunately, Also, according to this issue, it looks like the date parsing is in the YAML spec. I'm going to leave this open and see if I can come up with a working example of specifying another schema. In the meantime, I recommend quoting the strings that might look like dates or timestamps. |
@doowb thanks for the detailed response! |
Looks like this can be closed? thanks @KyleAMathews @doowb! |
Yup! Thanks @doowb! |
@KyleAMathews How did you solve it in the end? thanks. |
@doowb |
@patarapolw from my comment above and the
What isn't clear? That documentation shows how you can specify engines for parsing and stringifying front-matter. It was mentioned in the comment above as a way to specify your own |
The "engine" can be a no-op. |
@doowb Although, I did find out that this is possible, it isn't clear that I can specify Anyways, I'll post the solution for someone less smart... import matter from 'gray-matter'
import yaml from 'js-yaml'
matter(STRING, {
engines: {
yaml: s => yaml.safeLoad(s, { schema: yaml.JSON_SCHEMA })
}
})
{
resolve: 'gatsby-transformer-remark',
options: {
engines: {
yaml: {
parse: (s) => yaml.safeLoad(s, {
schema: yaml.JSON_SCHEMA,
}),
},
},
}, |
For those who came here, iit also can be disabled by '!!str 2021-02-22' syntax. By this you don't need to install js-yaml. example https://github.com/ulwlu/ulwlu.github.io/blob/master/posts/got-myname-on-mysql-releasenotes.md |
If anyone is still having this issue, I was able to fix it using the https://github.com/eemeli/yaml package. First, install the package: npm install yaml Then use it as a custom engine: import matter from 'gray-matter'
import { parse, stringify } from 'yaml'
const { data, content } = matter(source, {
engines: {
yaml: {
parse,
stringify,
},
},
}) This fix might not be needed if #147 got merged. |
Looks interesting, and it can already be easily installed by NPM-github feature. (though Git has to be installed separately)
I am not exactly sure about the package size or the solidness of the package, but I might consider yaml package as well, as it has TypeScript types built-in. Also, I am not sure about the value of function matter(s) {
const [,fm0] = s.split(/^---\r?\n/)
if (!fm0) {
return { content: s, data: {} }
}
const [fm, content = ''] = fm0.split(/\r?\n---(\r?\n)?/)
return { content, data: yaml.parse(fm) }
} About the tag, parsing to date can be forced as well, with |
Dates need to be quoted jonschlinkert/gray-matter#62
Found this issue after significant frustration trying to format a YYYY-MM-DD input through dayjs in a Next.js app and finally discovered that
instead of:
This may not be the right solution for every situation but it works fine for me, hopefully this is helpful to someone else. |
We're using gray-matter very successfully in Gatsby (thanks!). @tremby ran into an issue recently where he needs to access the original form of a date field in the frontmatter but since it's converted into a date object, he doesn't have access to it anymore. Since Gatsby handles date conversion automatically, would it be possible to turn off date parsing in gray-matter?
The text was updated successfully, but these errors were encountered: