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

Respect datetime format used in markdown file frontmatter YAML #2617

Closed
wadclapp opened this issue Apr 21, 2024 · 2 comments
Closed

Respect datetime format used in markdown file frontmatter YAML #2617

wadclapp opened this issue Apr 21, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@wadclapp
Copy link

Is your feature request related to a problem? Please describe

If I have a date saved in the format YYYY-MM-DD in a md file's frontmatter, like so

---
dateCreated: 2024-04-21T00:00:00.000Z
dateModified: 2024-04-21
---

{{ dateCreated }} <-- prints as 2024-04-21T00:00:00.000Z
{{ dateModified }} <-- also prints as 2024-04-21T00:00:00.000Z

and in queryContent(path).findOne() result all dates have time (T00:00:00.000Z) added.

The CMS I use has a datepicker UI, and saves it as a datetime, so I can't save '2024-04-21' as a string or else I don't get the UI functionality.

Describe the solution you'd like

Print the date as the format it's saved in the md file as, i.e. dateModified would be 2024-04-21, not 2024-04-21T00:00:00.000Z

Describe alternatives you've considered

I'm currently just replacing all T00:00:00.000Z occurrences from the queryContent result.

Additional context

@wadclapp wadclapp added the enhancement New feature or request label Apr 21, 2024
@farnabaz
Copy link
Member

Content module uses js-yaml under the hood to parse front-matter and js-yaml converts time/date into Date object. That's why different formats will end up with same result.

I'm currently just replacing all T00:00:00.000Z occurrences from the queryContent result.

I would create a component and pass the variable via props to it. This way you can render custom tags and custom formats too.

---
dateCreated: 2024-04-21T00:00:00.000Z
dateModified: 2024-04-21
---

:pretty-time{:date="dateCreated"}

:pretty-time{:date="dateModified"}

@wadclapp
Copy link
Author

that'll work, I'll close the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants