feat(v2): add custom props for consumption by swizzled sidebar (#3888)

This commit is contained in:
Oliver Ullman 2020-12-10 11:49:21 -07:00 committed by GitHub
parent 0b05806593
commit b11c24b752
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 11 deletions

View file

@ -11,6 +11,7 @@ import importFresh from 'import-fresh';
import {
Sidebars,
SidebarItem,
SidebarItemBase,
SidebarItemLink,
SidebarItemDoc,
Sidebar,
@ -20,7 +21,7 @@ import {
import {mapValues, flatten, difference} from 'lodash';
import {getElementsAround} from '@docusaurus/utils';
type SidebarItemCategoryJSON = {
type SidebarItemCategoryJSON = SidebarItemBase & {
type: 'category';
label: string;
items: SidebarItemJSON[];
@ -96,7 +97,7 @@ function assertItem<K extends string>(
function assertIsCategory(
item: unknown,
): asserts item is SidebarItemCategoryJSON {
assertItem(item, ['items', 'label', 'collapsed']);
assertItem(item, ['items', 'label', 'collapsed', 'customProps']);
if (typeof item.label !== 'string') {
throw new Error(
`Error loading ${JSON.stringify(item)}. "label" must be a string.`,
@ -116,7 +117,7 @@ function assertIsCategory(
}
function assertIsDoc(item: unknown): asserts item is SidebarItemDoc {
assertItem(item, ['id']);
assertItem(item, ['id', 'customProps']);
if (typeof item.id !== 'string') {
throw new Error(
`Error loading ${JSON.stringify(item)}. "id" must be a string.`,
@ -125,7 +126,7 @@ function assertIsDoc(item: unknown): asserts item is SidebarItemDoc {
}
function assertIsLink(item: unknown): asserts item is SidebarItemLink {
assertItem(item, ['href', 'label']);
assertItem(item, ['href', 'label', 'customProps']);
if (typeof item.href !== 'string') {
throw new Error(
`Error loading ${JSON.stringify(item)}. "href" must be a string.`,