mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-27 21:48:41 +02:00
feat(v2): improve DocFrontMatter schema validation (#4796)
Co-authored-by: Nam Hoang Le <nam.hoang.le@mgm-tp.com>
This commit is contained in:
parent
0360364570
commit
fa7aa08100
3 changed files with 193 additions and 27 deletions
|
@ -5,15 +5,20 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import {
|
||||
JoiFrontMatter as Joi, // Custom instance for frontmatter
|
||||
validateFrontMatter,
|
||||
} from '@docusaurus/utils-validation';
|
||||
|
||||
// TODO complete this frontmatter + add unit tests
|
||||
export type DocFrontMatter = {
|
||||
id?: string;
|
||||
title?: string;
|
||||
hide_title?: boolean;
|
||||
hide_table_of_contents?: boolean;
|
||||
keywords?: string[];
|
||||
image?: string;
|
||||
description?: string;
|
||||
slug?: string;
|
||||
sidebar_label?: string;
|
||||
|
@ -29,13 +34,17 @@ export type DocFrontMatter = {
|
|||
const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
|
||||
id: Joi.string(),
|
||||
title: Joi.string().allow(''), // see https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
|
||||
hide_title: Joi.boolean(),
|
||||
hide_table_of_contents: Joi.boolean(),
|
||||
keywords: Joi.array().items(Joi.string().required()),
|
||||
image: Joi.string().uri({allowRelative: false}),
|
||||
description: Joi.string().allow(''), // see https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
|
||||
slug: Joi.string(),
|
||||
sidebar_label: Joi.string(),
|
||||
sidebar_position: Joi.number(),
|
||||
custom_edit_url: Joi.string().allow('', null),
|
||||
sidebar_position: Joi.number().min(0),
|
||||
custom_edit_url: Joi.string().uri({allowRelative: true}).allow('', null),
|
||||
parse_number_prefixes: Joi.boolean(),
|
||||
});
|
||||
}).unknown();
|
||||
|
||||
export function validateDocFrontMatter(
|
||||
frontMatter: Record<string, unknown>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue