Skip to content

feat(v2): exhaustive BlogPostFrontMatter schema validation - #4759

Merged
slorber merged 5 commits into
meta:masterfrom
nam-hle:strict-frontmatter
May 14, 2021
Merged

slorber merged 5 commits into
meta:masterfrom
nam-hle:strict-frontmatter

Conversation

@nam-hle

@nam-hle nam-hle commented May 8, 2021 •

Copy link
Copy Markdown
Contributor

Motivation

From #4591.

What the PR does

  • Complete the BlogPostFrontMatter typing and the corresponding Joi schema validator in packages/docusaurus-plugin-content-blog/src/blogFrontMatter.ts
  • Add unit tests
  • Display friendly messages for wrong schemas:

image

  • @slorber: Can you explain the sentence: "try to use the frontmatter TS types in the theme?" ?

I found the after parsing the frontmatter use gray-matter package, the date field will be converted to a Date object, not a raw string. But we are treating it as a string. Currently there is no problem about it, but maybe furture.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Unit test.

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label May 8, 2021
@netlify

netlify Bot commented May 8, 2021 •

Copy link
Copy Markdown

@github-actions

github-actions Bot commented May 8, 2021 •

Copy link
Copy Markdown

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 76
🟢 Accessibility 96
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4759--docusaurus-2.netlify.app/

@nam-hle nam-hle changed the title Validate BlogPostFrontMatter and add tests Strict Validate BlogPostFrontMatter schema May 8, 2021
@nam-hle
nam-hle force-pushed the strict-frontmatter branch from e3f0ae6 to 9db8ac4 Compare May 9, 2021 02:47
@nam-hle nam-hle changed the title Strict Validate BlogPostFrontMatter schema fix(v2): improve BlogPostFrontMatter schema validation May 9, 2021
@nam-hle
nam-hle marked this pull request as ready for review May 9, 2021 03:07
@nam-hle
nam-hle requested review from lex111 and slorber as code owners May 9, 2021 03:07

@slorber slorber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Overall that looks good. Added a few useful changes to do

Comment thread website/docs/blog.md Resolved

@nam-hle nam-hle left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing. I add an annotation for deprecated fields and provide warning messages for them.

Comment thread website/docs/blog.md Resolved
@netlify

netlify Bot commented May 14, 2021 •

Copy link
Copy Markdown

@slorber

slorber commented May 14, 2021

Copy link
Copy Markdown
Collaborator

Thanks, that looks great!

Disabling the warnings for now as our own blog posts are still using those frontmatters (content is shared between v1/v2 so we can't update the frontmatter)

@slorber
slorber merged commit e092910 into meta:master May 14, 2021
@slorber slorber added the pr: new feature This PR adds a new API or behavior. label May 14, 2021
@slorber slorber changed the title fix(v2): improve BlogPostFrontMatter schema validation feat(v2): improve BlogPostFrontMatter schema validation May 14, 2021
@slorber slorber changed the title feat(v2): improve BlogPostFrontMatter schema validation feat(v2): exhaustive BlogPostFrontMatter schema validation May 14, 2021
@nam-hle
nam-hle deleted the strict-frontmatter branch May 15, 2021 00:25
@nam-hle

nam-hle commented May 15, 2021

Copy link
Copy Markdown
Contributor Author

Thanks. Now I can work on the docs frontmatter smoothly :D

mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
* fix(v2): improve BlogPostFrontMatter schema validation

* Edit doc

* Add deprecate warning message

* minor changes, disable warnings temporarily

* only disable warnings + fix frontmatter date type

Co-authored-by: Nam Hoang Le <[email protected]>
Co-authored-by: slorber <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants