mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-16 16:25:56 +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
|
@ -32,7 +32,7 @@ import {LoadContext} from '@docusaurus/types';
|
|||
import {validateBlogPostFrontMatter} from './blogFrontMatter';
|
||||
|
||||
export function truncate(fileString: string, truncateMarker: RegExp): string {
|
||||
return fileString.split(truncateMarker, 1).shift()!;
|
||||
return fileString.split(truncateMarker, 1).shift() as string;
|
||||
}
|
||||
|
||||
export function getSourceToPermalink(
|
||||
|
|
|
@ -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] ?? {};
|
||||
|
||||
|
|
|
@ -21,10 +21,10 @@ const ThemedImage = (props: Props): JSX.Element => {
|
|||
|
||||
type SourceName = keyof Props['sources'];
|
||||
|
||||
const clientTheme: SourceName[] = isDarkTheme ? ['dark'] : ['light'];
|
||||
|
||||
const renderedSourceNames: SourceName[] = isClient
|
||||
? isDarkTheme
|
||||
? ['dark']
|
||||
: ['light']
|
||||
? clientTheme
|
||||
: // We need to render both images on the server to avoid flash
|
||||
// See https://github.com/facebook/docusaurus/pull/3730
|
||||
['light', 'dark'];
|
||||
|
|
|
@ -21,10 +21,10 @@ const ThemedImage = (props: Props): JSX.Element => {
|
|||
|
||||
type SourceName = keyof Props['sources'];
|
||||
|
||||
const clientTheme: SourceName[] = isDarkTheme ? ['dark'] : ['light'];
|
||||
|
||||
const renderedSourceNames: SourceName[] = isClient
|
||||
? isDarkTheme
|
||||
? ['dark']
|
||||
: ['light']
|
||||
? clientTheme
|
||||
: // We need to render both images on the server to avoid flash
|
||||
// See https://github.com/facebook/docusaurus/pull/3730
|
||||
['light', 'dark'];
|
||||
|
|
|
@ -35,7 +35,7 @@ function getNavbarTranslationFile(navbar: Navbar): TranslationFileContent {
|
|||
)
|
||||
.keyBy((navbarItem) => `item.label.${navbarItem.label}`)
|
||||
.mapValues((navbarItem) => ({
|
||||
message: navbarItem.label!,
|
||||
message: navbarItem.label as string,
|
||||
description: `Navbar item with label ${navbarItem.label}`,
|
||||
}))
|
||||
.value();
|
||||
|
@ -78,7 +78,7 @@ function getFooterTranslationFile(footer: Footer): TranslationFileContent {
|
|||
)
|
||||
.keyBy((link) => `link.title.${link.title}`)
|
||||
.mapValues((link) => ({
|
||||
message: link.title!,
|
||||
message: link.title as string,
|
||||
description: `The title of the footer links column with title=${link.title} in the footer`,
|
||||
}))
|
||||
.value();
|
||||
|
@ -90,7 +90,7 @@ function getFooterTranslationFile(footer: Footer): TranslationFileContent {
|
|||
)
|
||||
.keyBy((linkItem) => `link.item.label.${linkItem.label}`)
|
||||
.mapValues((linkItem) => ({
|
||||
message: linkItem.label!,
|
||||
message: linkItem.label as string,
|
||||
description: `The label of footer link with label=${
|
||||
linkItem.label
|
||||
} linking to ${linkItem.to ?? linkItem.href}`,
|
||||
|
|
|
@ -10,6 +10,8 @@ const path = require('path');
|
|||
const fs = require('fs-extra');
|
||||
const globby = require('globby');
|
||||
const {mapValues, pickBy, difference, orderBy} = require('lodash');
|
||||
// Unsafe import, should we create a package for the translationsExtractor ?
|
||||
const translationsExtractor = require('@docusaurus/core/lib/server/translations/translationsExtractor');
|
||||
|
||||
const CodeDirPaths = [
|
||||
path.join(__dirname, 'lib-next'),
|
||||
|
@ -49,11 +51,10 @@ function logKeys(keys) {
|
|||
}
|
||||
|
||||
async function extractThemeCodeMessages() {
|
||||
// Unsafe import, should we create a package for the translationsExtractor ?
|
||||
const {
|
||||
globSourceCodeFilePaths,
|
||||
extractAllSourceCodeFileTranslations,
|
||||
} = require('@docusaurus/core/lib/server/translations/translationsExtractor');
|
||||
} = translationsExtractor;
|
||||
|
||||
const filePaths = (
|
||||
await globSourceCodeFilePaths(CodeDirPaths)
|
||||
|
|
|
@ -11,7 +11,15 @@ import {useLocation} from '@docusaurus/router';
|
|||
// Permits to obtain the url of the current page in another locale
|
||||
// Useful to generate hreflang meta headers etc...
|
||||
// See https://developers.google.com/search/docs/advanced/crawling/localized-versions
|
||||
export function useAlternatePageUtils() {
|
||||
export function useAlternatePageUtils(): {
|
||||
createUrl: ({
|
||||
locale,
|
||||
fullyQualified,
|
||||
}: {
|
||||
locale: string;
|
||||
fullyQualified: boolean;
|
||||
}) => string;
|
||||
} {
|
||||
const {
|
||||
siteConfig: {baseUrl, url},
|
||||
i18n: {defaultLocale, currentLocale},
|
||||
|
|
|
@ -21,6 +21,9 @@ export default function applyTrailingSlash(
|
|||
function removeTrailingSlash(str: string): string {
|
||||
return str.endsWith('/') ? str.slice(0, -1) : str;
|
||||
}
|
||||
function handleTrailingSlash(str: string, trailing: boolean): string {
|
||||
return trailing ? addTrailingSlash(str) : removeTrailingSlash(str);
|
||||
}
|
||||
|
||||
// undefined = legacy retrocompatible behavior
|
||||
if (typeof trailingSlash === 'undefined') {
|
||||
|
@ -32,10 +35,6 @@ export default function applyTrailingSlash(
|
|||
|
||||
// Never transform '/' to ''
|
||||
const newPathname =
|
||||
pathname === '/'
|
||||
? '/'
|
||||
: trailingSlash
|
||||
? addTrailingSlash(pathname)
|
||||
: removeTrailingSlash(pathname);
|
||||
pathname === '/' ? '/' : handleTrailingSlash(pathname, trailingSlash);
|
||||
return path.replace(pathname, newPathname);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ export function buildUrl(
|
|||
organizationName: string,
|
||||
projectName: string,
|
||||
useSSH: boolean | undefined,
|
||||
) {
|
||||
): string {
|
||||
return useSSH
|
||||
? buildSshUrl(githubHost, organizationName, projectName, githubPort)
|
||||
: buildHttpsUrl(
|
||||
|
|
|
@ -52,7 +52,7 @@ export async function loadSiteConfig({
|
|||
}: {
|
||||
siteDir: string;
|
||||
customConfigFilePath?: string;
|
||||
}) {
|
||||
}): Promise<{siteConfig: DocusaurusConfig; siteConfigPath: string}> {
|
||||
const siteConfigPathUnresolved =
|
||||
customConfigFilePath ?? DEFAULT_CONFIG_FILE_NAME;
|
||||
|
||||
|
@ -309,7 +309,7 @@ ${Object.keys(registry)
|
|||
const siteMetadata: DocusaurusSiteMetadata = {
|
||||
docusaurusVersion: getPackageJsonVersion(
|
||||
join(__dirname, '../../package.json'),
|
||||
)!,
|
||||
) as string,
|
||||
siteVersion: getPackageJsonVersion(join(siteDir, 'package.json')),
|
||||
pluginVersions: {},
|
||||
};
|
||||
|
|
|
@ -11,7 +11,7 @@ import {applyTrailingSlash} from '@docusaurus/utils-common';
|
|||
export default function applyRouteTrailingSlash(
|
||||
route: RouteConfig,
|
||||
trailingSlash: boolean | undefined,
|
||||
) {
|
||||
): RouteConfig {
|
||||
return {
|
||||
...route,
|
||||
path: applyTrailingSlash(route.path, trailingSlash),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue