mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-28 16:37:07 +02:00
fix(v2): sitemap plugin should handle siteConfig.trailingSlash automatically (#4950)
* create new @docusaurus/utils-common and move applyTrailingSlash there * sitemap plugin should handle siteConfig.trailingSlash automatically * typo
This commit is contained in:
parent
4e5f0febb9
commit
aeb8e9da51
18 changed files with 127 additions and 35 deletions
|
@ -35,6 +35,15 @@ export const logValidationBugReportHint = (): void => {
|
|||
);
|
||||
};
|
||||
|
||||
function printWarning(warning?: Joi.ValidationError) {
|
||||
if (warning) {
|
||||
const warningMessages = warning.details
|
||||
.map(({message}) => message)
|
||||
.join('\n');
|
||||
console.log(chalk.yellow(warningMessages));
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizePluginOptions<T extends {id?: string}>(
|
||||
schema: Joi.ObjectSchema<T>,
|
||||
options: Partial<T>,
|
||||
|
@ -44,9 +53,12 @@ export function normalizePluginOptions<T extends {id?: string}>(
|
|||
const finalSchema = schema.append({
|
||||
id: PluginIdSchema,
|
||||
});
|
||||
const {error, value} = finalSchema.validate(options, {
|
||||
const {error, warning, value} = finalSchema.validate(options, {
|
||||
convert: false,
|
||||
});
|
||||
|
||||
printWarning(warning);
|
||||
|
||||
if (error) {
|
||||
logValidationBugReportHint();
|
||||
if (isValidationDisabledEscapeHatch) {
|
||||
|
@ -56,6 +68,7 @@ export function normalizePluginOptions<T extends {id?: string}>(
|
|||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -68,10 +81,12 @@ export function normalizeThemeConfig<T>(
|
|||
// otherwise one theme would fail validating the data of another theme
|
||||
const finalSchema = schema.unknown();
|
||||
|
||||
const {error, value} = finalSchema.validate(themeConfig, {
|
||||
const {error, warning, value} = finalSchema.validate(themeConfig, {
|
||||
convert: false,
|
||||
});
|
||||
|
||||
printWarning(warning);
|
||||
|
||||
if (error) {
|
||||
logValidationBugReportHint();
|
||||
if (isValidationDisabledEscapeHatch) {
|
||||
|
@ -112,6 +127,8 @@ export function validateFrontMatter<T>(
|
|||
abortEarly: false,
|
||||
});
|
||||
|
||||
printWarning(warning);
|
||||
|
||||
if (error) {
|
||||
const frontMatterString = JSON.stringify(frontMatter, null, 2);
|
||||
const errorDetails = error.details;
|
||||
|
@ -132,12 +149,5 @@ export function validateFrontMatter<T>(
|
|||
throw error;
|
||||
}
|
||||
|
||||
if (warning) {
|
||||
const warningMessages = warning.details
|
||||
.map(({message}) => message)
|
||||
.join('\n');
|
||||
console.log(chalk.yellow(warningMessages));
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue