mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 09:07:29 +02:00
fix(content-docs): make getActivePlugin match plugin paths more exactly (#6435)
* fix(content-docs): make getActivePlugin match plugin IDs more exactly * refactor...
This commit is contained in:
parent
cbcbdaa9d3
commit
64909e7f14
2 changed files with 44 additions and 10 deletions
|
@ -6,14 +6,17 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
type ActivePlugin,
|
||||
getActivePlugin,
|
||||
getLatestVersion,
|
||||
getActiveDocContext,
|
||||
getActiveVersion,
|
||||
getDocVersionSuggestions,
|
||||
} from '../docsClientUtils';
|
||||
import type {GlobalPluginData, GlobalVersion} from '../../types';
|
||||
import type {
|
||||
GlobalPluginData,
|
||||
GlobalVersion,
|
||||
ActivePlugin,
|
||||
} from '@docusaurus/plugin-content-docs/client';
|
||||
import {shuffle} from 'lodash';
|
||||
|
||||
describe('docsClientUtils', () => {
|
||||
|
@ -58,6 +61,34 @@ describe('docsClientUtils', () => {
|
|||
expect(getActivePlugin(data, '/android')).toEqual(activePluginAndroid);
|
||||
expect(getActivePlugin(data, '/android/')).toEqual(activePluginAndroid);
|
||||
expect(getActivePlugin(data, '/android/ijk')).toEqual(activePluginAndroid);
|
||||
|
||||
// https://github.com/facebook/docusaurus/issues/6434
|
||||
const onePluginAtRoot = {
|
||||
pluginIosId: {
|
||||
path: '/',
|
||||
versions: [],
|
||||
},
|
||||
pluginAndroidId: {
|
||||
path: '/android',
|
||||
versions: [],
|
||||
},
|
||||
};
|
||||
expect(getActivePlugin(onePluginAtRoot, '/android/foo').pluginId).toEqual(
|
||||
'pluginAndroidId',
|
||||
);
|
||||
const onePluginAtRootReversed = {
|
||||
pluginAndroidId: {
|
||||
path: '/android',
|
||||
versions: [],
|
||||
},
|
||||
pluginIosId: {
|
||||
path: '/',
|
||||
versions: [],
|
||||
},
|
||||
};
|
||||
expect(
|
||||
getActivePlugin(onePluginAtRootReversed, '/android/foo').pluginId,
|
||||
).toEqual('pluginAndroidId');
|
||||
});
|
||||
|
||||
test('getLatestVersion', () => {
|
||||
|
|
|
@ -27,14 +27,17 @@ export function getActivePlugin(
|
|||
pathname: string,
|
||||
options: GetActivePluginOptions = {},
|
||||
): ActivePlugin | undefined {
|
||||
const activeEntry = Object.entries(allPluginDatas).find(
|
||||
([_id, pluginData]) =>
|
||||
!!matchPath(pathname, {
|
||||
path: pluginData.path,
|
||||
exact: false,
|
||||
strict: false,
|
||||
}),
|
||||
);
|
||||
const activeEntry = Object.entries(allPluginDatas)
|
||||
// A quick route sorting: '/android/foo' should match '/android' instead of '/'
|
||||
.sort((a, b) => b[1].path.localeCompare(a[1].path))
|
||||
.find(
|
||||
([, pluginData]) =>
|
||||
!!matchPath(pathname, {
|
||||
path: pluginData.path,
|
||||
exact: false,
|
||||
strict: false,
|
||||
}),
|
||||
);
|
||||
|
||||
const activePlugin: ActivePlugin | undefined = activeEntry
|
||||
? {pluginId: activeEntry[0], pluginData: activeEntry[1]}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue