mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
feat(core): simplify plugin API, support route.props (#10042)
This commit is contained in:
parent
d1590e37ac
commit
5c1d6464d8
26 changed files with 2858 additions and 2240 deletions
File diff suppressed because it is too large
Load diff
|
@ -31,7 +31,6 @@ import type {
|
|||
Options,
|
||||
PluginOptions,
|
||||
PropSidebarItemLink,
|
||||
PropSidebars,
|
||||
} from '@docusaurus/plugin-content-docs';
|
||||
import type {
|
||||
SidebarItemsGeneratorOption,
|
||||
|
@ -76,36 +75,11 @@ const createFakeActions = (contentDir: string) => {
|
|||
},
|
||||
};
|
||||
|
||||
// Query by prefix, because files have a hash at the end so it's not
|
||||
// convenient to query by full filename
|
||||
function getCreatedDataByPrefix(prefix: string) {
|
||||
const entry = Object.entries(dataContainer).find(([key]) =>
|
||||
key.startsWith(prefix),
|
||||
);
|
||||
if (!entry) {
|
||||
throw new Error(`No created entry found for prefix "${prefix}".
|
||||
Entries created:
|
||||
- ${Object.keys(dataContainer).join('\n- ')}
|
||||
`);
|
||||
}
|
||||
return JSON.parse(entry[1] as string) as PropSidebars;
|
||||
}
|
||||
|
||||
// Extra fns useful for tests!
|
||||
const utils = {
|
||||
getGlobalData: () => globalDataContainer,
|
||||
getRouteConfigs: () => routeConfigs,
|
||||
|
||||
checkVersionMetadataPropCreated: (version: LoadedVersion | undefined) => {
|
||||
if (!version) {
|
||||
throw new Error('Version not found');
|
||||
}
|
||||
const versionMetadataProp = getCreatedDataByPrefix(
|
||||
`version-${_.kebabCase(version.versionName)}-metadata-prop`,
|
||||
);
|
||||
expect(versionMetadataProp.docsSidebars).toEqual(toSidebarsProp(version));
|
||||
},
|
||||
|
||||
expectSnapshot: () => {
|
||||
// Sort the route config like in src/server/plugins/index.ts for
|
||||
// consistent snapshot ordering
|
||||
|
@ -335,11 +309,8 @@ describe('simple website', () => {
|
|||
await plugin.contentLoaded!({
|
||||
content,
|
||||
actions,
|
||||
allContent: {},
|
||||
});
|
||||
|
||||
utils.checkVersionMetadataPropCreated(currentVersion);
|
||||
|
||||
utils.expectSnapshot();
|
||||
|
||||
expect(utils.getGlobalData()).toMatchSnapshot();
|
||||
|
@ -464,14 +435,8 @@ describe('versioned website', () => {
|
|||
await plugin.contentLoaded!({
|
||||
content,
|
||||
actions,
|
||||
allContent: {},
|
||||
});
|
||||
|
||||
utils.checkVersionMetadataPropCreated(currentVersion);
|
||||
utils.checkVersionMetadataPropCreated(version101);
|
||||
utils.checkVersionMetadataPropCreated(version100);
|
||||
utils.checkVersionMetadataPropCreated(versionWithSlugs);
|
||||
|
||||
utils.expectSnapshot();
|
||||
});
|
||||
});
|
||||
|
@ -569,12 +534,8 @@ describe('versioned website (community)', () => {
|
|||
await plugin.contentLoaded!({
|
||||
content,
|
||||
actions,
|
||||
allContent: {},
|
||||
});
|
||||
|
||||
utils.checkVersionMetadataPropCreated(currentVersion);
|
||||
utils.checkVersionMetadataPropCreated(version100);
|
||||
|
||||
utils.expectSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue