mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
feat(content-docs): add custom props front matter (#6619)
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
parent
59289ed4d5
commit
665d164351
10 changed files with 69 additions and 8 deletions
|
@ -210,6 +210,19 @@ describe('validateDocFrontMatter sidebar_position', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('validateDocFrontMatter sidebar_custom_props', () => {
|
||||
testField({
|
||||
prefix: 'sidebar_custom_props',
|
||||
validFrontMatters: [
|
||||
{sidebar_custom_props: {}},
|
||||
{sidebar_custom_props: {prop: 'custom', number: 1, boolean: true}},
|
||||
],
|
||||
invalidFrontMatters: [
|
||||
[{sidebar_custom_props: ''}, 'must be of type object'],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateDocFrontMatter custom_edit_url', () => {
|
||||
testField({
|
||||
prefix: 'custom_edit_url',
|
||||
|
|
|
@ -30,6 +30,7 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
|
|||
sidebar_label: Joi.string(),
|
||||
sidebar_position: Joi.number(),
|
||||
sidebar_class_name: Joi.string(),
|
||||
sidebar_custom_props: Joi.object().unknown(),
|
||||
displayed_sidebar: Joi.string().allow(null),
|
||||
tags: FrontMatterTagsSchema,
|
||||
pagination_label: Joi.string(),
|
||||
|
|
|
@ -52,7 +52,8 @@ Available document ids are:
|
|||
label: sidebarLabel || item.label || title,
|
||||
href: permalink,
|
||||
className: item.className,
|
||||
customProps: item.customProps,
|
||||
customProps:
|
||||
item.customProps ?? docMetadata.frontMatter.sidebar_custom_props,
|
||||
docId: docMetadata.unversionedId,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -58,6 +58,7 @@ export type DocFrontMatter = {
|
|||
sidebar_label?: string;
|
||||
sidebar_position?: number;
|
||||
sidebar_class_name?: string;
|
||||
sidebar_custom_props?: Record<string, unknown>;
|
||||
displayed_sidebar?: string | null;
|
||||
pagination_label?: string;
|
||||
custom_edit_url?: string | null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue