mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 16:47:26 +02:00
refactor(v2): include path in error about non-existent ids (#4969)
This commit is contained in:
parent
737f80a026
commit
e25c0e7d3f
3 changed files with 8 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`sidebar site with wrong sidebar content 1`] = `
|
exports[`sidebar site with wrong sidebar content 1`] = `
|
||||||
"Bad sidebars file.
|
"Bad sidebar file at 'packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json'.
|
||||||
These sidebar document ids do not exist:
|
These sidebar document ids do not exist:
|
||||||
- goku,
|
- goku,
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,10 @@ export default function pluginContentDocs(
|
||||||
const sidebarsUtils = createSidebarsUtils(sidebars);
|
const sidebarsUtils = createSidebarsUtils(sidebars);
|
||||||
|
|
||||||
const validDocIds = Object.keys(docsBaseById);
|
const validDocIds = Object.keys(docsBaseById);
|
||||||
sidebarsUtils.checkSidebarsDocIds(validDocIds);
|
sidebarsUtils.checkSidebarsDocIds(
|
||||||
|
validDocIds,
|
||||||
|
versionMetadata.sidebarFilePath as string,
|
||||||
|
);
|
||||||
|
|
||||||
// Add sidebar/next/previous to the docs
|
// Add sidebar/next/previous to the docs
|
||||||
function addNavData(doc: DocMetadataBase): DocMetadata {
|
function addNavData(doc: DocMetadataBase): DocMetadata {
|
||||||
|
|
|
@ -28,7 +28,7 @@ import {
|
||||||
PluginOptions,
|
PluginOptions,
|
||||||
} from './types';
|
} from './types';
|
||||||
import {mapValues, flatten, flatMap, difference, pick, memoize} from 'lodash';
|
import {mapValues, flatten, flatMap, difference, pick, memoize} from 'lodash';
|
||||||
import {getElementsAround} from '@docusaurus/utils';
|
import {getElementsAround, toMessageRelativeFilePath} from '@docusaurus/utils';
|
||||||
import combinePromises from 'combine-promises';
|
import combinePromises from 'combine-promises';
|
||||||
import {DefaultSidebarItemsGenerator} from './sidebarItemsGenerator';
|
import {DefaultSidebarItemsGenerator} from './sidebarItemsGenerator';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
@ -480,12 +480,12 @@ export function createSidebarsUtils(sidebars: Sidebars) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkSidebarsDocIds(validDocIds: string[]) {
|
function checkSidebarsDocIds(validDocIds: string[], sidebarFilePath: string) {
|
||||||
const allSidebarDocIds = flatten(Object.values(sidebarNameToDocIds));
|
const allSidebarDocIds = flatten(Object.values(sidebarNameToDocIds));
|
||||||
const invalidSidebarDocIds = difference(allSidebarDocIds, validDocIds);
|
const invalidSidebarDocIds = difference(allSidebarDocIds, validDocIds);
|
||||||
if (invalidSidebarDocIds.length > 0) {
|
if (invalidSidebarDocIds.length > 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Bad sidebars file.
|
`Bad sidebar file at '${toMessageRelativeFilePath(sidebarFilePath)}'.
|
||||||
These sidebar document ids do not exist:
|
These sidebar document ids do not exist:
|
||||||
- ${invalidSidebarDocIds.sort().join('\n- ')},
|
- ${invalidSidebarDocIds.sort().join('\n- ')},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue