mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
fix(content-docs): restore functionality when a category only has index page (#7385)
* fix(content-docs): restore functionality when a category only has index page * use this internally
This commit is contained in:
parent
c3880cc342
commit
6e10a48059
13 changed files with 258 additions and 46 deletions
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"docs": [
|
||||
{
|
||||
"label": "Tutorials",
|
||||
"type": "category",
|
||||
"items": [
|
||||
{
|
||||
"type": "autogenerated",
|
||||
"dirName": "tutorials"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "index-only",
|
||||
"type": "category",
|
||||
"link": {
|
||||
"type": "doc",
|
||||
"id": "tutorials/tutorial-basics"
|
||||
},
|
||||
"items": []
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
{
|
||||
"sidebar": [
|
||||
"draft1",
|
||||
{
|
||||
"type": "category",
|
||||
"label": "all drafts",
|
||||
"items": [
|
||||
"draft2",
|
||||
"draft3"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "category",
|
||||
"label": "all drafts",
|
||||
"link": {
|
||||
"type": "generated-index"
|
||||
},
|
||||
"items": [
|
||||
"draft2",
|
||||
"draft3"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "category",
|
||||
"label": "all drafts",
|
||||
"link": {
|
||||
"type": "doc",
|
||||
"id": "draft1"
|
||||
},
|
||||
"items": [
|
||||
"draft2",
|
||||
"draft3"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "category",
|
||||
"label": "index not draft",
|
||||
"link": {
|
||||
"type": "doc",
|
||||
"id": "not-draft"
|
||||
},
|
||||
"items": [
|
||||
"draft2",
|
||||
"draft3"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "category",
|
||||
"label": "subitem not draft",
|
||||
"link": {
|
||||
"type": "doc",
|
||||
"id": "draft1"
|
||||
},
|
||||
"items": [
|
||||
"not-draft",
|
||||
"draft3"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,5 +1,56 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`loadSidebars loads sidebars with index-only categories 1`] = `
|
||||
{
|
||||
"docs": [
|
||||
{
|
||||
"collapsed": true,
|
||||
"collapsible": true,
|
||||
"items": [
|
||||
{
|
||||
"id": "tutorials/tutorial-basics",
|
||||
"label": "tutorial-basics",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "Tutorials",
|
||||
"link": undefined,
|
||||
"type": "category",
|
||||
},
|
||||
{
|
||||
"id": "tutorials/tutorial-basics",
|
||||
"label": "index-only",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`loadSidebars loads sidebars with interspersed draft items 1`] = `
|
||||
{
|
||||
"sidebar": [
|
||||
{
|
||||
"id": "not-draft",
|
||||
"label": "index not draft",
|
||||
"type": "doc",
|
||||
},
|
||||
{
|
||||
"collapsed": true,
|
||||
"collapsible": true,
|
||||
"items": [
|
||||
{
|
||||
"id": "not-draft",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "subitem not draft",
|
||||
"link": undefined,
|
||||
"type": "category",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`loadSidebars sidebars link 1`] = `
|
||||
{
|
||||
"docs": [
|
||||
|
|
|
@ -60,14 +60,21 @@ exports[`postProcess corrects collapsed state inconsistencies 3`] = `
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`postProcess transforms category without subitems 1`] = `
|
||||
exports[`postProcess filters draft items 1`] = `
|
||||
{
|
||||
"sidebar": [
|
||||
{
|
||||
"href": "version/generated/permalink",
|
||||
"id": "another",
|
||||
"label": "Category",
|
||||
"type": "link",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`postProcess transforms category without subitems 1`] = `
|
||||
{
|
||||
"sidebar": [
|
||||
{
|
||||
"id": "doc ID",
|
||||
"label": "Category 2",
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
import {jest} from '@jest/globals';
|
||||
import path from 'path';
|
||||
import {createSlugger} from '@docusaurus/utils';
|
||||
import {loadSidebars, DisabledSidebars} from '../index';
|
||||
import type {SidebarProcessorParams} from '../types';
|
||||
import {DefaultSidebarItemsGenerator} from '../generator';
|
||||
|
@ -27,6 +28,7 @@ describe('loadSidebars', () => {
|
|||
],
|
||||
drafts: [],
|
||||
version: {
|
||||
path: 'version',
|
||||
contentPath: path.join(fixtureDir, 'docs'),
|
||||
contentPathLocalized: path.join(fixtureDir, 'docs'),
|
||||
},
|
||||
|
@ -124,6 +126,32 @@ describe('loadSidebars', () => {
|
|||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('loads sidebars with index-only categories', async () => {
|
||||
const sidebarPath = path.join(fixtureDir, 'sidebars-category-index.json');
|
||||
const result = await loadSidebars(sidebarPath, {
|
||||
...params,
|
||||
docs: [
|
||||
{
|
||||
id: 'tutorials/tutorial-basics',
|
||||
source: '@site/docs/tutorials/tutorial-basics/index.md',
|
||||
sourceDirName: 'tutorials/tutorial-basics',
|
||||
frontMatter: {},
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('loads sidebars with interspersed draft items', async () => {
|
||||
const sidebarPath = path.join(fixtureDir, 'sidebars-drafts.json');
|
||||
const result = await loadSidebars(sidebarPath, {
|
||||
...params,
|
||||
drafts: [{id: 'draft1'}, {id: 'draft2'}, {id: 'draft3'}],
|
||||
categoryLabelSlugger: createSlugger(),
|
||||
});
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('duplicate category metadata files', async () => {
|
||||
const sidebarPath = path.join(
|
||||
fixtureDir,
|
||||
|
|
|
@ -35,6 +35,7 @@ describe('postProcess', () => {
|
|||
{
|
||||
sidebarOptions: {sidebarCollapsed: true, sidebarCollapsible: true},
|
||||
version: {path: 'version'},
|
||||
drafts: [],
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -54,6 +55,7 @@ describe('postProcess', () => {
|
|||
{
|
||||
sidebarOptions: {sidebarCollapsed: true, sidebarCollapsible: true},
|
||||
version: {path: 'version'},
|
||||
drafts: [],
|
||||
},
|
||||
);
|
||||
}).toThrowErrorMatchingInlineSnapshot(
|
||||
|
@ -79,6 +81,7 @@ describe('postProcess', () => {
|
|||
{
|
||||
sidebarOptions: {sidebarCollapsed: true, sidebarCollapsible: true},
|
||||
version: {path: 'version'},
|
||||
drafts: [],
|
||||
},
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
|
@ -99,6 +102,7 @@ describe('postProcess', () => {
|
|||
{
|
||||
sidebarOptions: {sidebarCollapsed: false, sidebarCollapsible: false},
|
||||
version: {path: 'version'},
|
||||
drafts: [],
|
||||
},
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
|
@ -118,6 +122,37 @@ describe('postProcess', () => {
|
|||
{
|
||||
sidebarOptions: {sidebarCollapsed: true, sidebarCollapsible: false},
|
||||
version: {path: 'version'},
|
||||
drafts: [],
|
||||
},
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('filters draft items', () => {
|
||||
expect(
|
||||
postProcessSidebars(
|
||||
{
|
||||
sidebar: [
|
||||
{
|
||||
type: 'category',
|
||||
label: 'Category',
|
||||
items: [{type: 'doc', id: 'foo'}],
|
||||
},
|
||||
{
|
||||
type: 'category',
|
||||
label: 'Category',
|
||||
link: {
|
||||
type: 'doc',
|
||||
id: 'another',
|
||||
},
|
||||
items: [{type: 'doc', id: 'foo'}],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
sidebarOptions: {sidebarCollapsed: true, sidebarCollapsible: true},
|
||||
version: {path: 'version'},
|
||||
drafts: [{id: 'foo', unversionedId: 'foo'}],
|
||||
},
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue