@docusaurus/plugin-content-docs 3.8.1-canary-6361 → 3.8.1-canary-6364

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cli.js CHANGED
@@ -49,7 +49,7 @@ async function cliDocsVersionCommand(version, { id: pluginId, path: docsPath, si
49
49
  logger_1.default.info `Versioned docs will be created for the following locales: name=${i18n.locales}`;
50
50
  }
51
51
  await Promise.all(i18n.locales.map(async (locale) => {
52
- const localizationDir = path_1.default.resolve(siteDir, i18n.path, i18n.localeConfigs[locale].path);
52
+ const localizationDir = path_1.default.resolve(siteDir, i18n.path, (0, utils_1.getLocaleConfig)(i18n, locale).path);
53
53
  // Copy docs files.
54
54
  const docsDir = locale === i18n.defaultLocale
55
55
  ? path_1.default.resolve(siteDir, docsPath)
package/lib/docs.js CHANGED
@@ -103,7 +103,8 @@ async function doProcessDocMetadata({ docFile, versionMetadata, context, options
103
103
  });
104
104
  }
105
105
  else if (typeof options.editUrl === 'string') {
106
- const isLocalized = contentPath === versionMetadata.contentPathLocalized;
106
+ const isLocalized = typeof versionMetadata.contentPathLocalized !== 'undefined' &&
107
+ contentPath === versionMetadata.contentPathLocalized;
107
108
  const baseVersionEditUrl = isLocalized && options.editLocalizedFiles
108
109
  ? versionMetadata.editUrlLocalized
109
110
  : versionMetadata.editUrl;
@@ -117,11 +117,14 @@ async function readVersionNames(siteDir, options) {
117
117
  */
118
118
  async function getVersionMetadataPaths({ versionName, context, options, }) {
119
119
  const isCurrent = versionName === constants_1.CURRENT_VERSION_NAME;
120
- const contentPathLocalized = getDocsDirPathLocalized({
121
- localizationDir: context.localizationDir,
122
- pluginId: options.id,
123
- versionName,
124
- });
120
+ const shouldTranslate = (0, utils_1.getLocaleConfig)(context.i18n).translate;
121
+ const contentPathLocalized = shouldTranslate
122
+ ? getDocsDirPathLocalized({
123
+ localizationDir: context.localizationDir,
124
+ pluginId: options.id,
125
+ versionName,
126
+ })
127
+ : undefined;
125
128
  const contentPath = isCurrent
126
129
  ? path_1.default.resolve(context.siteDir, options.path)
127
130
  : getVersionDocsDirPath(context.siteDir, options.id, versionName);
@@ -28,22 +28,32 @@ function getVersionEditUrls({ contentPath, contentPathLocalized, context, option
28
28
  if (!options.editUrl || typeof options.editUrl === 'function') {
29
29
  return { editUrl: undefined, editUrlLocalized: undefined };
30
30
  }
31
- const editDirPath = options.editCurrentVersion ? options.path : contentPath;
32
- const editDirPathLocalized = options.editCurrentVersion
33
- ? (0, files_1.getDocsDirPathLocalized)({
34
- localizationDir: context.localizationDir,
35
- versionName: constants_1.CURRENT_VERSION_NAME,
36
- pluginId: options.id,
37
- })
38
- : contentPathLocalized;
39
- const versionPathSegment = (0, utils_1.posixPath)(path_1.default.relative(context.siteDir, path_1.default.resolve(context.siteDir, editDirPath)));
40
- const versionPathSegmentLocalized = (0, utils_1.posixPath)(path_1.default.relative(context.siteDir, path_1.default.resolve(context.siteDir, editDirPathLocalized)));
41
- const editUrl = (0, utils_1.normalizeUrl)([options.editUrl, versionPathSegment]);
42
- const editUrlLocalized = (0, utils_1.normalizeUrl)([
43
- options.editUrl,
44
- versionPathSegmentLocalized,
45
- ]);
46
- return { editUrl, editUrlLocalized };
31
+ // Intermediate var just to please TS not narrowing to "string"
32
+ const editUrlOption = options.editUrl;
33
+ const getEditUrl = () => {
34
+ const editDirPath = options.editCurrentVersion ? options.path : contentPath;
35
+ return (0, utils_1.normalizeUrl)([
36
+ editUrlOption,
37
+ (0, utils_1.posixPath)(path_1.default.relative(context.siteDir, path_1.default.resolve(context.siteDir, editDirPath))),
38
+ ]);
39
+ };
40
+ const getEditUrlLocalized = () => {
41
+ if (!contentPathLocalized) {
42
+ return undefined;
43
+ }
44
+ const editDirPathLocalized = options.editCurrentVersion
45
+ ? (0, files_1.getDocsDirPathLocalized)({
46
+ localizationDir: context.localizationDir,
47
+ versionName: constants_1.CURRENT_VERSION_NAME,
48
+ pluginId: options.id,
49
+ })
50
+ : contentPathLocalized;
51
+ return (0, utils_1.normalizeUrl)([
52
+ editUrlOption,
53
+ (0, utils_1.posixPath)(path_1.default.relative(context.siteDir, path_1.default.resolve(context.siteDir, editDirPathLocalized))),
54
+ ]);
55
+ };
56
+ return { editUrl: getEditUrl(), editUrlLocalized: getEditUrlLocalized() };
47
57
  }
48
58
  /**
49
59
  * The default version banner depends on the version's relative position to the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "3.8.1-canary-6361",
3
+ "version": "3.8.1-canary-6364",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
@@ -35,15 +35,15 @@
35
35
  },
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "@docusaurus/core": "3.8.1-canary-6361",
39
- "@docusaurus/logger": "3.8.1-canary-6361",
40
- "@docusaurus/mdx-loader": "3.8.1-canary-6361",
41
- "@docusaurus/module-type-aliases": "3.8.1-canary-6361",
42
- "@docusaurus/theme-common": "3.8.1-canary-6361",
43
- "@docusaurus/types": "3.8.1-canary-6361",
44
- "@docusaurus/utils": "3.8.1-canary-6361",
45
- "@docusaurus/utils-common": "3.8.1-canary-6361",
46
- "@docusaurus/utils-validation": "3.8.1-canary-6361",
38
+ "@docusaurus/core": "3.8.1-canary-6364",
39
+ "@docusaurus/logger": "3.8.1-canary-6364",
40
+ "@docusaurus/mdx-loader": "3.8.1-canary-6364",
41
+ "@docusaurus/module-type-aliases": "3.8.1-canary-6364",
42
+ "@docusaurus/theme-common": "3.8.1-canary-6364",
43
+ "@docusaurus/types": "3.8.1-canary-6364",
44
+ "@docusaurus/utils": "3.8.1-canary-6364",
45
+ "@docusaurus/utils-common": "3.8.1-canary-6364",
46
+ "@docusaurus/utils-validation": "3.8.1-canary-6364",
47
47
  "@types/react-router-config": "^5.0.7",
48
48
  "combine-promises": "^1.1.0",
49
49
  "fs-extra": "^11.1.1",
@@ -67,5 +67,5 @@
67
67
  "engines": {
68
68
  "node": ">=18.0"
69
69
  },
70
- "gitHead": "184f214bf6cf8502921c316289df34500fb9ebb7"
70
+ "gitHead": "eb21e3eaf84009a29feff55780bb5d3a76658d01"
71
71
  }
package/src/cli.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  import fs from 'fs-extra';
9
9
  import path from 'path';
10
10
  import logger from '@docusaurus/logger';
11
- import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
11
+ import {DEFAULT_PLUGIN_ID, getLocaleConfig} from '@docusaurus/utils';
12
12
  import {
13
13
  getVersionsFilePath,
14
14
  getVersionDocsDirPath,
@@ -89,7 +89,7 @@ async function cliDocsVersionCommand(
89
89
  const localizationDir = path.resolve(
90
90
  siteDir,
91
91
  i18n.path,
92
- i18n.localeConfigs[locale]!.path,
92
+ getLocaleConfig(i18n, locale).path,
93
93
  );
94
94
  // Copy docs files.
95
95
  const docsDir =
package/src/docs.ts CHANGED
@@ -196,7 +196,9 @@ async function doProcessDocMetadata({
196
196
  locale: context.i18n.currentLocale,
197
197
  });
198
198
  } else if (typeof options.editUrl === 'string') {
199
- const isLocalized = contentPath === versionMetadata.contentPathLocalized;
199
+ const isLocalized =
200
+ typeof versionMetadata.contentPathLocalized !== 'undefined' &&
201
+ contentPath === versionMetadata.contentPathLocalized;
200
202
  const baseVersionEditUrl =
201
203
  isLocalized && options.editLocalizedFiles
202
204
  ? versionMetadata.editUrlLocalized
@@ -7,7 +7,11 @@
7
7
 
8
8
  import path from 'path';
9
9
  import fs from 'fs-extra';
10
- import {getPluginI18nPath, DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
10
+ import {
11
+ getPluginI18nPath,
12
+ getLocaleConfig,
13
+ DEFAULT_PLUGIN_ID,
14
+ } from '@docusaurus/utils';
11
15
  import {
12
16
  VERSIONS_JSON_FILE,
13
17
  VERSIONED_DOCS_DIR,
@@ -186,11 +190,16 @@ export async function getVersionMetadataPaths({
186
190
  >
187
191
  > {
188
192
  const isCurrent = versionName === CURRENT_VERSION_NAME;
189
- const contentPathLocalized = getDocsDirPathLocalized({
190
- localizationDir: context.localizationDir,
191
- pluginId: options.id,
192
- versionName,
193
- });
193
+
194
+ const shouldTranslate = getLocaleConfig(context.i18n).translate;
195
+ const contentPathLocalized = shouldTranslate
196
+ ? getDocsDirPathLocalized({
197
+ localizationDir: context.localizationDir,
198
+ pluginId: options.id,
199
+ versionName,
200
+ })
201
+ : undefined;
202
+
194
203
  const contentPath = isCurrent
195
204
  ? path.resolve(context.siteDir, options.path)
196
205
  : getVersionDocsDirPath(context.siteDir, options.id, versionName);
@@ -50,33 +50,47 @@ function getVersionEditUrls({
50
50
  return {editUrl: undefined, editUrlLocalized: undefined};
51
51
  }
52
52
 
53
- const editDirPath = options.editCurrentVersion ? options.path : contentPath;
54
- const editDirPathLocalized = options.editCurrentVersion
55
- ? getDocsDirPathLocalized({
56
- localizationDir: context.localizationDir,
57
- versionName: CURRENT_VERSION_NAME,
58
- pluginId: options.id,
59
- })
60
- : contentPathLocalized;
53
+ // Intermediate var just to please TS not narrowing to "string"
54
+ const editUrlOption = options.editUrl;
61
55
 
62
- const versionPathSegment = posixPath(
63
- path.relative(context.siteDir, path.resolve(context.siteDir, editDirPath)),
64
- );
65
- const versionPathSegmentLocalized = posixPath(
66
- path.relative(
67
- context.siteDir,
68
- path.resolve(context.siteDir, editDirPathLocalized),
69
- ),
70
- );
56
+ const getEditUrl = () => {
57
+ const editDirPath = options.editCurrentVersion ? options.path : contentPath;
58
+
59
+ return normalizeUrl([
60
+ editUrlOption,
61
+ posixPath(
62
+ path.relative(
63
+ context.siteDir,
64
+ path.resolve(context.siteDir, editDirPath),
65
+ ),
66
+ ),
67
+ ]);
68
+ };
71
69
 
72
- const editUrl = normalizeUrl([options.editUrl, versionPathSegment]);
70
+ const getEditUrlLocalized = () => {
71
+ if (!contentPathLocalized) {
72
+ return undefined;
73
+ }
74
+ const editDirPathLocalized = options.editCurrentVersion
75
+ ? getDocsDirPathLocalized({
76
+ localizationDir: context.localizationDir,
77
+ versionName: CURRENT_VERSION_NAME,
78
+ pluginId: options.id,
79
+ })
80
+ : contentPathLocalized;
73
81
 
74
- const editUrlLocalized = normalizeUrl([
75
- options.editUrl,
76
- versionPathSegmentLocalized,
77
- ]);
82
+ return normalizeUrl([
83
+ editUrlOption,
84
+ posixPath(
85
+ path.relative(
86
+ context.siteDir,
87
+ path.resolve(context.siteDir, editDirPathLocalized),
88
+ ),
89
+ ),
90
+ ]);
91
+ };
78
92
 
79
- return {editUrl, editUrlLocalized};
93
+ return {editUrl: getEditUrl(), editUrlLocalized: getEditUrlLocalized()};
80
94
  }
81
95
 
82
96
  /**