mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-20 10:08:17 +02:00
More fixes
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
This commit is contained in:
parent
6d3d416f58
commit
c7c833fe77
16 changed files with 59 additions and 32 deletions
|
@ -75,7 +75,7 @@ export type ActiveDocContext = {
|
|||
};
|
||||
|
||||
export const getLatestVersion = (data: GlobalPluginData): Version => {
|
||||
return data.versions.find((version) => version.isLast)!;
|
||||
return data.versions.find((version) => version.isLast) as GlobalVersion;
|
||||
};
|
||||
|
||||
// Note: return undefined on doc-unrelated pages,
|
||||
|
|
|
@ -130,6 +130,7 @@ function doProcessDocMetadata({
|
|||
|
||||
// Strip number prefixes by default (01-MyFolder/01-MyDoc.md => MyFolder/MyDoc) by default,
|
||||
// but allow to disable this behavior with frontmatterr
|
||||
// eslint-disable-next-line camelcase
|
||||
parse_number_prefixes = true,
|
||||
} = frontMatter;
|
||||
|
||||
|
@ -144,6 +145,7 @@ function doProcessDocMetadata({
|
|||
// ex: myDoc -> .
|
||||
const sourceDirName = path.dirname(source);
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
const {filename: unprefixedFileName, numberPrefix} = parse_number_prefixes
|
||||
? options.numberPrefixParser(sourceFileNameWithoutExtension)
|
||||
: {filename: sourceFileNameWithoutExtension, numberPrefix: undefined};
|
||||
|
@ -172,6 +174,7 @@ function doProcessDocMetadata({
|
|||
return undefined;
|
||||
}
|
||||
// Eventually remove the number prefixes from intermediate directories
|
||||
// eslint-disable-next-line camelcase
|
||||
return parse_number_prefixes
|
||||
? stripPathNumberPrefixes(sourceDirName, options.numberPrefixParser)
|
||||
: sourceDirName;
|
||||
|
|
|
@ -253,7 +253,9 @@ export default function pluginContentDocs(
|
|||
if (versionHomeDoc) {
|
||||
return versionHomeDoc;
|
||||
} else if (firstDocIdOfFirstSidebar) {
|
||||
return docs.find((doc) => doc.id === firstDocIdOfFirstSidebar)!;
|
||||
return docs.find(
|
||||
(doc) => doc.id === firstDocIdOfFirstSidebar,
|
||||
) as DocMetadata;
|
||||
} else {
|
||||
return docs[0];
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ function parseBreadcrumb(
|
|||
): {parents: string[]; tail: string} {
|
||||
return {
|
||||
parents: take(breadcrumb, breadcrumb.length - 1),
|
||||
tail: last(breadcrumb)!,
|
||||
tail: last(breadcrumb) as string,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,10 @@ function assertIsCategory(
|
|||
);
|
||||
}
|
||||
// "collapsed" is an optional property
|
||||
if (item.hasOwnProperty('collapsed') && typeof item.collapsed !== 'boolean') {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(item, 'collapsed') &&
|
||||
typeof item.collapsed !== 'boolean'
|
||||
) {
|
||||
throw new Error(
|
||||
`Error loading ${JSON.stringify(item)}: "collapsed" must be a boolean.`,
|
||||
);
|
||||
|
@ -438,7 +441,20 @@ export function collectSidebarsDocIds(
|
|||
});
|
||||
}
|
||||
|
||||
export function createSidebarsUtils(sidebars: Sidebars) {
|
||||
export function createSidebarsUtils(
|
||||
sidebars: Sidebars,
|
||||
): {
|
||||
getFirstDocIdOfFirstSidebar: () => string | undefined;
|
||||
getSidebarNameByDocId: (docId: string) => string | undefined;
|
||||
getDocNavigation: (
|
||||
docId: string,
|
||||
) => {
|
||||
sidebarName: string | undefined;
|
||||
previousId: string | undefined;
|
||||
nextId: string | undefined;
|
||||
};
|
||||
checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
|
||||
} {
|
||||
const sidebarNameToDocIds = collectSidebarsDocIds(sidebars);
|
||||
|
||||
function getFirstDocIdOfFirstSidebar(): string | undefined {
|
||||
|
|
|
@ -288,11 +288,9 @@ function createVersionMetadata({
|
|||
// retro-compatible values
|
||||
const defaultVersionLabel =
|
||||
versionName === CURRENT_VERSION_NAME ? 'Next' : versionName;
|
||||
const defaultVersionPathPart = isLast
|
||||
? ''
|
||||
: versionName === CURRENT_VERSION_NAME
|
||||
? 'next'
|
||||
: versionName;
|
||||
const versionNameNotLast =
|
||||
versionName === CURRENT_VERSION_NAME ? 'next' : versionName;
|
||||
const defaultVersionPathPart = isLast ? '' : versionNameNotLast;
|
||||
|
||||
const versionOptions: VersionOptions = options.versions[versionName] ?? {};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue