feat(content-docs): allow explicitly disabling index page for generated category (#6452)

* feat(content-docs): allow explicitly disabling index page for generated category

* docs

* add test
This commit is contained in:
Joshua Chen 2022-01-27 23:14:07 +08:00 committed by GitHub
parent ffa108b58b
commit 3c58d7f027
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 3 deletions

View file

@ -416,6 +416,10 @@ describe('DefaultSidebarItemsGenerator', () => {
id: 'doc3', // Using a "local doc id" ("doc1" instead of "parent/doc1") on purpose
},
},
'Category2/_category_.yml': {
label: 'Category 2 label',
link: null,
},
});
const sidebarSlice = await DefaultSidebarItemsGenerator({
@ -447,6 +451,24 @@ describe('DefaultSidebarItemsGenerator', () => {
sourceDirName: 'Category',
frontMatter: {},
},
{
id: 'parent/doc4',
source: '@site/docs/Category2/doc1.md',
sourceDirName: 'Category2',
frontMatter: {},
},
{
id: 'parent/doc5',
source: '@site/docs/Category2/index.md',
sourceDirName: 'Category2',
frontMatter: {},
},
{
id: 'parent/doc6',
source: '@site/docs/Category2/doc3.md',
sourceDirName: 'Category2',
frontMatter: {},
},
],
options: {
sidebarCollapsed: true,
@ -475,6 +497,26 @@ describe('DefaultSidebarItemsGenerator', () => {
},
],
},
{
type: 'category',
label: 'Category 2 label',
collapsed: true,
collapsible: true,
items: [
{
id: 'parent/doc4',
type: 'doc',
},
{
id: 'parent/doc5',
type: 'doc',
},
{
id: 'parent/doc6',
type: 'doc',
},
],
},
] as Sidebar);
});

View file

@ -45,7 +45,7 @@ export type CategoryMetadataFile = {
collapsed?: boolean;
collapsible?: boolean;
className?: string;
link?: SidebarItemCategoryLinkConfig;
link?: SidebarItemCategoryLinkConfig | null;
// TODO should we allow "items" here? how would this work? would an "autogenerated" type be allowed?
// This mkdocs plugin do something like that: https://github.com/lukasgeiter/mkdocs-awesome-pages-plugin/
@ -222,8 +222,8 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
function getCategoryLinkedDocId(): string | undefined {
const link = categoryMetadata?.link;
if (link) {
if (link.type === 'doc') {
if (link !== undefined) {
if (link && link.type === 'doc') {
return findDocByLocalId(link.id)?.id || getDoc(link.id).id;
} else {
// We don't continue for other link types on purpose!

View file

@ -56,6 +56,7 @@ const sidebarItemLinkSchema = sidebarItemBaseSchema.append<SidebarItemLink>({
});
const sidebarItemCategoryLinkSchema = Joi.object<SidebarItemCategoryLink>()
.allow(null)
.when('.type', {
switch: [
{