mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-26 21:18:47 +02:00
fix(v2): alpha 62 doc fixes (#3381)
* deprecated nextVersionLabel option * useActivePlugin failfast option * remove deprecated option nextVersionLabel * routeBasePath: '' should be forbidden * routeBasePath: '' should be forbidden * Docs: do not show version badge if there is only 1 version: https://github.com/facebook/docusaurus/issues/3362 * allow sidebars file to not exist: fallback to empty sidebars https://githu.com/facebook/docusaurus/issues/3366
This commit is contained in:
parent
2a3fe86579
commit
a4769e3f30
11 changed files with 80 additions and 35 deletions
|
@ -32,6 +32,17 @@ describe('docsClientUtils', () => {
|
|||
expect(getActivePlugin(data, '/')).toEqual(undefined);
|
||||
expect(getActivePlugin(data, '/xyz')).toEqual(undefined);
|
||||
|
||||
expect(() =>
|
||||
getActivePlugin(data, '/', {failfast: true}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Can't find active docs plugin for pathname=/, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: /ios, /android"`,
|
||||
);
|
||||
expect(() =>
|
||||
getActivePlugin(data, '/xyz', {failfast: true}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Can't find active docs plugin for pathname=/xyz, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: /ios, /android"`,
|
||||
);
|
||||
|
||||
const activePluginIos: ActivePlugin = {
|
||||
pluginId: 'pluginIosId',
|
||||
pluginData: data.pluginIosId,
|
||||
|
@ -115,6 +126,9 @@ describe('docsClientUtils', () => {
|
|||
},
|
||||
],
|
||||
};
|
||||
|
||||
expect(getActiveVersion(data, '/someUnknownPath')).toEqual(undefined);
|
||||
|
||||
expect(getActiveVersion(data, '/docs/next')?.name).toEqual('next');
|
||||
expect(getActiveVersion(data, '/docs/next/')?.name).toEqual('next');
|
||||
expect(getActiveVersion(data, '/docs/next/someDoc')?.name).toEqual('next');
|
||||
|
|
|
@ -20,13 +20,27 @@ export type ActivePlugin = {
|
|||
pluginData: GlobalPluginData;
|
||||
};
|
||||
|
||||
export type GetActivePluginOptions = {failfast?: boolean};
|
||||
|
||||
// get the data of the plugin that is currently "active"
|
||||
// ie the docs of that plugin are currently browsed
|
||||
// it is useful to support multiple docs plugin instances
|
||||
export const getActivePlugin = (
|
||||
export function getActivePlugin(
|
||||
allPluginDatas: Record<string, GlobalPluginData>,
|
||||
pathname: string,
|
||||
): ActivePlugin | undefined => {
|
||||
options: {failfast: true}, // use fail-fast option if you know for sure one plugin instance is active
|
||||
): ActivePlugin;
|
||||
export function getActivePlugin(
|
||||
allPluginDatas: Record<string, GlobalPluginData>,
|
||||
pathname: string,
|
||||
options?: GetActivePluginOptions,
|
||||
): ActivePlugin | undefined;
|
||||
|
||||
export function getActivePlugin(
|
||||
allPluginDatas: Record<string, GlobalPluginData>,
|
||||
pathname: string,
|
||||
options: GetActivePluginOptions = {},
|
||||
): ActivePlugin | undefined {
|
||||
const activeEntry = Object.entries(allPluginDatas).find(
|
||||
([_id, pluginData]) => {
|
||||
return !!matchPath(pathname, {
|
||||
|
@ -37,10 +51,22 @@ export const getActivePlugin = (
|
|||
},
|
||||
);
|
||||
|
||||
return activeEntry
|
||||
const activePlugin: ActivePlugin | undefined = activeEntry
|
||||
? {pluginId: activeEntry[0], pluginData: activeEntry[1]}
|
||||
: undefined;
|
||||
};
|
||||
|
||||
if (!activePlugin && options.failfast) {
|
||||
throw new Error(
|
||||
`Can't find active docs plugin for pathname=${pathname}, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: ${Object.values(
|
||||
allPluginDatas,
|
||||
)
|
||||
.map((plugin) => plugin.path)
|
||||
.join(', ')}`,
|
||||
);
|
||||
}
|
||||
|
||||
return activePlugin;
|
||||
}
|
||||
|
||||
export type ActiveDocContext = {
|
||||
activeVersion?: Version;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue