mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-14 01:27:35 +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 {
|
import {
|
||||||
type ActivePlugin,
|
|
||||||
getActivePlugin,
|
getActivePlugin,
|
||||||
getLatestVersion,
|
getLatestVersion,
|
||||||
getActiveDocContext,
|
getActiveDocContext,
|
||||||
getActiveVersion,
|
getActiveVersion,
|
||||||
getDocVersionSuggestions,
|
getDocVersionSuggestions,
|
||||||
} from '../docsClientUtils';
|
} from '../docsClientUtils';
|
||||||
import type {GlobalPluginData, GlobalVersion} from '../../types';
|
import type {
|
||||||
|
GlobalPluginData,
|
||||||
|
GlobalVersion,
|
||||||
|
ActivePlugin,
|
||||||
|
} from '@docusaurus/plugin-content-docs/client';
|
||||||
import {shuffle} from 'lodash';
|
import {shuffle} from 'lodash';
|
||||||
|
|
||||||
describe('docsClientUtils', () => {
|
describe('docsClientUtils', () => {
|
||||||
|
@ -58,6 +61,34 @@ describe('docsClientUtils', () => {
|
||||||
expect(getActivePlugin(data, '/android')).toEqual(activePluginAndroid);
|
expect(getActivePlugin(data, '/android')).toEqual(activePluginAndroid);
|
||||||
expect(getActivePlugin(data, '/android/')).toEqual(activePluginAndroid);
|
expect(getActivePlugin(data, '/android/')).toEqual(activePluginAndroid);
|
||||||
expect(getActivePlugin(data, '/android/ijk')).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', () => {
|
test('getLatestVersion', () => {
|
||||||
|
|
|
@ -27,14 +27,17 @@ export function getActivePlugin(
|
||||||
pathname: string,
|
pathname: string,
|
||||||
options: GetActivePluginOptions = {},
|
options: GetActivePluginOptions = {},
|
||||||
): ActivePlugin | undefined {
|
): ActivePlugin | undefined {
|
||||||
const activeEntry = Object.entries(allPluginDatas).find(
|
const activeEntry = Object.entries(allPluginDatas)
|
||||||
([_id, pluginData]) =>
|
// A quick route sorting: '/android/foo' should match '/android' instead of '/'
|
||||||
!!matchPath(pathname, {
|
.sort((a, b) => b[1].path.localeCompare(a[1].path))
|
||||||
path: pluginData.path,
|
.find(
|
||||||
exact: false,
|
([, pluginData]) =>
|
||||||
strict: false,
|
!!matchPath(pathname, {
|
||||||
}),
|
path: pluginData.path,
|
||||||
);
|
exact: false,
|
||||||
|
strict: false,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const activePlugin: ActivePlugin | undefined = activeEntry
|
const activePlugin: ActivePlugin | undefined = activeEntry
|
||||||
? {pluginId: activeEntry[0], pluginData: activeEntry[1]}
|
? {pluginId: activeEntry[0], pluginData: activeEntry[1]}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue