mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-19 17:49:19 +02:00
Disable localization in all content plugins
This commit is contained in:
parent
0924b8baa6
commit
ae4637bec5
8 changed files with 77 additions and 64 deletions
|
@ -73,13 +73,16 @@ export default async function pluginContentBlog(
|
||||||
|
|
||||||
const {baseUrl} = siteConfig;
|
const {baseUrl} = siteConfig;
|
||||||
|
|
||||||
|
const shouldLocalize = false;
|
||||||
const contentPaths: BlogContentPaths = {
|
const contentPaths: BlogContentPaths = {
|
||||||
contentPath: path.resolve(siteDir, options.path),
|
contentPath: path.resolve(siteDir, options.path),
|
||||||
contentPathLocalized: getPluginI18nPath({
|
contentPathLocalized: shouldLocalize
|
||||||
|
? getPluginI18nPath({
|
||||||
localizationDir,
|
localizationDir,
|
||||||
pluginName: PluginName,
|
pluginName: PluginName,
|
||||||
pluginId: options.id,
|
pluginId: options.id,
|
||||||
}),
|
})
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
const pluginId = options.id ?? DEFAULT_PLUGIN_ID;
|
const pluginId = options.id ?? DEFAULT_PLUGIN_ID;
|
||||||
|
|
||||||
|
|
|
@ -186,11 +186,16 @@ export async function getVersionMetadataPaths({
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
const isCurrent = versionName === CURRENT_VERSION_NAME;
|
const isCurrent = versionName === CURRENT_VERSION_NAME;
|
||||||
const contentPathLocalized = getDocsDirPathLocalized({
|
|
||||||
|
const shouldTranslate = false; // TODO wire this properly
|
||||||
|
const contentPathLocalized = shouldTranslate
|
||||||
|
? getDocsDirPathLocalized({
|
||||||
localizationDir: context.localizationDir,
|
localizationDir: context.localizationDir,
|
||||||
pluginId: options.id,
|
pluginId: options.id,
|
||||||
versionName,
|
versionName,
|
||||||
});
|
})
|
||||||
|
: undefined;
|
||||||
|
|
||||||
const contentPath = isCurrent
|
const contentPath = isCurrent
|
||||||
? path.resolve(context.siteDir, options.path)
|
? path.resolve(context.siteDir, options.path)
|
||||||
: getVersionDocsDirPath(context.siteDir, options.id, versionName);
|
: getVersionDocsDirPath(context.siteDir, options.id, versionName);
|
||||||
|
|
|
@ -50,7 +50,27 @@ function getVersionEditUrls({
|
||||||
return {editUrl: undefined, editUrlLocalized: undefined};
|
return {editUrl: undefined, editUrlLocalized: undefined};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Intermediate var just to please TS not narrowing to "string"
|
||||||
|
const editUrlOption = options.editUrl;
|
||||||
|
|
||||||
|
const getEditUrl = () => {
|
||||||
const editDirPath = options.editCurrentVersion ? options.path : contentPath;
|
const editDirPath = options.editCurrentVersion ? options.path : contentPath;
|
||||||
|
|
||||||
|
return normalizeUrl([
|
||||||
|
editUrlOption,
|
||||||
|
posixPath(
|
||||||
|
path.relative(
|
||||||
|
context.siteDir,
|
||||||
|
path.resolve(context.siteDir, editDirPath),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getEditUrlLocalized = () => {
|
||||||
|
if (!contentPathLocalized) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
const editDirPathLocalized = options.editCurrentVersion
|
const editDirPathLocalized = options.editCurrentVersion
|
||||||
? getDocsDirPathLocalized({
|
? getDocsDirPathLocalized({
|
||||||
localizationDir: context.localizationDir,
|
localizationDir: context.localizationDir,
|
||||||
|
@ -59,24 +79,18 @@ function getVersionEditUrls({
|
||||||
})
|
})
|
||||||
: contentPathLocalized;
|
: contentPathLocalized;
|
||||||
|
|
||||||
const versionPathSegment = posixPath(
|
return normalizeUrl([
|
||||||
path.relative(context.siteDir, path.resolve(context.siteDir, editDirPath)),
|
editUrlOption,
|
||||||
);
|
posixPath(
|
||||||
const versionPathSegmentLocalized = posixPath(
|
|
||||||
path.relative(
|
path.relative(
|
||||||
context.siteDir,
|
context.siteDir,
|
||||||
path.resolve(context.siteDir, editDirPathLocalized),
|
path.resolve(context.siteDir, editDirPathLocalized),
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
|
||||||
const editUrl = normalizeUrl([options.editUrl, versionPathSegment]);
|
|
||||||
|
|
||||||
const editUrlLocalized = normalizeUrl([
|
|
||||||
options.editUrl,
|
|
||||||
versionPathSegmentLocalized,
|
|
||||||
]);
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
return {editUrl, editUrlLocalized};
|
return {editUrl: getEditUrl(), editUrlLocalized: getEditUrlLocalized()};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,10 +21,11 @@ import {
|
||||||
getEditUrl,
|
getEditUrl,
|
||||||
posixPath,
|
posixPath,
|
||||||
getPluginI18nPath,
|
getPluginI18nPath,
|
||||||
|
getContentPathList,
|
||||||
|
type ContentPaths,
|
||||||
} from '@docusaurus/utils';
|
} from '@docusaurus/utils';
|
||||||
import {validatePageFrontMatter} from './frontMatter';
|
import {validatePageFrontMatter} from './frontMatter';
|
||||||
import type {LoadContext} from '@docusaurus/types';
|
import type {LoadContext} from '@docusaurus/types';
|
||||||
import type {PagesContentPaths} from './types';
|
|
||||||
import type {
|
import type {
|
||||||
PluginOptions,
|
PluginOptions,
|
||||||
Metadata,
|
Metadata,
|
||||||
|
@ -37,29 +38,29 @@ export function createPagesContentPaths({
|
||||||
}: {
|
}: {
|
||||||
context: LoadContext;
|
context: LoadContext;
|
||||||
options: PluginOptions;
|
options: PluginOptions;
|
||||||
}): PagesContentPaths {
|
}): ContentPaths {
|
||||||
const {siteDir, localizationDir} = context;
|
const {siteDir, localizationDir} = context;
|
||||||
|
|
||||||
|
const shouldLocalize = false;
|
||||||
return {
|
return {
|
||||||
contentPath: path.resolve(siteDir, options.path),
|
contentPath: path.resolve(siteDir, options.path),
|
||||||
contentPathLocalized: getPluginI18nPath({
|
contentPathLocalized: shouldLocalize
|
||||||
|
? getPluginI18nPath({
|
||||||
localizationDir,
|
localizationDir,
|
||||||
pluginName: 'docusaurus-plugin-content-pages',
|
pluginName: 'docusaurus-plugin-content-pages',
|
||||||
pluginId: options.id,
|
pluginId: options.id,
|
||||||
}),
|
})
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getContentPathList(contentPaths: PagesContentPaths): string[] {
|
|
||||||
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
|
|
||||||
}
|
|
||||||
|
|
||||||
const isMarkdownSource = (source: string) =>
|
const isMarkdownSource = (source: string) =>
|
||||||
source.endsWith('.md') || source.endsWith('.mdx');
|
source.endsWith('.md') || source.endsWith('.mdx');
|
||||||
|
|
||||||
type LoadContentParams = {
|
type LoadContentParams = {
|
||||||
context: LoadContext;
|
context: LoadContext;
|
||||||
options: PluginOptions;
|
options: PluginOptions;
|
||||||
contentPaths: PagesContentPaths;
|
contentPaths: ContentPaths;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function loadPagesContent(
|
export async function loadPagesContent(
|
||||||
|
@ -158,7 +159,9 @@ async function processPageSourceFile(
|
||||||
} else if (typeof editUrl === 'string') {
|
} else if (typeof editUrl === 'string') {
|
||||||
const isLocalized = pagesDirPath === contentPaths.contentPathLocalized;
|
const isLocalized = pagesDirPath === contentPaths.contentPathLocalized;
|
||||||
const fileContentPath =
|
const fileContentPath =
|
||||||
isLocalized && options.editLocalizedFiles
|
isLocalized &&
|
||||||
|
options.editLocalizedFiles &&
|
||||||
|
contentPaths.contentPathLocalized
|
||||||
? contentPaths.contentPathLocalized
|
? contentPaths.contentPathLocalized
|
||||||
: contentPaths.contentPath;
|
: contentPaths.contentPath;
|
||||||
|
|
||||||
|
|
|
@ -12,15 +12,12 @@ import {
|
||||||
docuHash,
|
docuHash,
|
||||||
addTrailingPathSeparator,
|
addTrailingPathSeparator,
|
||||||
createAbsoluteFilePathMatcher,
|
createAbsoluteFilePathMatcher,
|
||||||
|
getContentPathList,
|
||||||
DEFAULT_PLUGIN_ID,
|
DEFAULT_PLUGIN_ID,
|
||||||
} from '@docusaurus/utils';
|
} from '@docusaurus/utils';
|
||||||
import {createMDXLoaderRule} from '@docusaurus/mdx-loader';
|
import {createMDXLoaderRule} from '@docusaurus/mdx-loader';
|
||||||
import {createAllRoutes} from './routes';
|
import {createAllRoutes} from './routes';
|
||||||
import {
|
import {createPagesContentPaths, loadPagesContent} from './content';
|
||||||
createPagesContentPaths,
|
|
||||||
getContentPathList,
|
|
||||||
loadPagesContent,
|
|
||||||
} from './content';
|
|
||||||
import type {LoadContext, Plugin} from '@docusaurus/types';
|
import type {LoadContext, Plugin} from '@docusaurus/types';
|
||||||
import type {
|
import type {
|
||||||
PluginOptions,
|
PluginOptions,
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export type PagesContentPaths = {
|
|
||||||
contentPath: string;
|
|
||||||
contentPathLocalized: string;
|
|
||||||
};
|
|
|
@ -74,7 +74,9 @@ export async function readDataFile(params: DataFileParams): Promise<unknown> {
|
||||||
* in priority.
|
* in priority.
|
||||||
*/
|
*/
|
||||||
export function getContentPathList(contentPaths: ContentPaths): string[] {
|
export function getContentPathList(contentPaths: ContentPaths): string[] {
|
||||||
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
|
return [contentPaths.contentPathLocalized, contentPaths.contentPath].filter(
|
||||||
|
(p) => p !== undefined,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,7 +22,7 @@ export type ContentPaths = {
|
||||||
* The absolute path to the localized content directory, like
|
* The absolute path to the localized content directory, like
|
||||||
* `"<siteDir>/i18n/zh-Hans/plugin-content-docs"`.
|
* `"<siteDir>/i18n/zh-Hans/plugin-content-docs"`.
|
||||||
*/
|
*/
|
||||||
contentPathLocalized: string;
|
contentPathLocalized?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Data structure representing each broken Markdown link to be reported. */
|
/** Data structure representing each broken Markdown link to be reported. */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue