mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 16:17:25 +02:00
feat(content-docs): allow custom props through _category_.json (#6780)
* feat(content-docs): allow custom props through _category_.json * refactor * documentation Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
parent
b2d6e453e3
commit
2e163a9ec4
5 changed files with 18 additions and 1 deletions
|
@ -126,7 +126,12 @@ describe('DefaultSidebarItemsGenerator', () => {
|
||||||
contentPath: '',
|
contentPath: '',
|
||||||
},
|
},
|
||||||
categoriesMetadata: {
|
categoriesMetadata: {
|
||||||
'02-Guides': {collapsed: false},
|
'02-Guides': {
|
||||||
|
collapsed: false,
|
||||||
|
customProps: {
|
||||||
|
description: 'foo',
|
||||||
|
},
|
||||||
|
},
|
||||||
'02-Guides/01-SubGuides': {
|
'02-Guides/01-SubGuides': {
|
||||||
label: 'SubGuides (metadata file label)',
|
label: 'SubGuides (metadata file label)',
|
||||||
link: {
|
link: {
|
||||||
|
@ -230,6 +235,9 @@ describe('DefaultSidebarItemsGenerator', () => {
|
||||||
type: 'doc',
|
type: 'doc',
|
||||||
id: 'guides-index',
|
id: 'guides-index',
|
||||||
},
|
},
|
||||||
|
customProps: {
|
||||||
|
description: 'foo',
|
||||||
|
},
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
items: [
|
items: [
|
||||||
{type: 'doc', id: 'guide1', className: 'foo'},
|
{type: 'doc', id: 'guide1', className: 'foo'},
|
||||||
|
|
|
@ -159,6 +159,7 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
|
||||||
const categoryMetadata =
|
const categoryMetadata =
|
||||||
categoriesMetadata[posixPath(path.join(autogenDir, fullPath))];
|
categoriesMetadata[posixPath(path.join(autogenDir, fullPath))];
|
||||||
const className = categoryMetadata?.className;
|
const className = categoryMetadata?.className;
|
||||||
|
const customProps = categoryMetadata?.customProps;
|
||||||
const {filename, numberPrefix} = numberPrefixParser(folderName);
|
const {filename, numberPrefix} = numberPrefixParser(folderName);
|
||||||
const allItems = Object.entries(dir).map(([key, content]) =>
|
const allItems = Object.entries(dir).map(([key, content]) =>
|
||||||
dirToItem(content, key, `${fullPath}/${key}`),
|
dirToItem(content, key, `${fullPath}/${key}`),
|
||||||
|
@ -219,6 +220,7 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
|
||||||
collapsed: categoryMetadata?.collapsed,
|
collapsed: categoryMetadata?.collapsed,
|
||||||
position: categoryMetadata?.position ?? numberPrefix,
|
position: categoryMetadata?.position ?? numberPrefix,
|
||||||
source: folderName,
|
source: folderName,
|
||||||
|
...(customProps !== undefined && {customProps}),
|
||||||
...(className !== undefined && {className}),
|
...(className !== undefined && {className}),
|
||||||
items,
|
items,
|
||||||
...(link && {link}),
|
...(link && {link}),
|
||||||
|
|
|
@ -216,6 +216,7 @@ export type CategoryMetadataFile = {
|
||||||
collapsible?: boolean;
|
collapsible?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
link?: SidebarItemCategoryLinkConfig | null;
|
link?: SidebarItemCategoryLinkConfig | null;
|
||||||
|
customProps?: Record<string, unknown>;
|
||||||
|
|
||||||
// TODO should we allow "items" here? how would this work? would an
|
// TODO should we allow "items" here? how would this work? would an
|
||||||
// "autogenerated" type be allowed?
|
// "autogenerated" type be allowed?
|
||||||
|
|
|
@ -164,6 +164,7 @@ const categoryMetadataFileSchema = Joi.object<CategoryMetadataFile>({
|
||||||
collapsible: Joi.boolean(),
|
collapsible: Joi.boolean(),
|
||||||
className: Joi.string(),
|
className: Joi.string(),
|
||||||
link: sidebarItemCategoryLinkSchema,
|
link: sidebarItemCategoryLinkSchema,
|
||||||
|
customProps: Joi.object().unknown(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export function validateCategoryMetadataFile(
|
export function validateCategoryMetadataFile(
|
||||||
|
|
|
@ -338,6 +338,9 @@ This is the easy tutorial!
|
||||||
"link": {
|
"link": {
|
||||||
"type": "generated-index",
|
"type": "generated-index",
|
||||||
"title": "Tutorial overview"
|
"title": "Tutorial overview"
|
||||||
|
},
|
||||||
|
"customProps": {
|
||||||
|
"description": "This description can be used in the swizzled DocCard"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -354,6 +357,8 @@ className: red
|
||||||
link:
|
link:
|
||||||
type: generated-index
|
type: generated-index
|
||||||
title: Tutorial overview
|
title: Tutorial overview
|
||||||
|
customProps:
|
||||||
|
description: This description can be used in the swizzled DocCard
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue