mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-09 23:27:28 +02:00
refactor: handle all admonitions via JSX component (#7152)
Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
17fe43ecc8
commit
5746c58f41
39 changed files with 709 additions and 250 deletions
|
@ -1,12 +1,32 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value=[] 1`] = `""value" must be of type object"`;
|
||||
exports[`validation schemas admonitionsSchema: for value=[] 1`] = `""value" does not look like a valid admonitions config"`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value=3 1`] = `""value" must be of type object"`;
|
||||
exports[`validation schemas admonitionsSchema: for value={"customTypes":{"myKeyword":{"keyword":"myKeyword","infima":true,"svg":"<svg width=\\"512px\\" height=\\"512px\\" viewBox=\\"0 0 512 512\\" xmlns=\\"http://www.w3.org/2000/svg\\"></svg>"}}} 1`] = `
|
||||
"The Docusaurus admonitions system has changed, and the option "customTypes" does not exist anymore.
|
||||
You now need to swizzle the admonitions component to provide UI customizations such as icons.
|
||||
Please refer to https://github.com/facebook/docusaurus/pull/7152 for detailed upgrade instructions."
|
||||
`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value=null 1`] = `""value" must be of type object"`;
|
||||
exports[`validation schemas admonitionsSchema: for value={"icons":"emoji"} 1`] = `
|
||||
"The Docusaurus admonitions system has changed, and the option "icons" does not exist anymore.
|
||||
You now need to swizzle the admonitions component to provide UI customizations such as icons.
|
||||
Please refer to https://github.com/facebook/docusaurus/pull/7152 for detailed upgrade instructions."
|
||||
`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value=true 1`] = `""value" must be of type object"`;
|
||||
exports[`validation schemas admonitionsSchema: for value={"infima":true} 1`] = `
|
||||
"The Docusaurus admonitions system has changed, and the option "infima" does not exist anymore.
|
||||
You now need to swizzle the admonitions component to provide UI customizations such as icons.
|
||||
Please refer to https://github.com/facebook/docusaurus/pull/7152 for detailed upgrade instructions."
|
||||
`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value={"keywords":[]} 1`] = `""keywords" does not contain 1 required value(s)"`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value={"tag":""} 1`] = `""tag" is not allowed to be empty"`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value={"unknownAttribute":"val"} 1`] = `""unknownAttribute" is not allowed"`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value=3 1`] = `""value" does not look like a valid admonitions config"`;
|
||||
|
||||
exports[`validation schemas pathnameSchema: for value="foo" 1`] = `""value" is not a valid pathname. Pathname should start with slash and not contain any domain or query string."`;
|
||||
|
||||
|
|
|
@ -87,17 +87,39 @@ describe('validation schemas', () => {
|
|||
it('admonitionsSchema', () => {
|
||||
const {testOK, testFail} = createTestHelpers({
|
||||
schema: AdmonitionsSchema,
|
||||
defaultValue: {},
|
||||
defaultValue: true,
|
||||
});
|
||||
|
||||
testOK(undefined);
|
||||
testOK(true);
|
||||
testOK(false);
|
||||
testOK({});
|
||||
testOK({attr: 'val'});
|
||||
testOK({tag: '+++'});
|
||||
testOK({keywords: ['info', 'tip']});
|
||||
testOK({tag: '+++', keywords: ['info', 'tip']});
|
||||
|
||||
testFail(null);
|
||||
testFail(3);
|
||||
testFail(true);
|
||||
testFail([]);
|
||||
testFail({unknownAttribute: 'val'});
|
||||
testFail({tag: ''});
|
||||
testFail({keywords: []});
|
||||
|
||||
// Legacy types
|
||||
testFail({
|
||||
infima: true,
|
||||
});
|
||||
testFail({
|
||||
icons: 'emoji',
|
||||
});
|
||||
testFail({
|
||||
customTypes: {
|
||||
myKeyword: {
|
||||
keyword: `myKeyword`,
|
||||
infima: true,
|
||||
svg: '<svg width="512px" height="512px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"></svg>',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('remarkPluginsSchema', () => {
|
||||
|
|
|
@ -32,7 +32,31 @@ const MarkdownPluginsSchema = Joi.array()
|
|||
export const RemarkPluginsSchema = MarkdownPluginsSchema;
|
||||
export const RehypePluginsSchema = MarkdownPluginsSchema;
|
||||
|
||||
export const AdmonitionsSchema = Joi.object().default({});
|
||||
const LegacyAdmonitionConfigSchema = Joi.forbidden().messages({
|
||||
'any.unknown': `The Docusaurus admonitions system has changed, and the option {#label} does not exist anymore.
|
||||
You now need to swizzle the admonitions component to provide UI customizations such as icons.
|
||||
Please refer to https://github.com/facebook/docusaurus/pull/7152 for detailed upgrade instructions.`,
|
||||
});
|
||||
|
||||
export const AdmonitionsSchema = JoiFrontMatter.alternatives()
|
||||
.try(
|
||||
JoiFrontMatter.boolean().required(),
|
||||
JoiFrontMatter.object({
|
||||
tag: JoiFrontMatter.string(),
|
||||
keywords: JoiFrontMatter.array().items(
|
||||
JoiFrontMatter.string().required(),
|
||||
),
|
||||
// TODO Remove before 2023
|
||||
customTypes: LegacyAdmonitionConfigSchema,
|
||||
icons: LegacyAdmonitionConfigSchema,
|
||||
infima: LegacyAdmonitionConfigSchema,
|
||||
}).required(),
|
||||
)
|
||||
.default(true)
|
||||
.messages({
|
||||
'alternatives.types':
|
||||
'{{#label}} does not look like a valid admonitions config',
|
||||
});
|
||||
|
||||
// TODO how can we make this emit a custom error message :'(
|
||||
// Joi is such a pain, good luck to annoying trying to improve this
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue