Disable localization in all content plugins

This commit is contained in:
sebastien 2025-07-03 17:08:10 +02:00
parent 0924b8baa6
commit ae4637bec5
8 changed files with 77 additions and 64 deletions

View file

@ -73,13 +73,16 @@ export default async function pluginContentBlog(
const {baseUrl} = siteConfig;
const shouldLocalize = false;
const contentPaths: BlogContentPaths = {
contentPath: path.resolve(siteDir, options.path),
contentPathLocalized: getPluginI18nPath({
localizationDir,
pluginName: PluginName,
pluginId: options.id,
}),
contentPathLocalized: shouldLocalize
? getPluginI18nPath({
localizationDir,
pluginName: PluginName,
pluginId: options.id,
})
: undefined,
};
const pluginId = options.id ?? DEFAULT_PLUGIN_ID;

View file

@ -186,11 +186,16 @@ export async function getVersionMetadataPaths({
>
> {
const isCurrent = versionName === CURRENT_VERSION_NAME;
const contentPathLocalized = getDocsDirPathLocalized({
localizationDir: context.localizationDir,
pluginId: options.id,
versionName,
});
const shouldTranslate = false; // TODO wire this properly
const contentPathLocalized = shouldTranslate
? getDocsDirPathLocalized({
localizationDir: context.localizationDir,
pluginId: options.id,
versionName,
})
: undefined;
const contentPath = isCurrent
? path.resolve(context.siteDir, options.path)
: getVersionDocsDirPath(context.siteDir, options.id, versionName);

View file

@ -50,33 +50,47 @@ function getVersionEditUrls({
return {editUrl: undefined, editUrlLocalized: undefined};
}
const editDirPath = options.editCurrentVersion ? options.path : contentPath;
const editDirPathLocalized = options.editCurrentVersion
? getDocsDirPathLocalized({
localizationDir: context.localizationDir,
versionName: CURRENT_VERSION_NAME,
pluginId: options.id,
})
: contentPathLocalized;
// Intermediate var just to please TS not narrowing to "string"
const editUrlOption = options.editUrl;
const versionPathSegment = posixPath(
path.relative(context.siteDir, path.resolve(context.siteDir, editDirPath)),
);
const versionPathSegmentLocalized = posixPath(
path.relative(
context.siteDir,
path.resolve(context.siteDir, editDirPathLocalized),
),
);
const getEditUrl = () => {
const editDirPath = options.editCurrentVersion ? options.path : contentPath;
const editUrl = normalizeUrl([options.editUrl, versionPathSegment]);
return normalizeUrl([
editUrlOption,
posixPath(
path.relative(
context.siteDir,
path.resolve(context.siteDir, editDirPath),
),
),
]);
};
const editUrlLocalized = normalizeUrl([
options.editUrl,
versionPathSegmentLocalized,
]);
const getEditUrlLocalized = () => {
if (!contentPathLocalized) {
return undefined;
}
const editDirPathLocalized = options.editCurrentVersion
? getDocsDirPathLocalized({
localizationDir: context.localizationDir,
versionName: CURRENT_VERSION_NAME,
pluginId: options.id,
})
: contentPathLocalized;
return {editUrl, editUrlLocalized};
return normalizeUrl([
editUrlOption,
posixPath(
path.relative(
context.siteDir,
path.resolve(context.siteDir, editDirPathLocalized),
),
),
]);
};
return {editUrl: getEditUrl(), editUrlLocalized: getEditUrlLocalized()};
}
/**

View file

@ -21,10 +21,11 @@ import {
getEditUrl,
posixPath,
getPluginI18nPath,
getContentPathList,
type ContentPaths,
} from '@docusaurus/utils';
import {validatePageFrontMatter} from './frontMatter';
import type {LoadContext} from '@docusaurus/types';
import type {PagesContentPaths} from './types';
import type {
PluginOptions,
Metadata,
@ -37,29 +38,29 @@ export function createPagesContentPaths({
}: {
context: LoadContext;
options: PluginOptions;
}): PagesContentPaths {
}): ContentPaths {
const {siteDir, localizationDir} = context;
const shouldLocalize = false;
return {
contentPath: path.resolve(siteDir, options.path),
contentPathLocalized: getPluginI18nPath({
localizationDir,
pluginName: 'docusaurus-plugin-content-pages',
pluginId: options.id,
}),
contentPathLocalized: shouldLocalize
? getPluginI18nPath({
localizationDir,
pluginName: 'docusaurus-plugin-content-pages',
pluginId: options.id,
})
: undefined,
};
}
export function getContentPathList(contentPaths: PagesContentPaths): string[] {
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
}
const isMarkdownSource = (source: string) =>
source.endsWith('.md') || source.endsWith('.mdx');
type LoadContentParams = {
context: LoadContext;
options: PluginOptions;
contentPaths: PagesContentPaths;
contentPaths: ContentPaths;
};
export async function loadPagesContent(
@ -158,7 +159,9 @@ async function processPageSourceFile(
} else if (typeof editUrl === 'string') {
const isLocalized = pagesDirPath === contentPaths.contentPathLocalized;
const fileContentPath =
isLocalized && options.editLocalizedFiles
isLocalized &&
options.editLocalizedFiles &&
contentPaths.contentPathLocalized
? contentPaths.contentPathLocalized
: contentPaths.contentPath;

View file

@ -12,15 +12,12 @@ import {
docuHash,
addTrailingPathSeparator,
createAbsoluteFilePathMatcher,
getContentPathList,
DEFAULT_PLUGIN_ID,
} from '@docusaurus/utils';
import {createMDXLoaderRule} from '@docusaurus/mdx-loader';
import {createAllRoutes} from './routes';
import {
createPagesContentPaths,
getContentPathList,
loadPagesContent,
} from './content';
import {createPagesContentPaths, loadPagesContent} from './content';
import type {LoadContext, Plugin} from '@docusaurus/types';
import type {
PluginOptions,

View file

@ -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;
};

View file

@ -74,7 +74,9 @@ export async function readDataFile(params: DataFileParams): Promise<unknown> {
* in priority.
*/
export function getContentPathList(contentPaths: ContentPaths): string[] {
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
return [contentPaths.contentPathLocalized, contentPaths.contentPath].filter(
(p) => p !== undefined,
);
}
/**

View file

@ -22,7 +22,7 @@ export type ContentPaths = {
* The absolute path to the localized content directory, like
* `"<siteDir>/i18n/zh-Hans/plugin-content-docs"`.
*/
contentPathLocalized: string;
contentPathLocalized?: string;
};
/** Data structure representing each broken Markdown link to be reported. */