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

fix(docs): forward doc frontMatter.sidebar_custom_props to linking sidebar category #7638

Merged
merged 2 commits into from Jun 16, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion packages/docusaurus-plugin-content-docs/src/props.ts
Expand Up @@ -73,10 +73,28 @@ Available document ids are:
}
}

function getCategoryLinkCustomProps(
link: SidebarItemCategoryLink | undefined,
) {
switch (link?.type) {
case 'doc':
return getDocById(link.id).frontMatter.sidebar_custom_props;
default:
return undefined;
}
}

function convertCategory(item: SidebarItemCategory): PropSidebarItemCategory {
const {link, ...rest} = item;
const href = getCategoryLinkHref(link);
return {...rest, items: item.items.map(normalizeItem), ...(href && {href})};
const customProps = item.customProps ?? getCategoryLinkCustomProps(link);

return {
...rest,
items: item.items.map(normalizeItem),
...(href && {href}),
...(customProps && {customProps}),
};
}

function normalizeItem(item: SidebarItem): PropSidebarItem {
Expand Down
1 change: 1 addition & 0 deletions website/docs/api/plugins/plugin-content-docs.md
Expand Up @@ -273,6 +273,7 @@ Accepted fields:
| `sidebar_label` | `string` | `title` | The text shown in the document sidebar for this document. |
| `sidebar_position` | `number` | Default ordering | Controls the position of a doc inside the generated sidebar slice when using `autogenerated` sidebar items. See also [Autogenerated sidebar metadata](/docs/sidebar#autogenerated-sidebar-metadata). |
| `sidebar_class_name` | `string` | `undefined` | Gives the corresponding sidebar label a special class name when using autogenerated sidebars. |
| `sidebar_custom_props` | `string` | `undefined` | Assign custom metadata to the sidebar item referencing this doc. |
| `hide_title` | `boolean` | `false` | Whether to hide the title at the top of the doc. It only hides a title declared through the front matter, and have no effect on a Markdown title at the top of your document. |
| `hide_table_of_contents` | `boolean` | `false` | Whether to hide the table of contents to the right. |
| `toc_min_heading_level` | `number` | `2` | The minimum heading level shown in the table of contents. Must be between 2 and 6 and lower or equal to the max value. |
Expand Down