feat(content-docs): draft docs excluded from build & sidebars (#6457)

Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
Jody Heavener 2022-04-13 13:02:05 -03:00 committed by GitHub
parent ee4c984bc7
commit 5fb0a2e274
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 396 additions and 58 deletions

View file

@ -247,6 +247,31 @@ exports[`loadSidebars sidebars with known sidebar item type 1`] = `
}
`;
exports[`loadSidebars sidebars with some draft items 1`] = `
{
"docs": [
{
"collapsed": true,
"collapsible": true,
"items": [
{
"id": "foo/bar",
"type": "doc",
},
{
"href": "https://github.com",
"label": "GitHub",
"type": "link",
},
],
"label": "Test",
"link": undefined,
"type": "category",
},
],
}
`;
exports[`loadSidebars undefined path 1`] = `
{
"defaultSidebar": [

View file

@ -10,6 +10,7 @@ import path from 'path';
import {loadSidebars, DisabledSidebars} from '../index';
import type {SidebarProcessorParams} from '../types';
import {DefaultSidebarItemsGenerator} from '../generator';
import type {DocMetadata} from '@docusaurus/plugin-content-docs';
describe('loadSidebars', () => {
const fixtureDir = path.join(__dirname, '__fixtures__', 'sidebars');
@ -24,6 +25,7 @@ describe('loadSidebars', () => {
frontMatter: {},
},
],
drafts: [],
version: {
contentPath: path.join(fixtureDir, 'docs'),
contentPathLocalized: path.join(fixtureDir, 'docs'),
@ -37,6 +39,16 @@ describe('loadSidebars', () => {
expect(result).toMatchSnapshot();
});
it('sidebars with some draft items', async () => {
const sidebarPath = path.join(fixtureDir, 'sidebars.json');
const paramsWithDrafts: SidebarProcessorParams = {
...params,
drafts: [{id: 'foo/baz'} as DocMetadata, {id: 'hello'} as DocMetadata],
};
const result = await loadSidebars(sidebarPath, paramsWithDrafts);
expect(result).toMatchSnapshot();
});
it('sidebars with deep level of category', async () => {
const sidebarPath = path.join(fixtureDir, 'sidebars-category.js');
const result = await loadSidebars(sidebarPath, params);

View file

@ -46,6 +46,7 @@ describe('processSidebars', () => {
const params: SidebarProcessorParams = {
sidebarItemsGenerator: StaticSidebarItemsGenerator,
docs: [],
drafts: [],
version,
numberPrefixParser: DefaultNumberPrefixParser,
categoryLabelSlugger: createSlugger(),