@docusaurus/plugin-content-docs 0.0.0-5956 → 0.0.0-5961
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/index.js +52 -47
- package/lib/types.d.ts +2 -9
- package/lib/versions/index.d.ts +1 -0
- package/lib/versions/index.js +9 -1
- package/package.json +10 -10
- package/src/index.ts +73 -67
- package/src/types.ts +1 -11
- package/src/versions/index.ts +18 -1
- package/lib/markdown/index.d.ts +0 -9
- package/lib/markdown/index.js +0 -16
- package/lib/markdown/linkify.d.ts +0 -8
- package/lib/markdown/linkify.js +0 -34
- package/src/markdown/index.ts +0 -20
- package/src/markdown/linkify.ts +0 -47
package/lib/index.js
CHANGED
|
@@ -160,57 +160,56 @@ async function pluginContentDocs(context, options) {
|
|
|
160
160
|
},
|
|
161
161
|
configureWebpack(_config, isServer, utils, content) {
|
|
162
162
|
const { rehypePlugins, remarkPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
|
|
163
|
+
const contentDirs = versionsMetadata
|
|
164
|
+
.flatMap(utils_1.getContentPathList)
|
|
165
|
+
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
|
|
166
|
+
.map(utils_1.addTrailingPathSeparator);
|
|
167
|
+
// TODO this does not re-run when content gets updated in dev!
|
|
168
|
+
// it's probably better to restore a mutable cache in the plugin
|
|
163
169
|
function getSourceToPermalink() {
|
|
164
170
|
const allDocs = content.loadedVersions.flatMap((v) => v.docs);
|
|
165
171
|
return Object.fromEntries(allDocs.map(({ source, permalink }) => [source, permalink]));
|
|
166
172
|
}
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
173
|
+
const sourceToPermalink = getSourceToPermalink();
|
|
174
|
+
function createMDXLoader() {
|
|
175
|
+
const loaderOptions = {
|
|
176
|
+
admonitions: options.admonitions,
|
|
177
|
+
remarkPlugins,
|
|
178
|
+
rehypePlugins,
|
|
179
|
+
beforeDefaultRehypePlugins,
|
|
180
|
+
beforeDefaultRemarkPlugins,
|
|
181
|
+
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
182
|
+
siteDir,
|
|
183
|
+
isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
|
|
184
|
+
metadataPath: (mdxPath) => {
|
|
185
|
+
// Note that metadataPath must be the same/in-sync as
|
|
186
|
+
// the path from createData for each MDX.
|
|
187
|
+
const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
|
|
188
|
+
return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
|
|
189
|
+
},
|
|
190
|
+
// Assets allow to convert some relative images paths to
|
|
191
|
+
// require(...) calls
|
|
192
|
+
createAssets: ({ frontMatter }) => ({
|
|
193
|
+
image: frontMatter.image,
|
|
194
|
+
}),
|
|
195
|
+
markdownConfig: siteConfig.markdown,
|
|
196
|
+
resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
|
|
197
|
+
const version = (0, versions_1.getVersionFromSourceFilePath)(sourceFilePath, content.loadedVersions);
|
|
198
|
+
const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
|
|
199
|
+
sourceFilePath,
|
|
200
|
+
sourceToPermalink,
|
|
201
|
+
siteDir,
|
|
202
|
+
contentPaths: version,
|
|
203
|
+
});
|
|
204
|
+
if (permalink === null) {
|
|
205
|
+
logger_1.default.report(siteConfig.onBrokenMarkdownLinks) `Docs markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath} for version number=${version.versionName}`;
|
|
206
|
+
}
|
|
207
|
+
return permalink;
|
|
208
|
+
},
|
|
209
|
+
};
|
|
180
210
|
return {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
use: [
|
|
184
|
-
{
|
|
185
|
-
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
186
|
-
options: {
|
|
187
|
-
admonitions: options.admonitions,
|
|
188
|
-
remarkPlugins,
|
|
189
|
-
rehypePlugins,
|
|
190
|
-
beforeDefaultRehypePlugins,
|
|
191
|
-
beforeDefaultRemarkPlugins,
|
|
192
|
-
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
193
|
-
siteDir,
|
|
194
|
-
isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
|
|
195
|
-
metadataPath: (mdxPath) => {
|
|
196
|
-
// Note that metadataPath must be the same/in-sync as
|
|
197
|
-
// the path from createData for each MDX.
|
|
198
|
-
const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
|
|
199
|
-
return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
|
|
200
|
-
},
|
|
201
|
-
// Assets allow to convert some relative images paths to
|
|
202
|
-
// require(...) calls
|
|
203
|
-
createAssets: ({ frontMatter, }) => ({
|
|
204
|
-
image: frontMatter.image,
|
|
205
|
-
}),
|
|
206
|
-
markdownConfig: siteConfig.markdown,
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
loader: path_1.default.resolve(__dirname, './markdown/index.js'),
|
|
211
|
-
options: docsMarkdownOptions,
|
|
212
|
-
},
|
|
213
|
-
].filter(Boolean),
|
|
211
|
+
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
212
|
+
options: loaderOptions,
|
|
214
213
|
};
|
|
215
214
|
}
|
|
216
215
|
return {
|
|
@@ -225,7 +224,13 @@ async function pluginContentDocs(context, options) {
|
|
|
225
224
|
},
|
|
226
225
|
},
|
|
227
226
|
module: {
|
|
228
|
-
rules: [
|
|
227
|
+
rules: [
|
|
228
|
+
{
|
|
229
|
+
test: /\.mdx?$/i,
|
|
230
|
+
include: contentDirs,
|
|
231
|
+
use: [createMDXLoader()],
|
|
232
|
+
},
|
|
233
|
+
],
|
|
229
234
|
},
|
|
230
235
|
};
|
|
231
236
|
},
|
package/lib/types.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
/// <reference path="../src/plugin-content-docs.d.ts" />
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
8
|
+
import type { Tag } from '@docusaurus/utils';
|
|
9
|
+
import type { LoadedVersion, CategoryGeneratedIndexMetadata } from '@docusaurus/plugin-content-docs';
|
|
10
10
|
import type { SidebarsUtils } from './sidebars/utils';
|
|
11
11
|
export type DocFile = {
|
|
12
12
|
contentPath: string;
|
|
@@ -29,10 +29,3 @@ export type FullVersion = LoadedVersion & {
|
|
|
29
29
|
sidebarsUtils: SidebarsUtils;
|
|
30
30
|
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
|
|
31
31
|
};
|
|
32
|
-
export type DocBrokenMarkdownLink = BrokenMarkdownLink<VersionMetadata>;
|
|
33
|
-
export type DocsMarkdownOption = {
|
|
34
|
-
versionsMetadata: VersionMetadata[];
|
|
35
|
-
siteDir: string;
|
|
36
|
-
sourceToPermalink: SourceToPermalink;
|
|
37
|
-
onBrokenMarkdownLink: (brokenMarkdownLink: DocBrokenMarkdownLink) => void;
|
|
38
|
-
};
|
package/lib/versions/index.d.ts
CHANGED
|
@@ -38,3 +38,4 @@ export declare function readVersionsMetadata({ context, options, }: {
|
|
|
38
38
|
options: PluginOptions;
|
|
39
39
|
}): Promise<VersionMetadata[]>;
|
|
40
40
|
export declare function toFullVersion(version: LoadedVersion): FullVersion;
|
|
41
|
+
export declare function getVersionFromSourceFilePath(filePath: string, versionsMetadata: VersionMetadata[]): VersionMetadata;
|
package/lib/versions/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.toFullVersion = exports.readVersionsMetadata = exports.filterVersions = exports.getVersionNoIndex = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = void 0;
|
|
9
|
+
exports.getVersionFromSourceFilePath = exports.toFullVersion = exports.readVersionsMetadata = exports.filterVersions = exports.getVersionNoIndex = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
@@ -171,3 +171,11 @@ function toFullVersion(version) {
|
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
173
|
exports.toFullVersion = toFullVersion;
|
|
174
|
+
function getVersionFromSourceFilePath(filePath, versionsMetadata) {
|
|
175
|
+
const versionFound = versionsMetadata.find((version) => (0, utils_1.getContentPathList)(version).some((docsDirPath) => filePath.startsWith(docsDirPath)));
|
|
176
|
+
if (!versionFound) {
|
|
177
|
+
throw new Error(`Unexpected error: file at "${filePath}" does not belong to any docs version!`);
|
|
178
|
+
}
|
|
179
|
+
return versionFound;
|
|
180
|
+
}
|
|
181
|
+
exports.getVersionFromSourceFilePath = getVersionFromSourceFilePath;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-5961",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
},
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@docusaurus/core": "0.0.0-
|
|
39
|
-
"@docusaurus/logger": "0.0.0-
|
|
40
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
41
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
42
|
-
"@docusaurus/types": "0.0.0-
|
|
43
|
-
"@docusaurus/utils": "0.0.0-
|
|
44
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
45
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
38
|
+
"@docusaurus/core": "0.0.0-5961",
|
|
39
|
+
"@docusaurus/logger": "0.0.0-5961",
|
|
40
|
+
"@docusaurus/mdx-loader": "0.0.0-5961",
|
|
41
|
+
"@docusaurus/module-type-aliases": "0.0.0-5961",
|
|
42
|
+
"@docusaurus/types": "0.0.0-5961",
|
|
43
|
+
"@docusaurus/utils": "0.0.0-5961",
|
|
44
|
+
"@docusaurus/utils-common": "0.0.0-5961",
|
|
45
|
+
"@docusaurus/utils-validation": "0.0.0-5961",
|
|
46
46
|
"@types/react-router-config": "^5.0.7",
|
|
47
47
|
"combine-promises": "^1.1.0",
|
|
48
48
|
"fs-extra": "^11.1.1",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"engines": {
|
|
67
67
|
"node": ">=18.0"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "ae17c4245467ae9c0c218dc375d4d059410f8622"
|
|
70
70
|
}
|
package/src/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
addTrailingPathSeparator,
|
|
18
18
|
createAbsoluteFilePathMatcher,
|
|
19
19
|
createSlugger,
|
|
20
|
+
resolveMarkdownLinkPathname,
|
|
20
21
|
DEFAULT_PLUGIN_ID,
|
|
21
22
|
} from '@docusaurus/utils';
|
|
22
23
|
import {loadSidebars, resolveSidebarPathOption} from './sidebars';
|
|
@@ -28,7 +29,11 @@ import {
|
|
|
28
29
|
type DocEnv,
|
|
29
30
|
createDocsByIdIndex,
|
|
30
31
|
} from './docs';
|
|
31
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
getVersionFromSourceFilePath,
|
|
34
|
+
readVersionsMetadata,
|
|
35
|
+
toFullVersion,
|
|
36
|
+
} from './versions';
|
|
32
37
|
import {cliDocsVersionCommand} from './cli';
|
|
33
38
|
import {VERSIONS_JSON_FILE} from './constants';
|
|
34
39
|
import {toGlobalDataVersion} from './globalData';
|
|
@@ -38,6 +43,7 @@ import {
|
|
|
38
43
|
} from './translations';
|
|
39
44
|
import {createAllRoutes} from './routes';
|
|
40
45
|
import {createSidebarsUtils} from './sidebars/utils';
|
|
46
|
+
import type {Options as MDXLoaderOptions} from '@docusaurus/mdx-loader';
|
|
41
47
|
|
|
42
48
|
import type {
|
|
43
49
|
PluginOptions,
|
|
@@ -48,13 +54,8 @@ import type {
|
|
|
48
54
|
LoadedVersion,
|
|
49
55
|
} from '@docusaurus/plugin-content-docs';
|
|
50
56
|
import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
51
|
-
import type {
|
|
52
|
-
|
|
53
|
-
DocFile,
|
|
54
|
-
DocsMarkdownOption,
|
|
55
|
-
FullVersion,
|
|
56
|
-
} from './types';
|
|
57
|
-
import type {RuleSetRule} from 'webpack';
|
|
57
|
+
import type {SourceToPermalink, DocFile, FullVersion} from './types';
|
|
58
|
+
import type {RuleSetUseItem} from 'webpack';
|
|
58
59
|
|
|
59
60
|
export default async function pluginContentDocs(
|
|
60
61
|
context: LoadContext,
|
|
@@ -251,72 +252,71 @@ export default async function pluginContentDocs(
|
|
|
251
252
|
beforeDefaultRemarkPlugins,
|
|
252
253
|
} = options;
|
|
253
254
|
|
|
255
|
+
const contentDirs = versionsMetadata
|
|
256
|
+
.flatMap(getContentPathList)
|
|
257
|
+
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
|
|
258
|
+
.map(addTrailingPathSeparator);
|
|
259
|
+
|
|
260
|
+
// TODO this does not re-run when content gets updated in dev!
|
|
261
|
+
// it's probably better to restore a mutable cache in the plugin
|
|
254
262
|
function getSourceToPermalink(): SourceToPermalink {
|
|
255
263
|
const allDocs = content.loadedVersions.flatMap((v) => v.docs);
|
|
256
264
|
return Object.fromEntries(
|
|
257
265
|
allDocs.map(({source, permalink}) => [source, permalink]),
|
|
258
266
|
);
|
|
259
267
|
}
|
|
268
|
+
const sourceToPermalink = getSourceToPermalink();
|
|
269
|
+
|
|
270
|
+
function createMDXLoader(): RuleSetUseItem {
|
|
271
|
+
const loaderOptions: MDXLoaderOptions = {
|
|
272
|
+
admonitions: options.admonitions,
|
|
273
|
+
remarkPlugins,
|
|
274
|
+
rehypePlugins,
|
|
275
|
+
beforeDefaultRehypePlugins,
|
|
276
|
+
beforeDefaultRemarkPlugins,
|
|
277
|
+
staticDirs: siteConfig.staticDirectories.map((dir) =>
|
|
278
|
+
path.resolve(siteDir, dir),
|
|
279
|
+
),
|
|
280
|
+
siteDir,
|
|
281
|
+
isMDXPartial: createAbsoluteFilePathMatcher(
|
|
282
|
+
options.exclude,
|
|
283
|
+
contentDirs,
|
|
284
|
+
),
|
|
285
|
+
metadataPath: (mdxPath: string) => {
|
|
286
|
+
// Note that metadataPath must be the same/in-sync as
|
|
287
|
+
// the path from createData for each MDX.
|
|
288
|
+
const aliasedPath = aliasedSitePath(mdxPath, siteDir);
|
|
289
|
+
return path.join(dataDir, `${docuHash(aliasedPath)}.json`);
|
|
290
|
+
},
|
|
291
|
+
// Assets allow to convert some relative images paths to
|
|
292
|
+
// require(...) calls
|
|
293
|
+
createAssets: ({frontMatter}: {frontMatter: DocFrontMatter}) => ({
|
|
294
|
+
image: frontMatter.image,
|
|
295
|
+
}),
|
|
296
|
+
markdownConfig: siteConfig.markdown,
|
|
297
|
+
resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
|
|
298
|
+
const version = getVersionFromSourceFilePath(
|
|
299
|
+
sourceFilePath,
|
|
300
|
+
content.loadedVersions,
|
|
301
|
+
);
|
|
302
|
+
const permalink = resolveMarkdownLinkPathname(linkPathname, {
|
|
303
|
+
sourceFilePath,
|
|
304
|
+
sourceToPermalink,
|
|
305
|
+
siteDir,
|
|
306
|
+
contentPaths: version,
|
|
307
|
+
});
|
|
308
|
+
if (permalink === null) {
|
|
309
|
+
logger.report(
|
|
310
|
+
siteConfig.onBrokenMarkdownLinks,
|
|
311
|
+
)`Docs markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath} for version number=${version.versionName}`;
|
|
312
|
+
}
|
|
313
|
+
return permalink;
|
|
314
|
+
},
|
|
315
|
+
};
|
|
260
316
|
|
|
261
|
-
const docsMarkdownOptions: DocsMarkdownOption = {
|
|
262
|
-
siteDir,
|
|
263
|
-
sourceToPermalink: getSourceToPermalink(),
|
|
264
|
-
versionsMetadata,
|
|
265
|
-
onBrokenMarkdownLink: (brokenMarkdownLink) => {
|
|
266
|
-
logger.report(
|
|
267
|
-
siteConfig.onBrokenMarkdownLinks,
|
|
268
|
-
)`Docs markdown link couldn't be resolved: (url=${brokenMarkdownLink.link}) in path=${brokenMarkdownLink.filePath} for version number=${brokenMarkdownLink.contentPaths.versionName}`;
|
|
269
|
-
},
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
function createMDXLoaderRule(): RuleSetRule {
|
|
273
|
-
const contentDirs = versionsMetadata
|
|
274
|
-
.flatMap(getContentPathList)
|
|
275
|
-
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
|
|
276
|
-
.map(addTrailingPathSeparator);
|
|
277
317
|
return {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
use: [
|
|
281
|
-
{
|
|
282
|
-
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
283
|
-
options: {
|
|
284
|
-
admonitions: options.admonitions,
|
|
285
|
-
remarkPlugins,
|
|
286
|
-
rehypePlugins,
|
|
287
|
-
beforeDefaultRehypePlugins,
|
|
288
|
-
beforeDefaultRemarkPlugins,
|
|
289
|
-
staticDirs: siteConfig.staticDirectories.map((dir) =>
|
|
290
|
-
path.resolve(siteDir, dir),
|
|
291
|
-
),
|
|
292
|
-
siteDir,
|
|
293
|
-
isMDXPartial: createAbsoluteFilePathMatcher(
|
|
294
|
-
options.exclude,
|
|
295
|
-
contentDirs,
|
|
296
|
-
),
|
|
297
|
-
metadataPath: (mdxPath: string) => {
|
|
298
|
-
// Note that metadataPath must be the same/in-sync as
|
|
299
|
-
// the path from createData for each MDX.
|
|
300
|
-
const aliasedPath = aliasedSitePath(mdxPath, siteDir);
|
|
301
|
-
return path.join(dataDir, `${docuHash(aliasedPath)}.json`);
|
|
302
|
-
},
|
|
303
|
-
// Assets allow to convert some relative images paths to
|
|
304
|
-
// require(...) calls
|
|
305
|
-
createAssets: ({
|
|
306
|
-
frontMatter,
|
|
307
|
-
}: {
|
|
308
|
-
frontMatter: DocFrontMatter;
|
|
309
|
-
}) => ({
|
|
310
|
-
image: frontMatter.image,
|
|
311
|
-
}),
|
|
312
|
-
markdownConfig: siteConfig.markdown,
|
|
313
|
-
},
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
loader: path.resolve(__dirname, './markdown/index.js'),
|
|
317
|
-
options: docsMarkdownOptions,
|
|
318
|
-
},
|
|
319
|
-
].filter(Boolean),
|
|
318
|
+
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
319
|
+
options: loaderOptions,
|
|
320
320
|
};
|
|
321
321
|
}
|
|
322
322
|
|
|
@@ -333,7 +333,13 @@ export default async function pluginContentDocs(
|
|
|
333
333
|
},
|
|
334
334
|
},
|
|
335
335
|
module: {
|
|
336
|
-
rules: [
|
|
336
|
+
rules: [
|
|
337
|
+
{
|
|
338
|
+
test: /\.mdx?$/i,
|
|
339
|
+
include: contentDirs,
|
|
340
|
+
use: [createMDXLoader()],
|
|
341
|
+
},
|
|
342
|
+
],
|
|
337
343
|
},
|
|
338
344
|
};
|
|
339
345
|
},
|
package/src/types.ts
CHANGED
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type {Tag} from '@docusaurus/utils';
|
|
9
9
|
import type {
|
|
10
|
-
VersionMetadata,
|
|
11
10
|
LoadedVersion,
|
|
12
11
|
CategoryGeneratedIndexMetadata,
|
|
13
12
|
} from '@docusaurus/plugin-content-docs';
|
|
@@ -37,12 +36,3 @@ export type FullVersion = LoadedVersion & {
|
|
|
37
36
|
sidebarsUtils: SidebarsUtils;
|
|
38
37
|
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
|
|
39
38
|
};
|
|
40
|
-
|
|
41
|
-
export type DocBrokenMarkdownLink = BrokenMarkdownLink<VersionMetadata>;
|
|
42
|
-
|
|
43
|
-
export type DocsMarkdownOption = {
|
|
44
|
-
versionsMetadata: VersionMetadata[];
|
|
45
|
-
siteDir: string;
|
|
46
|
-
sourceToPermalink: SourceToPermalink;
|
|
47
|
-
onBrokenMarkdownLink: (brokenMarkdownLink: DocBrokenMarkdownLink) => void;
|
|
48
|
-
};
|
package/src/versions/index.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
|
-
import {normalizeUrl, posixPath} from '@docusaurus/utils';
|
|
9
|
+
import {getContentPathList, normalizeUrl, posixPath} from '@docusaurus/utils';
|
|
10
10
|
import {CURRENT_VERSION_NAME} from '../constants';
|
|
11
11
|
import {validateVersionsOptions} from './validation';
|
|
12
12
|
import {
|
|
@@ -268,3 +268,20 @@ export function toFullVersion(version: LoadedVersion): FullVersion {
|
|
|
268
268
|
}),
|
|
269
269
|
};
|
|
270
270
|
}
|
|
271
|
+
|
|
272
|
+
export function getVersionFromSourceFilePath(
|
|
273
|
+
filePath: string,
|
|
274
|
+
versionsMetadata: VersionMetadata[],
|
|
275
|
+
): VersionMetadata {
|
|
276
|
+
const versionFound = versionsMetadata.find((version) =>
|
|
277
|
+
getContentPathList(version).some((docsDirPath) =>
|
|
278
|
+
filePath.startsWith(docsDirPath),
|
|
279
|
+
),
|
|
280
|
+
);
|
|
281
|
+
if (!versionFound) {
|
|
282
|
+
throw new Error(
|
|
283
|
+
`Unexpected error: file at "${filePath}" does not belong to any docs version!`,
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
return versionFound;
|
|
287
|
+
}
|
package/lib/markdown/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import type { DocsMarkdownOption } from '../types';
|
|
8
|
-
import type { LoaderContext } from 'webpack';
|
|
9
|
-
export default function markdownLoader(this: LoaderContext<DocsMarkdownOption>, source: string): void;
|
package/lib/markdown/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const linkify_1 = require("./linkify");
|
|
10
|
-
function markdownLoader(source) {
|
|
11
|
-
const fileString = source;
|
|
12
|
-
const callback = this.async();
|
|
13
|
-
const options = this.getOptions();
|
|
14
|
-
return callback(null, (0, linkify_1.linkify)(fileString, this.resourcePath, options));
|
|
15
|
-
}
|
|
16
|
-
exports.default = markdownLoader;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import type { DocsMarkdownOption } from '../types';
|
|
8
|
-
export declare function linkify(fileString: string, filePath: string, options: DocsMarkdownOption): string;
|
package/lib/markdown/linkify.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.linkify = void 0;
|
|
10
|
-
const utils_1 = require("@docusaurus/utils");
|
|
11
|
-
function getVersion(filePath, options) {
|
|
12
|
-
const versionFound = options.versionsMetadata.find((version) => (0, utils_1.getContentPathList)(version).some((docsDirPath) => filePath.startsWith(docsDirPath)));
|
|
13
|
-
// At this point, this should never happen, because the MDX loaders' paths are
|
|
14
|
-
// literally using the version content paths; but if we allow sourcing content
|
|
15
|
-
// from outside the docs directory (through the `include` option, for example;
|
|
16
|
-
// is there a compelling use-case?), this would actually be testable
|
|
17
|
-
if (!versionFound) {
|
|
18
|
-
throw new Error(`Unexpected error: Markdown file at "${filePath}" does not belong to any docs version!`);
|
|
19
|
-
}
|
|
20
|
-
return versionFound;
|
|
21
|
-
}
|
|
22
|
-
function linkify(fileString, filePath, options) {
|
|
23
|
-
const { siteDir, sourceToPermalink, onBrokenMarkdownLink } = options;
|
|
24
|
-
const { newContent, brokenMarkdownLinks } = (0, utils_1.replaceMarkdownLinks)({
|
|
25
|
-
siteDir,
|
|
26
|
-
fileString,
|
|
27
|
-
filePath,
|
|
28
|
-
contentPaths: getVersion(filePath, options),
|
|
29
|
-
sourceToPermalink,
|
|
30
|
-
});
|
|
31
|
-
brokenMarkdownLinks.forEach((l) => onBrokenMarkdownLink(l));
|
|
32
|
-
return newContent;
|
|
33
|
-
}
|
|
34
|
-
exports.linkify = linkify;
|
package/src/markdown/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {linkify} from './linkify';
|
|
9
|
-
import type {DocsMarkdownOption} from '../types';
|
|
10
|
-
import type {LoaderContext} from 'webpack';
|
|
11
|
-
|
|
12
|
-
export default function markdownLoader(
|
|
13
|
-
this: LoaderContext<DocsMarkdownOption>,
|
|
14
|
-
source: string,
|
|
15
|
-
): void {
|
|
16
|
-
const fileString = source;
|
|
17
|
-
const callback = this.async();
|
|
18
|
-
const options = this.getOptions();
|
|
19
|
-
return callback(null, linkify(fileString, this.resourcePath, options));
|
|
20
|
-
}
|
package/src/markdown/linkify.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {replaceMarkdownLinks, getContentPathList} from '@docusaurus/utils';
|
|
9
|
-
import type {DocsMarkdownOption} from '../types';
|
|
10
|
-
|
|
11
|
-
function getVersion(filePath: string, options: DocsMarkdownOption) {
|
|
12
|
-
const versionFound = options.versionsMetadata.find((version) =>
|
|
13
|
-
getContentPathList(version).some((docsDirPath) =>
|
|
14
|
-
filePath.startsWith(docsDirPath),
|
|
15
|
-
),
|
|
16
|
-
);
|
|
17
|
-
// At this point, this should never happen, because the MDX loaders' paths are
|
|
18
|
-
// literally using the version content paths; but if we allow sourcing content
|
|
19
|
-
// from outside the docs directory (through the `include` option, for example;
|
|
20
|
-
// is there a compelling use-case?), this would actually be testable
|
|
21
|
-
if (!versionFound) {
|
|
22
|
-
throw new Error(
|
|
23
|
-
`Unexpected error: Markdown file at "${filePath}" does not belong to any docs version!`,
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
return versionFound;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function linkify(
|
|
30
|
-
fileString: string,
|
|
31
|
-
filePath: string,
|
|
32
|
-
options: DocsMarkdownOption,
|
|
33
|
-
): string {
|
|
34
|
-
const {siteDir, sourceToPermalink, onBrokenMarkdownLink} = options;
|
|
35
|
-
|
|
36
|
-
const {newContent, brokenMarkdownLinks} = replaceMarkdownLinks({
|
|
37
|
-
siteDir,
|
|
38
|
-
fileString,
|
|
39
|
-
filePath,
|
|
40
|
-
contentPaths: getVersion(filePath, options),
|
|
41
|
-
sourceToPermalink,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
brokenMarkdownLinks.forEach((l) => onBrokenMarkdownLink(l));
|
|
45
|
-
|
|
46
|
-
return newContent;
|
|
47
|
-
}
|