Feature created metadata#12034
Conversation
…sted) Resolves facebook#5691 - Add created field to DocFrontMatter type (accepts a date string or Date object) - Add FrontMatterCreatedSchema in docusaurus-utils-validation - Export the new schema from the validation package index - Validate the created field in the docs plugin frontMatter schema - Parse the created front matter into a createdAt millisecond timestamp on DocMetadataBase, following the same nullable semantics as lastUpdatedAt - Add comprehensive tests for the new created front matter field
|
Hi @sameerpashaaa! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Pre-flight checklist
Motivation
This PR implements the
createdfront matter field for the@docusaurus/plugin-content-docspackage, as proposed in issue #5691.Currently, Docusaurus supports
last_updatefront matter to let authors override the last-updated date of a document. However, there is no equivalent way to specify a document's creation date through front matter. This is useful for:This PR adds a
createdfront matter field that is validated, parsed into a millisecond timestamp (createdAt), and exposed on theDocMetadataBasetype — following the exact same pattern aslast_update/lastUpdatedAt.Test Plan
Unit tests were added to
frontMatter.test.tscovering:undefinedwhen the field is absent.Integration tests were added to
docs.test.tscovering:customCreated.md) withcreated: 2024-01-15correctly producescreatedAt: new Date('2024-01-15').getTime().createdin its front matter producescreatedAt: undefined.new Date(value).getTime().To run the tests locally:
All 105 tests pass.
Test links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Changes
packages/docusaurus-utils-validation/src/validationSchemas.tsFrontMatterCreatedSchemausingJoi.date().raw()packages/docusaurus-utils-validation/src/index.tsFrontMatterCreatedSchemapackages/docusaurus-plugin-content-docs/src/frontMatter.tsDocFrontMatterSchemapackages/docusaurus-plugin-content-docs/src/docs.tscreatedfield, parsed tocreatedAtms timestamppackages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.tscreated?: Date | stringtoDocFrontMatter; addedcreatedAt?: number | nulltoDocMetadataBasewebsite/docs/api/plugins/plugin-content-docs.mdxcreatedto the front matter reference table and examplesrc/__tests__/frontMatter.test.ts,docs.test.ts, fixturecustomCreated.md, snapshotsRelated issues/PRs