mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-04 01:09:20 +02:00
fix: baseUrl passed to sortConfig (#5824)
This commit is contained in:
parent
b5b2c18118
commit
8eaf02fe15
3 changed files with 90 additions and 4 deletions
|
@ -82,3 +82,48 @@ Array [
|
|||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`sortConfig should sort route config given a baseURL 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"component": "",
|
||||
"path": "/latest/community",
|
||||
},
|
||||
Object {
|
||||
"component": "",
|
||||
"path": "/latest/example",
|
||||
},
|
||||
Object {
|
||||
"component": "",
|
||||
"path": "/latest/some-page",
|
||||
},
|
||||
Object {
|
||||
"component": "",
|
||||
"path": "/latest/docs",
|
||||
"routes": Array [
|
||||
Object {
|
||||
"component": "",
|
||||
"path": "/latest/docs/someDoc",
|
||||
},
|
||||
Object {
|
||||
"component": "",
|
||||
"path": "/latest/docs/someOtherDoc",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"component": "",
|
||||
"path": "/latest",
|
||||
"routes": Array [
|
||||
Object {
|
||||
"component": "",
|
||||
"path": "/latest/someDoc",
|
||||
},
|
||||
Object {
|
||||
"component": "",
|
||||
"path": "/latest/someOtherDoc",
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
|
|
@ -87,4 +87,42 @@ describe('sortConfig', () => {
|
|||
|
||||
expect(routes).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should sort route config given a baseURL', () => {
|
||||
const baseURL = '/latest';
|
||||
const routes: RouteConfig[] = [
|
||||
{
|
||||
path: baseURL,
|
||||
component: '',
|
||||
routes: [
|
||||
{path: `${baseURL}/someDoc`, component: ''},
|
||||
{path: `${baseURL}/someOtherDoc`, component: ''},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: `${baseURL}/example`,
|
||||
component: '',
|
||||
},
|
||||
{
|
||||
path: `${baseURL}/docs`,
|
||||
component: '',
|
||||
routes: [
|
||||
{path: `${baseURL}/docs/someDoc`, component: ''},
|
||||
{path: `${baseURL}/docs/someOtherDoc`, component: ''},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: `${baseURL}/community`,
|
||||
component: '',
|
||||
},
|
||||
{
|
||||
path: `${baseURL}/some-page`,
|
||||
component: '',
|
||||
},
|
||||
];
|
||||
|
||||
sortConfig(routes, baseURL);
|
||||
|
||||
expect(routes).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -26,15 +26,18 @@ import {chain} from 'lodash';
|
|||
import {localizePluginTranslationFile} from '../translations/translations';
|
||||
import applyRouteTrailingSlash from './applyRouteTrailingSlash';
|
||||
|
||||
export function sortConfig(routeConfigs: RouteConfig[]): void {
|
||||
export function sortConfig(
|
||||
routeConfigs: RouteConfig[],
|
||||
baseUrl: string = '/',
|
||||
): void {
|
||||
// Sort the route config. This ensures that route with nested
|
||||
// routes is always placed last.
|
||||
routeConfigs.sort((a, b) => {
|
||||
// Root route should get placed last.
|
||||
if (a.path === '/' && b.path !== '/') {
|
||||
if (a.path === baseUrl && b.path !== baseUrl) {
|
||||
return 1;
|
||||
}
|
||||
if (a.path !== '/' && b.path === '/') {
|
||||
if (a.path !== baseUrl && b.path === baseUrl) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -221,7 +224,7 @@ export async function loadPlugins({
|
|||
|
||||
// Sort the route config. This ensures that route with nested
|
||||
// routes are always placed last.
|
||||
sortConfig(pluginsRouteConfigs);
|
||||
sortConfig(pluginsRouteConfigs, context.siteConfig.baseUrl);
|
||||
|
||||
// Apply each plugin one after the other to translate the theme config
|
||||
function translateThemeConfig(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue