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 {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
localizationDir, ? getPluginI18nPath({
pluginName: PluginName, localizationDir,
pluginId: options.id, pluginName: PluginName,
}), pluginId: options.id,
})
: undefined,
}; };
const pluginId = options.id ?? DEFAULT_PLUGIN_ID; const pluginId = options.id ?? DEFAULT_PLUGIN_ID;

View file

@ -186,11 +186,16 @@ export async function getVersionMetadataPaths({
> >
> { > {
const isCurrent = versionName === CURRENT_VERSION_NAME; const isCurrent = versionName === CURRENT_VERSION_NAME;
const contentPathLocalized = getDocsDirPathLocalized({
localizationDir: context.localizationDir, const shouldTranslate = false; // TODO wire this properly
pluginId: options.id, const contentPathLocalized = shouldTranslate
versionName, ? getDocsDirPathLocalized({
}); localizationDir: context.localizationDir,
pluginId: options.id,
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);

View file

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

View file

@ -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,

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. * 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,
);
} }
/** /**

View file

@ -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. */