Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(content-docs): allow custom props through _category_.json #6780

Merged
merged 3 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ describe('DefaultSidebarItemsGenerator', () => {
contentPath: '',
},
categoriesMetadata: {
'02-Guides': {collapsed: false},
'02-Guides': {
collapsed: false,
customProps: {
description: 'foo',
},
},
'02-Guides/01-SubGuides': {
label: 'SubGuides (metadata file label)',
link: {
Expand Down Expand Up @@ -230,6 +235,9 @@ describe('DefaultSidebarItemsGenerator', () => {
type: 'doc',
id: 'guides-index',
},
customProps: {
description: 'foo',
},
collapsed: false,
items: [
{type: 'doc', id: 'guide1', className: 'foo'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
const categoryMetadata =
categoriesMetadata[posixPath(path.join(autogenDir, fullPath))];
const className = categoryMetadata?.className;
const customProps = categoryMetadata?.customProps;
const {filename, numberPrefix} = numberPrefixParser(folderName);
const allItems = Object.entries(dir).map(([key, content]) =>
dirToItem(content, key, `${fullPath}/${key}`),
Expand Down Expand Up @@ -219,6 +220,7 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
collapsed: categoryMetadata?.collapsed,
position: categoryMetadata?.position ?? numberPrefix,
source: folderName,
...(customProps !== undefined && {customProps}),
...(className !== undefined && {className}),
items,
...(link && {link}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export type CategoryMetadataFile = {
collapsible?: boolean;
className?: string;
link?: SidebarItemCategoryLinkConfig | null;
customProps?: Record<string, unknown>;

// TODO should we allow "items" here? how would this work? would an
// "autogenerated" type be allowed?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const categoryMetadataFileSchema = Joi.object<CategoryMetadataFile>({
collapsible: Joi.boolean(),
className: Joi.string(),
link: sidebarItemCategoryLinkSchema,
customProps: Joi.object().unknown(),
});

export function validateCategoryMetadataFile(
Expand Down
5 changes: 5 additions & 0 deletions website/docs/guides/docs/sidebar/autogenerated.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ This is the easy tutorial!
"link": {
"type": "generated-index",
"title": "Tutorial overview"
},
"customProps": {
"description": "This description can be used in the swizzled DocCard"
}
}
```
Expand All @@ -354,6 +357,8 @@ className: red
link:
type: generated-index
title: Tutorial overview
customProps:
description: This description can be used in the swizzled DocCard
```

</TabItem>
Expand Down