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

fix: add docs tag validation to solve #5478 #5479

Merged
merged 6 commits into from
Sep 3, 2021
Merged

Conversation

swyxio
Copy link
Contributor

@swyxio swyxio commented Sep 3, 2021

fix: add docs tag validation to solve #5478

Motivation

nicer developer experience when people put in malformed tags, as suggested by @Josh-Cena #5478 (comment)

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

i confess i did not test this one locally. hoping its a simple one.

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Sep 3, 2021
Comment on lines 30 to 33
tags: [Joi.string(), Joi.array().items(Joi.object({
label: Joi.string,
permalink: Joi.string
}))]
Copy link
Collaborator

@Josh-Cena Josh-Cena Sep 3, 2021

Choose a reason for hiding this comment

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

Suggested change
tags: [Joi.string(), Joi.array().items(Joi.object({
label: Joi.string,
permalink: Joi.string
}))]
tags: Joi.array().items(Joi.alternatives().try(
Joi.string(),
Joi.object({
label: Joi.string().required(),
permalink: Joi.string().required(),
}),
)),

Joi is really a pain, yeah

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, there's a FrontMatterTagsSchema from utils-validation. See here:

import {
JoiFrontMatter as Joi, // Custom instance for frontmatter
URISchema,
validateFrontMatter,
FrontMatterTagsSchema,
} from '@docusaurus/utils-validation';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you!

@Josh-Cena
Copy link
Collaborator

Also, maybe we can elaborate in the documentation? After some pondering I think it's worth documenting both possibilities to avoid confusion.

@swyxio
Copy link
Contributor Author

swyxio commented Sep 3, 2021

added!

@netlify
Copy link

netlify bot commented Sep 3, 2021

✔️ [V2]
Built without sensitive environment variables

🔨 Explore the source changes: 07cc898

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/6131db85383ece000808ec17

😎 Browse the preview: https://deploy-preview-5479--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Sep 3, 2021

⚡️ Lighthouse report for the changes in this PR:

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

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

@netlify
Copy link

netlify bot commented Sep 3, 2021

✔️ [V2]

🔨 Explore the source changes: 8166cac

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/6132038502ac780007994f1e

😎 Browse the preview: https://deploy-preview-5479--docusaurus-2.netlify.app

@slorber
Copy link
Collaborator

slorber commented Sep 3, 2021

Thanks,

I'll edit it a bit before merge because Joi default messages are so bad in this case :)

@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Sep 3, 2021
@slorber slorber linked an issue Sep 3, 2021 that may be closed by this pull request
@slorber slorber merged commit 194f429 into facebook:main Sep 3, 2021
@swyxio swyxio deleted the patch-1 branch September 22, 2021 17:40
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: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

beta.5 docs tags feature - better validation for malformed tags
4 participants