mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 08:37:25 +02:00
feat(content-docs): sidebar category linking to document or auto-generated index page (#5830)
Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: Armano <armano2@users.noreply.github.com> Co-authored-by: Alexey Pyltsyn <lex61rus@gmail.com>
This commit is contained in:
parent
95f911efef
commit
cfae5d0933
105 changed files with 3904 additions and 816 deletions
|
@ -11,7 +11,8 @@ import {
|
|||
processDocMetadata,
|
||||
readVersionDocs,
|
||||
readDocFile,
|
||||
handleNavigation,
|
||||
addDocNavigation,
|
||||
isConventionalDocIndex,
|
||||
} from '../docs';
|
||||
import {loadSidebars} from '../sidebars';
|
||||
import {readVersionsMetadata} from '../versions';
|
||||
|
@ -28,7 +29,8 @@ import type {LoadContext} from '@docusaurus/types';
|
|||
import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
|
||||
import {DEFAULT_OPTIONS} from '../options';
|
||||
import {Optional} from 'utility-types';
|
||||
import {posixPath} from '@docusaurus/utils';
|
||||
import {createSlugger, posixPath} from '@docusaurus/utils';
|
||||
import {createSidebarsUtils} from '../sidebars/utils';
|
||||
|
||||
const fixtureDir = path.join(__dirname, '__fixtures__');
|
||||
|
||||
|
@ -119,7 +121,7 @@ function createTestUtils({
|
|||
|
||||
async function generateNavigation(
|
||||
docFiles: DocFile[],
|
||||
): Promise<[DocNavLink, DocNavLink][]> {
|
||||
): Promise<[DocNavLink | undefined, DocNavLink | undefined][]> {
|
||||
const rawDocs = await Promise.all(
|
||||
docFiles.map((docFile) =>
|
||||
processDocMetadata({
|
||||
|
@ -136,16 +138,19 @@ function createTestUtils({
|
|||
numberPrefixParser: options.numberPrefixParser,
|
||||
docs: rawDocs,
|
||||
version: versionMetadata,
|
||||
options: {
|
||||
sidebarOptions: {
|
||||
sidebarCollapsed: false,
|
||||
sidebarCollapsible: true,
|
||||
},
|
||||
categoryLabelSlugger: createSlugger(),
|
||||
});
|
||||
return handleNavigation(
|
||||
const sidebarsUtils = createSidebarsUtils(sidebars);
|
||||
|
||||
return addDocNavigation(
|
||||
rawDocs,
|
||||
sidebars,
|
||||
sidebarsUtils,
|
||||
versionMetadata.sidebarFilePath as string,
|
||||
).docs.map((doc) => [doc.previous, doc.next]);
|
||||
).map((doc) => [doc.previous, doc.next]);
|
||||
}
|
||||
|
||||
return {processDocFile, testMeta, testSlug, generateNavigation};
|
||||
|
@ -1022,3 +1027,113 @@ describe('versioned site', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isConventionalDocIndex', () => {
|
||||
test('supports readme', () => {
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'doesNotMatter',
|
||||
source: 'readme.md',
|
||||
}),
|
||||
).toEqual(true);
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'doesNotMatter',
|
||||
source: 'readme.mdx',
|
||||
}),
|
||||
).toEqual(true);
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'doesNotMatter',
|
||||
source: 'README.md',
|
||||
}),
|
||||
).toEqual(true);
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'doesNotMatter',
|
||||
source: 'parent/ReAdMe',
|
||||
}),
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
test('supports index', () => {
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'doesNotMatter',
|
||||
source: 'index.md',
|
||||
}),
|
||||
).toEqual(true);
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'doesNotMatter',
|
||||
source: 'index.mdx',
|
||||
}),
|
||||
).toEqual(true);
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'doesNotMatter',
|
||||
source: 'INDEX.md',
|
||||
}),
|
||||
).toEqual(true);
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'doesNotMatter',
|
||||
source: 'parent/InDeX',
|
||||
}),
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
test('supports <categoryName>/<categoryName>.md', () => {
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'someCategory',
|
||||
source: 'someCategory',
|
||||
}),
|
||||
).toEqual(true);
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'someCategory',
|
||||
source: 'someCategory.md',
|
||||
}),
|
||||
).toEqual(true);
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'someCategory',
|
||||
source: 'someCategory.mdx',
|
||||
}),
|
||||
).toEqual(true);
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'some_category',
|
||||
source: 'SOME_CATEGORY.md',
|
||||
}),
|
||||
).toEqual(true);
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'some_category',
|
||||
source: 'parent/some_category',
|
||||
}),
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
test('reject other cases', () => {
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'someCategory',
|
||||
source: 'some_Category',
|
||||
}),
|
||||
).toEqual(false);
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'doesNotMatter',
|
||||
source: 'read_me',
|
||||
}),
|
||||
).toEqual(false);
|
||||
expect(
|
||||
isConventionalDocIndex({
|
||||
sourceDirName: 'doesNotMatter',
|
||||
source: 'the index',
|
||||
}),
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue