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
docs: clarifying how dates work in frontmatter for content collections page #5234
docs: clarifying how dates work in frontmatter for content collections page #5234
Conversation
✅ Deploy Preview for astro-docs-2 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
Thanks for grabbing another issue, @jdwilkin4 ! I think this could be even more helpful if we add how to then use the date (that's always the tricky part for me, because if you then try to render Would you be willing to add another code snippet and explain that once you have your YAML date, you may wish to format it as a string and then you can either simply truncate the long string, or format something like this in your template? for more control over formatting and maybe mention that you can find an example of doing the above in a separate https://github.com/withastro/astro/blob/latest/examples/blog/src/components/FormattedDate.astro |
|
This date format is not specific to content collections, it's a YAML thing so I assume this can also have effects outside of CC |
|
Yes, it is the YAML spec, though I think it's maybe particularly a content collections issue because Zod requires this format if you want to use In plain Markdown outside of collections, it's not checking that |
Zod does not require a ISO8601 date, it accepts a JavaScript Date object, not a string. YAML (and so The nuance is important because in a normal Markdown file, if you put a ISO date in the frontmatter, you'd get a Date object and not a string |
|
Ah thanks for that! I was reading Zod docs and they said they require ISO8601, but I suppose they meant for that to be user-facing, what you'd put in your YAML (though internally they are using a date object). I noticed that So, I see a couple of options going forward:
Not gonna lie, already that section looks like it's trying to do too much, so I do think some extra date advice somewhere is necessary! So @jdwilkin4 I'll let you decide if you think you want to expand this into a full "recipe" format, guiding people how to thing about doing dates, or just continue the section here! The most important part is getting content written and published, and then we can always move it around or decide later! |
|
HI @sarah11918 !
I like going with this option 👍 I will go ahead and add those additional code examples you mentioned in your first comment here |
|
I pushed an update for adding an additional example
I wasn't able to find the Formatted date component in the blog tutorial here Should I just use the link straight to the github example here? |
|
@jdwilkin4 Yes! It's not in the blog tutorial, it's in the blog template from Astro.new. You found it! That's the right one! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jdwilkin4 for being so responsive! What do you think of my suggestions? Just made a few minor changes, and I think we can get this in for 🎃 !
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
|
I think you're going to be Astro Docs' final 🎃 merge of the year!! Thank you for your service, and plant that tree! 🌳 |
Preview link
https://deploy-preview-5234--astro-docs-2.netlify.app/en/guides/content-collections/#working-with-dates-in-the-frontmatter
Description (required)
This PR is responsible for adding a section in the content collection page on how dates work in the frontmatter
I am participating in hacktoberfest
Related issues & labels (optional)