@docusaurus/utils 2.0.0-beta.16 → 2.0.0-beta.19
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/constants.d.ts +51 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +57 -10
- package/lib/constants.js.map +1 -1
- package/lib/dataFileUtils.d.ts +38 -2
- package/lib/dataFileUtils.d.ts.map +1 -1
- package/lib/dataFileUtils.js +39 -13
- package/lib/dataFileUtils.js.map +1 -1
- package/lib/emitUtils.d.ts +32 -0
- package/lib/emitUtils.d.ts.map +1 -0
- package/lib/emitUtils.js +80 -0
- package/lib/emitUtils.js.map +1 -0
- package/lib/gitUtils.d.ts +54 -5
- package/lib/gitUtils.d.ts.map +1 -1
- package/lib/gitUtils.js +17 -14
- package/lib/gitUtils.js.map +1 -1
- package/lib/globUtils.d.ts +28 -0
- package/lib/globUtils.d.ts.map +1 -1
- package/lib/globUtils.js +36 -13
- package/lib/globUtils.js.map +1 -1
- package/lib/hashUtils.d.ts +5 -4
- package/lib/hashUtils.d.ts.map +1 -1
- package/lib/hashUtils.js +7 -6
- package/lib/hashUtils.js.map +1 -1
- package/lib/i18nUtils.d.ts +51 -0
- package/lib/i18nUtils.d.ts.map +1 -0
- package/lib/i18nUtils.js +69 -0
- package/lib/i18nUtils.js.map +1 -0
- package/lib/index.d.ts +10 -54
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +56 -256
- package/lib/index.js.map +1 -1
- package/lib/jsUtils.d.ts +45 -0
- package/lib/jsUtils.d.ts.map +1 -0
- package/lib/jsUtils.js +94 -0
- package/lib/jsUtils.js.map +1 -0
- package/lib/markdownLinks.d.ts +48 -5
- package/lib/markdownLinks.d.ts.map +1 -1
- package/lib/markdownLinks.js +29 -13
- package/lib/markdownLinks.js.map +1 -1
- package/lib/markdownUtils.d.ts +112 -0
- package/lib/markdownUtils.d.ts.map +1 -0
- package/lib/markdownUtils.js +271 -0
- package/lib/markdownUtils.js.map +1 -0
- package/lib/pathUtils.d.ts +2 -1
- package/lib/pathUtils.d.ts.map +1 -1
- package/lib/pathUtils.js +16 -7
- package/lib/pathUtils.js.map +1 -1
- package/lib/slugger.d.ts +10 -0
- package/lib/slugger.d.ts.map +1 -1
- package/lib/slugger.js +6 -2
- package/lib/slugger.js.map +1 -1
- package/lib/tags.d.ts +42 -10
- package/lib/tags.d.ts.map +1 -1
- package/lib/tags.js +40 -26
- package/lib/tags.js.map +1 -1
- package/lib/urlUtils.d.ts +57 -0
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js +132 -6
- package/lib/urlUtils.js.map +1 -1
- package/lib/webpackUtils.d.ts +5 -0
- package/lib/webpackUtils.d.ts.map +1 -1
- package/lib/webpackUtils.js +8 -5
- package/lib/webpackUtils.js.map +1 -1
- package/package.json +11 -11
- package/src/constants.ts +65 -9
- package/src/dataFileUtils.ts +44 -12
- package/src/emitUtils.ts +99 -0
- package/src/gitUtils.ts +77 -17
- package/src/globUtils.ts +34 -13
- package/src/hashUtils.ts +6 -5
- package/src/i18nUtils.ts +115 -0
- package/src/index.ts +43 -307
- package/src/jsUtils.ts +102 -0
- package/src/markdownLinks.ts +71 -28
- package/src/markdownUtils.ts +354 -0
- package/src/pathUtils.ts +15 -7
- package/src/slugger.ts +13 -1
- package/src/tags.ts +53 -28
- package/src/urlUtils.ts +145 -7
- package/src/webpackUtils.ts +11 -4
- package/lib/markdownParser.d.ts +0 -32
- package/lib/markdownParser.d.ts.map +0 -1
- package/lib/markdownParser.js +0 -161
- package/lib/markdownParser.js.map +0 -1
- package/src/markdownParser.ts +0 -201
package/lib/index.js
CHANGED
|
@@ -6,48 +6,66 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Object.defineProperty(exports, "
|
|
23
|
-
Object.defineProperty(exports, "
|
|
24
|
-
Object.defineProperty(exports, "
|
|
25
|
-
Object.defineProperty(exports, "
|
|
26
|
-
Object.defineProperty(exports, "
|
|
27
|
-
Object.defineProperty(exports, "
|
|
28
|
-
|
|
29
|
-
Object.defineProperty(exports, "
|
|
30
|
-
Object.defineProperty(exports, "
|
|
31
|
-
Object.defineProperty(exports, "THEME_PATH", { enumerable: true, get: function () { return constants_2.THEME_PATH; } });
|
|
32
|
-
Object.defineProperty(exports, "DEFAULT_PORT", { enumerable: true, get: function () { return constants_2.DEFAULT_PORT; } });
|
|
33
|
-
Object.defineProperty(exports, "DEFAULT_PLUGIN_ID", { enumerable: true, get: function () { return constants_2.DEFAULT_PLUGIN_ID; } });
|
|
34
|
-
Object.defineProperty(exports, "WEBPACK_URL_LOADER_LIMIT", { enumerable: true, get: function () { return constants_2.WEBPACK_URL_LOADER_LIMIT; } });
|
|
9
|
+
exports.writeMarkdownHeadingId = exports.parseMarkdownString = exports.parseMarkdownContentTitle = exports.parseFrontMatter = exports.createExcerpt = exports.parseMarkdownHeadingId = exports.groupTaggedItems = exports.normalizeFrontMatterTags = exports.buildSshUrl = exports.buildHttpsUrl = exports.hasSSHProtocol = exports.removeTrailingSlash = exports.addTrailingSlash = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.encodePath = exports.fileToPath = exports.getEditUrl = exports.normalizeUrl = exports.reportMessage = exports.findAsyncSequential = exports.mapAsyncSequential = exports.removePrefix = exports.removeSuffix = exports.localizePath = exports.getPluginI18nPath = exports.updateTranslationFileMessages = exports.mergeTranslations = exports.GitNotFoundError = exports.FileNotTrackedError = exports.getFileCommitDate = exports.readOutputHTMLFile = exports.generate = exports.WEBPACK_URL_LOADER_LIMIT = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.CODE_TRANSLATIONS_FILE_NAME = exports.I18N_DIR_NAME = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.DEFAULT_STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.DOCUSAURUS_VERSION = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
|
|
10
|
+
exports.getFolderContainingFile = exports.findFolderContainingFile = exports.getContentPathList = exports.getDataFileData = exports.getDataFilePath = exports.getFileLoaderUtils = exports.createAbsoluteFilePathMatcher = exports.createMatcher = exports.GlobExcludeDefault = exports.Globby = exports.docuHash = exports.simpleHash = exports.md5Hash = exports.addTrailingPathSeparator = exports.escapePath = exports.aliasedSitePath = exports.toMessageRelativeFilePath = exports.posixPath = exports.shortName = exports.isNameTooLong = exports.createSlugger = exports.replaceMarkdownLinks = void 0;
|
|
11
|
+
var constants_1 = require("./constants");
|
|
12
|
+
Object.defineProperty(exports, "NODE_MAJOR_VERSION", { enumerable: true, get: function () { return constants_1.NODE_MAJOR_VERSION; } });
|
|
13
|
+
Object.defineProperty(exports, "NODE_MINOR_VERSION", { enumerable: true, get: function () { return constants_1.NODE_MINOR_VERSION; } });
|
|
14
|
+
Object.defineProperty(exports, "DOCUSAURUS_VERSION", { enumerable: true, get: function () { return constants_1.DOCUSAURUS_VERSION; } });
|
|
15
|
+
Object.defineProperty(exports, "DEFAULT_BUILD_DIR_NAME", { enumerable: true, get: function () { return constants_1.DEFAULT_BUILD_DIR_NAME; } });
|
|
16
|
+
Object.defineProperty(exports, "DEFAULT_CONFIG_FILE_NAME", { enumerable: true, get: function () { return constants_1.DEFAULT_CONFIG_FILE_NAME; } });
|
|
17
|
+
Object.defineProperty(exports, "BABEL_CONFIG_FILE_NAME", { enumerable: true, get: function () { return constants_1.BABEL_CONFIG_FILE_NAME; } });
|
|
18
|
+
Object.defineProperty(exports, "GENERATED_FILES_DIR_NAME", { enumerable: true, get: function () { return constants_1.GENERATED_FILES_DIR_NAME; } });
|
|
19
|
+
Object.defineProperty(exports, "SRC_DIR_NAME", { enumerable: true, get: function () { return constants_1.SRC_DIR_NAME; } });
|
|
20
|
+
Object.defineProperty(exports, "DEFAULT_STATIC_DIR_NAME", { enumerable: true, get: function () { return constants_1.DEFAULT_STATIC_DIR_NAME; } });
|
|
21
|
+
Object.defineProperty(exports, "OUTPUT_STATIC_ASSETS_DIR_NAME", { enumerable: true, get: function () { return constants_1.OUTPUT_STATIC_ASSETS_DIR_NAME; } });
|
|
22
|
+
Object.defineProperty(exports, "THEME_PATH", { enumerable: true, get: function () { return constants_1.THEME_PATH; } });
|
|
23
|
+
Object.defineProperty(exports, "I18N_DIR_NAME", { enumerable: true, get: function () { return constants_1.I18N_DIR_NAME; } });
|
|
24
|
+
Object.defineProperty(exports, "CODE_TRANSLATIONS_FILE_NAME", { enumerable: true, get: function () { return constants_1.CODE_TRANSLATIONS_FILE_NAME; } });
|
|
25
|
+
Object.defineProperty(exports, "DEFAULT_PORT", { enumerable: true, get: function () { return constants_1.DEFAULT_PORT; } });
|
|
26
|
+
Object.defineProperty(exports, "DEFAULT_PLUGIN_ID", { enumerable: true, get: function () { return constants_1.DEFAULT_PLUGIN_ID; } });
|
|
27
|
+
Object.defineProperty(exports, "WEBPACK_URL_LOADER_LIMIT", { enumerable: true, get: function () { return constants_1.WEBPACK_URL_LOADER_LIMIT; } });
|
|
28
|
+
var emitUtils_1 = require("./emitUtils");
|
|
29
|
+
Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return emitUtils_1.generate; } });
|
|
30
|
+
Object.defineProperty(exports, "readOutputHTMLFile", { enumerable: true, get: function () { return emitUtils_1.readOutputHTMLFile; } });
|
|
35
31
|
var gitUtils_1 = require("./gitUtils");
|
|
36
32
|
Object.defineProperty(exports, "getFileCommitDate", { enumerable: true, get: function () { return gitUtils_1.getFileCommitDate; } });
|
|
33
|
+
Object.defineProperty(exports, "FileNotTrackedError", { enumerable: true, get: function () { return gitUtils_1.FileNotTrackedError; } });
|
|
37
34
|
Object.defineProperty(exports, "GitNotFoundError", { enumerable: true, get: function () { return gitUtils_1.GitNotFoundError; } });
|
|
35
|
+
var i18nUtils_1 = require("./i18nUtils");
|
|
36
|
+
Object.defineProperty(exports, "mergeTranslations", { enumerable: true, get: function () { return i18nUtils_1.mergeTranslations; } });
|
|
37
|
+
Object.defineProperty(exports, "updateTranslationFileMessages", { enumerable: true, get: function () { return i18nUtils_1.updateTranslationFileMessages; } });
|
|
38
|
+
Object.defineProperty(exports, "getPluginI18nPath", { enumerable: true, get: function () { return i18nUtils_1.getPluginI18nPath; } });
|
|
39
|
+
Object.defineProperty(exports, "localizePath", { enumerable: true, get: function () { return i18nUtils_1.localizePath; } });
|
|
40
|
+
var jsUtils_1 = require("./jsUtils");
|
|
41
|
+
Object.defineProperty(exports, "removeSuffix", { enumerable: true, get: function () { return jsUtils_1.removeSuffix; } });
|
|
42
|
+
Object.defineProperty(exports, "removePrefix", { enumerable: true, get: function () { return jsUtils_1.removePrefix; } });
|
|
43
|
+
Object.defineProperty(exports, "mapAsyncSequential", { enumerable: true, get: function () { return jsUtils_1.mapAsyncSequential; } });
|
|
44
|
+
Object.defineProperty(exports, "findAsyncSequential", { enumerable: true, get: function () { return jsUtils_1.findAsyncSequential; } });
|
|
45
|
+
Object.defineProperty(exports, "reportMessage", { enumerable: true, get: function () { return jsUtils_1.reportMessage; } });
|
|
38
46
|
var urlUtils_1 = require("./urlUtils");
|
|
39
47
|
Object.defineProperty(exports, "normalizeUrl", { enumerable: true, get: function () { return urlUtils_1.normalizeUrl; } });
|
|
40
48
|
Object.defineProperty(exports, "getEditUrl", { enumerable: true, get: function () { return urlUtils_1.getEditUrl; } });
|
|
49
|
+
Object.defineProperty(exports, "fileToPath", { enumerable: true, get: function () { return urlUtils_1.fileToPath; } });
|
|
50
|
+
Object.defineProperty(exports, "encodePath", { enumerable: true, get: function () { return urlUtils_1.encodePath; } });
|
|
51
|
+
Object.defineProperty(exports, "isValidPathname", { enumerable: true, get: function () { return urlUtils_1.isValidPathname; } });
|
|
52
|
+
Object.defineProperty(exports, "resolvePathname", { enumerable: true, get: function () { return urlUtils_1.resolvePathname; } });
|
|
53
|
+
Object.defineProperty(exports, "addLeadingSlash", { enumerable: true, get: function () { return urlUtils_1.addLeadingSlash; } });
|
|
54
|
+
Object.defineProperty(exports, "addTrailingSlash", { enumerable: true, get: function () { return urlUtils_1.addTrailingSlash; } });
|
|
55
|
+
Object.defineProperty(exports, "removeTrailingSlash", { enumerable: true, get: function () { return urlUtils_1.removeTrailingSlash; } });
|
|
56
|
+
Object.defineProperty(exports, "hasSSHProtocol", { enumerable: true, get: function () { return urlUtils_1.hasSSHProtocol; } });
|
|
57
|
+
Object.defineProperty(exports, "buildHttpsUrl", { enumerable: true, get: function () { return urlUtils_1.buildHttpsUrl; } });
|
|
58
|
+
Object.defineProperty(exports, "buildSshUrl", { enumerable: true, get: function () { return urlUtils_1.buildSshUrl; } });
|
|
41
59
|
var tags_1 = require("./tags");
|
|
42
|
-
Object.defineProperty(exports, "normalizeFrontMatterTag", { enumerable: true, get: function () { return tags_1.normalizeFrontMatterTag; } });
|
|
43
60
|
Object.defineProperty(exports, "normalizeFrontMatterTags", { enumerable: true, get: function () { return tags_1.normalizeFrontMatterTags; } });
|
|
44
61
|
Object.defineProperty(exports, "groupTaggedItems", { enumerable: true, get: function () { return tags_1.groupTaggedItems; } });
|
|
45
|
-
var
|
|
46
|
-
Object.defineProperty(exports, "parseMarkdownHeadingId", { enumerable: true, get: function () { return
|
|
47
|
-
Object.defineProperty(exports, "createExcerpt", { enumerable: true, get: function () { return
|
|
48
|
-
Object.defineProperty(exports, "parseFrontMatter", { enumerable: true, get: function () { return
|
|
49
|
-
Object.defineProperty(exports, "parseMarkdownContentTitle", { enumerable: true, get: function () { return
|
|
50
|
-
Object.defineProperty(exports, "parseMarkdownString", { enumerable: true, get: function () { return
|
|
62
|
+
var markdownUtils_1 = require("./markdownUtils");
|
|
63
|
+
Object.defineProperty(exports, "parseMarkdownHeadingId", { enumerable: true, get: function () { return markdownUtils_1.parseMarkdownHeadingId; } });
|
|
64
|
+
Object.defineProperty(exports, "createExcerpt", { enumerable: true, get: function () { return markdownUtils_1.createExcerpt; } });
|
|
65
|
+
Object.defineProperty(exports, "parseFrontMatter", { enumerable: true, get: function () { return markdownUtils_1.parseFrontMatter; } });
|
|
66
|
+
Object.defineProperty(exports, "parseMarkdownContentTitle", { enumerable: true, get: function () { return markdownUtils_1.parseMarkdownContentTitle; } });
|
|
67
|
+
Object.defineProperty(exports, "parseMarkdownString", { enumerable: true, get: function () { return markdownUtils_1.parseMarkdownString; } });
|
|
68
|
+
Object.defineProperty(exports, "writeMarkdownHeadingId", { enumerable: true, get: function () { return markdownUtils_1.writeMarkdownHeadingId; } });
|
|
51
69
|
var markdownLinks_1 = require("./markdownLinks");
|
|
52
70
|
Object.defineProperty(exports, "replaceMarkdownLinks", { enumerable: true, get: function () { return markdownLinks_1.replaceMarkdownLinks; } });
|
|
53
71
|
var slugger_1 = require("./slugger");
|
|
@@ -59,10 +77,11 @@ Object.defineProperty(exports, "posixPath", { enumerable: true, get: function ()
|
|
|
59
77
|
Object.defineProperty(exports, "toMessageRelativeFilePath", { enumerable: true, get: function () { return pathUtils_1.toMessageRelativeFilePath; } });
|
|
60
78
|
Object.defineProperty(exports, "aliasedSitePath", { enumerable: true, get: function () { return pathUtils_1.aliasedSitePath; } });
|
|
61
79
|
Object.defineProperty(exports, "escapePath", { enumerable: true, get: function () { return pathUtils_1.escapePath; } });
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
Object.defineProperty(exports, "
|
|
65
|
-
Object.defineProperty(exports, "
|
|
80
|
+
Object.defineProperty(exports, "addTrailingPathSeparator", { enumerable: true, get: function () { return pathUtils_1.addTrailingPathSeparator; } });
|
|
81
|
+
var hashUtils_1 = require("./hashUtils");
|
|
82
|
+
Object.defineProperty(exports, "md5Hash", { enumerable: true, get: function () { return hashUtils_1.md5Hash; } });
|
|
83
|
+
Object.defineProperty(exports, "simpleHash", { enumerable: true, get: function () { return hashUtils_1.simpleHash; } });
|
|
84
|
+
Object.defineProperty(exports, "docuHash", { enumerable: true, get: function () { return hashUtils_1.docuHash; } });
|
|
66
85
|
var globUtils_1 = require("./globUtils");
|
|
67
86
|
Object.defineProperty(exports, "Globby", { enumerable: true, get: function () { return globUtils_1.Globby; } });
|
|
68
87
|
Object.defineProperty(exports, "GlobExcludeDefault", { enumerable: true, get: function () { return globUtils_1.GlobExcludeDefault; } });
|
|
@@ -76,223 +95,4 @@ Object.defineProperty(exports, "getDataFileData", { enumerable: true, get: funct
|
|
|
76
95
|
Object.defineProperty(exports, "getContentPathList", { enumerable: true, get: function () { return dataFileUtils_1.getContentPathList; } });
|
|
77
96
|
Object.defineProperty(exports, "findFolderContainingFile", { enumerable: true, get: function () { return dataFileUtils_1.findFolderContainingFile; } });
|
|
78
97
|
Object.defineProperty(exports, "getFolderContainingFile", { enumerable: true, get: function () { return dataFileUtils_1.getFolderContainingFile; } });
|
|
79
|
-
const fileHash = new Map();
|
|
80
|
-
async function generate(generatedFilesDir, file, content, skipCache = process.env.NODE_ENV === 'production') {
|
|
81
|
-
const filepath = path_1.default.join(generatedFilesDir, file);
|
|
82
|
-
if (skipCache) {
|
|
83
|
-
await fs_extra_1.default.ensureDir(path_1.default.dirname(filepath));
|
|
84
|
-
await fs_extra_1.default.writeFile(filepath, content);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
let lastHash = fileHash.get(filepath);
|
|
88
|
-
// If file already exists but its not in runtime cache yet,
|
|
89
|
-
// we try to calculate the content hash and then compare
|
|
90
|
-
// This is to avoid unnecessary overwriting and we can reuse old file.
|
|
91
|
-
if (!lastHash && (await fs_extra_1.default.pathExists(filepath))) {
|
|
92
|
-
const lastContent = await fs_extra_1.default.readFile(filepath, 'utf8');
|
|
93
|
-
lastHash = (0, crypto_1.createHash)('md5').update(lastContent).digest('hex');
|
|
94
|
-
fileHash.set(filepath, lastHash);
|
|
95
|
-
}
|
|
96
|
-
const currentHash = (0, crypto_1.createHash)('md5').update(content).digest('hex');
|
|
97
|
-
if (lastHash !== currentHash) {
|
|
98
|
-
await fs_extra_1.default.ensureDir(path_1.default.dirname(filepath));
|
|
99
|
-
await fs_extra_1.default.writeFile(filepath, content);
|
|
100
|
-
fileHash.set(filepath, currentHash);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
exports.generate = generate;
|
|
104
|
-
const indexRE = /(?<dirname>^|.*\/)index\.(?:mdx?|jsx?|tsx?)$/i;
|
|
105
|
-
const extRE = /\.(?:mdx?|jsx?|tsx?)$/;
|
|
106
|
-
/**
|
|
107
|
-
* Convert filepath to url path.
|
|
108
|
-
* Example: 'index.md' -> '/', 'foo/bar.js' -> '/foo/bar',
|
|
109
|
-
*/
|
|
110
|
-
function fileToPath(file) {
|
|
111
|
-
if (indexRE.test(file)) {
|
|
112
|
-
return file.replace(indexRE, '/$1');
|
|
113
|
-
}
|
|
114
|
-
return `/${file.replace(extRE, '').replace(/\\/g, '/')}`;
|
|
115
|
-
}
|
|
116
|
-
exports.fileToPath = fileToPath;
|
|
117
|
-
function encodePath(userPath) {
|
|
118
|
-
return userPath
|
|
119
|
-
.split('/')
|
|
120
|
-
.map((item) => encodeURIComponent(item))
|
|
121
|
-
.join('/');
|
|
122
|
-
}
|
|
123
|
-
exports.encodePath = encodePath;
|
|
124
|
-
const chunkNameCache = new Map();
|
|
125
|
-
/**
|
|
126
|
-
* Generate unique chunk name given a module path.
|
|
127
|
-
*/
|
|
128
|
-
function genChunkName(modulePath, prefix, preferredName, shortId = process.env.NODE_ENV === 'production') {
|
|
129
|
-
let chunkName = chunkNameCache.get(modulePath);
|
|
130
|
-
if (!chunkName) {
|
|
131
|
-
if (shortId) {
|
|
132
|
-
chunkName = (0, hashUtils_1.simpleHash)(modulePath, 8);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
let str = modulePath;
|
|
136
|
-
if (preferredName) {
|
|
137
|
-
const shortHash = (0, hashUtils_1.simpleHash)(modulePath, 3);
|
|
138
|
-
str = `${preferredName}${shortHash}`;
|
|
139
|
-
}
|
|
140
|
-
const name = str === '/' ? 'index' : (0, hashUtils_1.docuHash)(str);
|
|
141
|
-
chunkName = prefix ? `${prefix}---${name}` : name;
|
|
142
|
-
}
|
|
143
|
-
chunkNameCache.set(modulePath, chunkName);
|
|
144
|
-
}
|
|
145
|
-
return chunkName;
|
|
146
|
-
}
|
|
147
|
-
exports.genChunkName = genChunkName;
|
|
148
|
-
function isValidPathname(str) {
|
|
149
|
-
if (!str.startsWith('/')) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
|
-
// weird, but is there a better way?
|
|
154
|
-
const parsedPathname = new url_1.URL(str, 'https://domain.com').pathname;
|
|
155
|
-
return parsedPathname === str || parsedPathname === encodeURI(str);
|
|
156
|
-
}
|
|
157
|
-
catch {
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
exports.isValidPathname = isValidPathname;
|
|
162
|
-
// resolve pathname and fail fast if resolution fails
|
|
163
|
-
function resolvePathname(to, from) {
|
|
164
|
-
return (0, resolve_pathname_1.default)(to, from);
|
|
165
|
-
}
|
|
166
|
-
exports.resolvePathname = resolvePathname;
|
|
167
|
-
function addLeadingSlash(str) {
|
|
168
|
-
return str.startsWith('/') ? str : `/${str}`;
|
|
169
|
-
}
|
|
170
|
-
exports.addLeadingSlash = addLeadingSlash;
|
|
171
|
-
function addTrailingPathSeparator(str) {
|
|
172
|
-
return str.endsWith(path_1.default.sep)
|
|
173
|
-
? str
|
|
174
|
-
: // If this is Windows, we need to change the forward slash to backward
|
|
175
|
-
`${str.replace(/\/$/, '')}${path_1.default.sep}`;
|
|
176
|
-
}
|
|
177
|
-
exports.addTrailingPathSeparator = addTrailingPathSeparator;
|
|
178
|
-
// TODO deduplicate: also present in @docusaurus/utils-common
|
|
179
|
-
function addTrailingSlash(str) {
|
|
180
|
-
return str.endsWith('/') ? str : `${str}/`;
|
|
181
|
-
}
|
|
182
|
-
exports.addTrailingSlash = addTrailingSlash;
|
|
183
|
-
function removeTrailingSlash(str) {
|
|
184
|
-
return removeSuffix(str, '/');
|
|
185
|
-
}
|
|
186
|
-
exports.removeTrailingSlash = removeTrailingSlash;
|
|
187
|
-
function removeSuffix(str, suffix) {
|
|
188
|
-
if (suffix === '') {
|
|
189
|
-
return str; // always returns "" otherwise!
|
|
190
|
-
}
|
|
191
|
-
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
|
|
192
|
-
}
|
|
193
|
-
exports.removeSuffix = removeSuffix;
|
|
194
|
-
function removePrefix(str, prefix) {
|
|
195
|
-
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
|
|
196
|
-
}
|
|
197
|
-
exports.removePrefix = removePrefix;
|
|
198
|
-
function getElementsAround(array, aroundIndex) {
|
|
199
|
-
const min = 0;
|
|
200
|
-
const max = array.length - 1;
|
|
201
|
-
if (aroundIndex < min || aroundIndex > max) {
|
|
202
|
-
throw new Error(`Valid "aroundIndex" for array (of size ${array.length}) are between ${min} and ${max}, but you provided ${aroundIndex}.`);
|
|
203
|
-
}
|
|
204
|
-
const previous = aroundIndex === min ? undefined : array[aroundIndex - 1];
|
|
205
|
-
const next = aroundIndex === max ? undefined : array[aroundIndex + 1];
|
|
206
|
-
return { previous, next };
|
|
207
|
-
}
|
|
208
|
-
exports.getElementsAround = getElementsAround;
|
|
209
|
-
function getPluginI18nPath({ siteDir, locale, pluginName, pluginId = constants_1.DEFAULT_PLUGIN_ID, subPaths = [], }) {
|
|
210
|
-
return path_1.default.join(siteDir, 'i18n',
|
|
211
|
-
// namespace first by locale: convenient to work in a single folder for a
|
|
212
|
-
// translator
|
|
213
|
-
locale,
|
|
214
|
-
// Make it convenient to use for single-instance
|
|
215
|
-
// ie: return "docs", not "docs-default" nor "docs/default"
|
|
216
|
-
`${pluginName}${pluginId === constants_1.DEFAULT_PLUGIN_ID ? '' : `-${pluginId}`}`, ...subPaths);
|
|
217
|
-
}
|
|
218
|
-
exports.getPluginI18nPath = getPluginI18nPath;
|
|
219
|
-
/**
|
|
220
|
-
* @param permalink The URL that the HTML file corresponds to, without base URL
|
|
221
|
-
* @param outDir Full path to the output directory
|
|
222
|
-
* @param trailingSlash The site config option. If provided, only one path will
|
|
223
|
-
* be read.
|
|
224
|
-
* @returns This returns a buffer, which you have to decode string yourself if
|
|
225
|
-
* needed. (Not always necessary since the output isn't for human consumption
|
|
226
|
-
* anyways, and most HTML manipulation libs accept buffers)
|
|
227
|
-
*/
|
|
228
|
-
async function readOutputHTMLFile(permalink, outDir, trailingSlash) {
|
|
229
|
-
const withTrailingSlashPath = path_1.default.join(outDir, permalink, 'index.html');
|
|
230
|
-
const withoutTrailingSlashPath = path_1.default.join(outDir, `${permalink.replace(/\/$/, '')}.html`);
|
|
231
|
-
if (trailingSlash) {
|
|
232
|
-
return fs_extra_1.default.readFile(withTrailingSlashPath);
|
|
233
|
-
}
|
|
234
|
-
else if (trailingSlash === false) {
|
|
235
|
-
return fs_extra_1.default.readFile(withoutTrailingSlashPath);
|
|
236
|
-
}
|
|
237
|
-
const HTMLPath = await findAsyncSequential([withTrailingSlashPath, withoutTrailingSlashPath], fs_extra_1.default.pathExists);
|
|
238
|
-
if (!HTMLPath) {
|
|
239
|
-
throw new Error(`Expected output HTML file to be found at ${withTrailingSlashPath}`);
|
|
240
|
-
}
|
|
241
|
-
return fs_extra_1.default.readFile(HTMLPath);
|
|
242
|
-
}
|
|
243
|
-
exports.readOutputHTMLFile = readOutputHTMLFile;
|
|
244
|
-
async function mapAsyncSequential(array, action) {
|
|
245
|
-
const results = [];
|
|
246
|
-
for (const t of array) {
|
|
247
|
-
const result = await action(t);
|
|
248
|
-
results.push(result);
|
|
249
|
-
}
|
|
250
|
-
return results;
|
|
251
|
-
}
|
|
252
|
-
exports.mapAsyncSequential = mapAsyncSequential;
|
|
253
|
-
async function findAsyncSequential(array, predicate) {
|
|
254
|
-
for (const t of array) {
|
|
255
|
-
if (await predicate(t)) {
|
|
256
|
-
return t;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return undefined;
|
|
260
|
-
}
|
|
261
|
-
exports.findAsyncSequential = findAsyncSequential;
|
|
262
|
-
function reportMessage(message, reportingSeverity) {
|
|
263
|
-
switch (reportingSeverity) {
|
|
264
|
-
case 'ignore':
|
|
265
|
-
break;
|
|
266
|
-
case 'log':
|
|
267
|
-
logger_1.default.info(message);
|
|
268
|
-
break;
|
|
269
|
-
case 'warn':
|
|
270
|
-
logger_1.default.warn(message);
|
|
271
|
-
break;
|
|
272
|
-
case 'error':
|
|
273
|
-
logger_1.default.error(message);
|
|
274
|
-
break;
|
|
275
|
-
case 'throw':
|
|
276
|
-
throw new Error(message);
|
|
277
|
-
default:
|
|
278
|
-
throw new Error(`Unexpected "reportingSeverity" value: ${reportingSeverity}.`);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
exports.reportMessage = reportMessage;
|
|
282
|
-
function mergeTranslations(contents) {
|
|
283
|
-
return contents.reduce((acc, content) => ({ ...acc, ...content }), {});
|
|
284
|
-
}
|
|
285
|
-
exports.mergeTranslations = mergeTranslations;
|
|
286
|
-
// Useful to update all the messages of a translation file
|
|
287
|
-
// Used in tests to simulate translations
|
|
288
|
-
function updateTranslationFileMessages(translationFile, updateMessage) {
|
|
289
|
-
return {
|
|
290
|
-
...translationFile,
|
|
291
|
-
content: lodash_1.default.mapValues(translationFile.content, (translation) => ({
|
|
292
|
-
...translation,
|
|
293
|
-
message: updateMessage(translation.message),
|
|
294
|
-
})),
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
exports.updateTranslationFileMessages = updateTranslationFileMessages;
|
|
298
98
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,yCAiBqB;AAhBnB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA;AACtB,qHAAA,wBAAwB,OAAA;AACxB,mHAAA,sBAAsB,OAAA;AACtB,qHAAA,wBAAwB,OAAA;AACxB,yGAAA,YAAY,OAAA;AACZ,oHAAA,uBAAuB,OAAA;AACvB,0HAAA,6BAA6B,OAAA;AAC7B,uGAAA,UAAU,OAAA;AACV,0GAAA,aAAa,OAAA;AACb,wHAAA,2BAA2B,OAAA;AAC3B,yGAAA,YAAY,OAAA;AACZ,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AAE1B,yCAAyD;AAAjD,qGAAA,QAAQ,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AACpC,uCAIoB;AAHlB,6GAAA,iBAAiB,OAAA;AACjB,+GAAA,mBAAmB,OAAA;AACnB,4GAAA,gBAAgB,OAAA;AAElB,yCAKqB;AAJnB,8GAAA,iBAAiB,OAAA;AACjB,0HAAA,6BAA6B,OAAA;AAC7B,8GAAA,iBAAiB,OAAA;AACjB,yGAAA,YAAY,OAAA;AAEd,qCAMmB;AALjB,uGAAA,YAAY,OAAA;AACZ,uGAAA,YAAY,OAAA;AACZ,6GAAA,kBAAkB,OAAA;AAClB,8GAAA,mBAAmB,OAAA;AACnB,wGAAA,aAAa,OAAA;AAEf,uCAaoB;AAZlB,wGAAA,YAAY,OAAA;AACZ,sGAAA,UAAU,OAAA;AACV,sGAAA,UAAU,OAAA;AACV,sGAAA,UAAU,OAAA;AACV,2GAAA,eAAe,OAAA;AACf,2GAAA,eAAe,OAAA;AACf,2GAAA,eAAe,OAAA;AACf,4GAAA,gBAAgB,OAAA;AAChB,+GAAA,mBAAmB,OAAA;AACnB,0GAAA,cAAc,OAAA;AACd,yGAAA,aAAa,OAAA;AACb,uGAAA,WAAW,OAAA;AAEb,+BAOgB;AAFd,gHAAA,wBAAwB,OAAA;AACxB,wGAAA,gBAAgB,OAAA;AAElB,iDAQyB;AAPvB,uHAAA,sBAAsB,OAAA;AACtB,8GAAA,aAAa,OAAA;AACb,iHAAA,gBAAgB,OAAA;AAChB,0HAAA,yBAAyB,OAAA;AACzB,oHAAA,mBAAmB,OAAA;AACnB,uHAAA,sBAAsB,OAAA;AAGxB,iDAIyB;AADvB,qHAAA,oBAAoB,OAAA;AAEtB,qCAA2E;AAAhC,wGAAA,aAAa,OAAA;AACxD,yCAQqB;AAPnB,0GAAA,aAAa,OAAA;AACb,sGAAA,SAAS,OAAA;AACT,sGAAA,SAAS,OAAA;AACT,sHAAA,yBAAyB,OAAA;AACzB,4GAAA,eAAe,OAAA;AACf,uGAAA,UAAU,OAAA;AACV,qHAAA,wBAAwB,OAAA;AAE1B,yCAA0D;AAAlD,oGAAA,OAAO,OAAA;AAAE,uGAAA,UAAU,OAAA;AAAE,qGAAA,QAAQ,OAAA;AACrC,yCAKqB;AAJnB,mGAAA,MAAM,OAAA;AACN,+GAAA,kBAAkB,OAAA;AAClB,0GAAA,aAAa,OAAA;AACb,0HAAA,6BAA6B,OAAA;AAE/B,+CAAkD;AAA1C,kHAAA,kBAAkB,OAAA;AAC1B,iDAMyB;AALvB,gHAAA,eAAe,OAAA;AACf,gHAAA,eAAe,OAAA;AACf,mHAAA,kBAAkB,OAAA;AAClB,yHAAA,wBAAwB,OAAA;AACxB,wHAAA,uBAAuB,OAAA"}
|
package/lib/jsUtils.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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 { ReportingSeverity } from '@docusaurus/types';
|
|
8
|
+
/** Removes a given string suffix from `str`. */
|
|
9
|
+
export declare function removeSuffix(str: string, suffix: string): string;
|
|
10
|
+
/** Removes a given string prefix from `str`. */
|
|
11
|
+
export declare function removePrefix(str: string, prefix: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* `Array#map` for async operations where order matters.
|
|
14
|
+
* @param array The array to traverse.
|
|
15
|
+
* @param action An async action to be performed on every array item. Will be
|
|
16
|
+
* awaited before working on the next.
|
|
17
|
+
* @returns The list of results returned from every `action(item)`
|
|
18
|
+
*/
|
|
19
|
+
export declare function mapAsyncSequential<T, R>(array: T[], action: (t: T) => Promise<R>): Promise<R[]>;
|
|
20
|
+
/**
|
|
21
|
+
* `Array#find` for async operations where order matters.
|
|
22
|
+
* @param array The array to traverse.
|
|
23
|
+
* @param predicate An async predicate to be called on every array item. Should
|
|
24
|
+
* return a boolean indicating whether the currently element should be returned.
|
|
25
|
+
* @returns The function immediately returns the first item on which `predicate`
|
|
26
|
+
* returns `true`, or `undefined` if none matches the predicate.
|
|
27
|
+
*/
|
|
28
|
+
export declare function findAsyncSequential<T>(array: T[], predicate: (t: T) => Promise<boolean>): Promise<T | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Takes a message and reports it according to the severity that the user wants.
|
|
31
|
+
*
|
|
32
|
+
* - `ignore`: completely no-op
|
|
33
|
+
* - `log`: uses the `INFO` log level
|
|
34
|
+
* - `warn`: uses the `WARN` log level
|
|
35
|
+
* - `error`: uses the `ERROR` log level
|
|
36
|
+
* - `throw`: aborts the process, throws the error.
|
|
37
|
+
*
|
|
38
|
+
* Since the logger doesn't have logging level filters yet, these severities
|
|
39
|
+
* mostly just differ by their colors.
|
|
40
|
+
*
|
|
41
|
+
* @throws In addition to throwing when `reportingSeverity === "throw"`, this
|
|
42
|
+
* function also throws if `reportingSeverity` is not one of the above.
|
|
43
|
+
*/
|
|
44
|
+
export declare function reportMessage(message: string, reportingSeverity: ReportingSeverity): void;
|
|
45
|
+
//# sourceMappingURL=jsUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsUtils.d.ts","sourceRoot":"","sources":["../src/jsUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAGzD,gDAAgD;AAChD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAMhE;AAED,gDAAgD;AAChD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAC3C,KAAK,EAAE,CAAC,EAAE,EACV,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,CAAC,EAAE,CAAC,CAOd;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,KAAK,EAAE,CAAC,EAAE,EACV,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,GACpC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAOxB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,iBAAiB,EAAE,iBAAiB,GACnC,IAAI,CAoBN"}
|
package/lib/jsUtils.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
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.reportMessage = exports.findAsyncSequential = exports.mapAsyncSequential = exports.removePrefix = exports.removeSuffix = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
|
+
/** Removes a given string suffix from `str`. */
|
|
13
|
+
function removeSuffix(str, suffix) {
|
|
14
|
+
if (suffix === '') {
|
|
15
|
+
// str.slice(0, 0) is ""
|
|
16
|
+
return str;
|
|
17
|
+
}
|
|
18
|
+
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
|
|
19
|
+
}
|
|
20
|
+
exports.removeSuffix = removeSuffix;
|
|
21
|
+
/** Removes a given string prefix from `str`. */
|
|
22
|
+
function removePrefix(str, prefix) {
|
|
23
|
+
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
|
|
24
|
+
}
|
|
25
|
+
exports.removePrefix = removePrefix;
|
|
26
|
+
/**
|
|
27
|
+
* `Array#map` for async operations where order matters.
|
|
28
|
+
* @param array The array to traverse.
|
|
29
|
+
* @param action An async action to be performed on every array item. Will be
|
|
30
|
+
* awaited before working on the next.
|
|
31
|
+
* @returns The list of results returned from every `action(item)`
|
|
32
|
+
*/
|
|
33
|
+
async function mapAsyncSequential(array, action) {
|
|
34
|
+
const results = [];
|
|
35
|
+
for (const t of array) {
|
|
36
|
+
const result = await action(t);
|
|
37
|
+
results.push(result);
|
|
38
|
+
}
|
|
39
|
+
return results;
|
|
40
|
+
}
|
|
41
|
+
exports.mapAsyncSequential = mapAsyncSequential;
|
|
42
|
+
/**
|
|
43
|
+
* `Array#find` for async operations where order matters.
|
|
44
|
+
* @param array The array to traverse.
|
|
45
|
+
* @param predicate An async predicate to be called on every array item. Should
|
|
46
|
+
* return a boolean indicating whether the currently element should be returned.
|
|
47
|
+
* @returns The function immediately returns the first item on which `predicate`
|
|
48
|
+
* returns `true`, or `undefined` if none matches the predicate.
|
|
49
|
+
*/
|
|
50
|
+
async function findAsyncSequential(array, predicate) {
|
|
51
|
+
for (const t of array) {
|
|
52
|
+
if (await predicate(t)) {
|
|
53
|
+
return t;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
exports.findAsyncSequential = findAsyncSequential;
|
|
59
|
+
/**
|
|
60
|
+
* Takes a message and reports it according to the severity that the user wants.
|
|
61
|
+
*
|
|
62
|
+
* - `ignore`: completely no-op
|
|
63
|
+
* - `log`: uses the `INFO` log level
|
|
64
|
+
* - `warn`: uses the `WARN` log level
|
|
65
|
+
* - `error`: uses the `ERROR` log level
|
|
66
|
+
* - `throw`: aborts the process, throws the error.
|
|
67
|
+
*
|
|
68
|
+
* Since the logger doesn't have logging level filters yet, these severities
|
|
69
|
+
* mostly just differ by their colors.
|
|
70
|
+
*
|
|
71
|
+
* @throws In addition to throwing when `reportingSeverity === "throw"`, this
|
|
72
|
+
* function also throws if `reportingSeverity` is not one of the above.
|
|
73
|
+
*/
|
|
74
|
+
function reportMessage(message, reportingSeverity) {
|
|
75
|
+
switch (reportingSeverity) {
|
|
76
|
+
case 'ignore':
|
|
77
|
+
break;
|
|
78
|
+
case 'log':
|
|
79
|
+
logger_1.default.info(message);
|
|
80
|
+
break;
|
|
81
|
+
case 'warn':
|
|
82
|
+
logger_1.default.warn(message);
|
|
83
|
+
break;
|
|
84
|
+
case 'error':
|
|
85
|
+
logger_1.default.error(message);
|
|
86
|
+
break;
|
|
87
|
+
case 'throw':
|
|
88
|
+
throw new Error(message);
|
|
89
|
+
default:
|
|
90
|
+
throw new Error(`Unexpected "reportingSeverity" value: ${reportingSeverity}.`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.reportMessage = reportMessage;
|
|
94
|
+
//# sourceMappingURL=jsUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsUtils.js","sourceRoot":"","sources":["../src/jsUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,wEAAwC;AAExC,gDAAgD;AAChD,SAAgB,YAAY,CAAC,GAAW,EAAE,MAAc;IACtD,IAAI,MAAM,KAAK,EAAE,EAAE;QACjB,wBAAwB;QACxB,OAAO,GAAG,CAAC;KACZ;IACD,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACnE,CAAC;AAND,oCAMC;AAED,gDAAgD;AAChD,SAAgB,YAAY,CAAC,GAAW,EAAE,MAAc;IACtD,OAAO,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACjE,CAAC;AAFD,oCAEC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,kBAAkB,CACtC,KAAU,EACV,MAA4B;IAE5B,MAAM,OAAO,GAAQ,EAAE,CAAC;IACxB,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;QACrB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC;QAC/B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;KACtB;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAVD,gDAUC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,mBAAmB,CACvC,KAAU,EACV,SAAqC;IAErC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;QACrB,IAAI,MAAM,SAAS,CAAC,CAAC,CAAC,EAAE;YACtB,OAAO,CAAC,CAAC;SACV;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAVD,kDAUC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,aAAa,CAC3B,OAAe,EACf,iBAAoC;IAEpC,QAAQ,iBAAiB,EAAE;QACzB,KAAK,QAAQ;YACX,MAAM;QACR,KAAK,KAAK;YACR,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrB,MAAM;QACR,KAAK,MAAM;YACT,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrB,MAAM;QACR,KAAK,OAAO;YACV,gBAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACtB,MAAM;QACR,KAAK,OAAO;YACV,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B;YACE,MAAM,IAAI,KAAK,CACb,yCAAyC,iBAAiB,GAAG,CAC9D,CAAC;KACL;AACH,CAAC;AAvBD,sCAuBC"}
|
package/lib/markdownLinks.d.ts
CHANGED
|
@@ -4,25 +4,68 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Content plugins have a base path and a localized path to source content from.
|
|
9
|
+
* We will look into the localized path in priority.
|
|
10
|
+
*/
|
|
7
11
|
export declare type ContentPaths = {
|
|
12
|
+
/**
|
|
13
|
+
* The absolute path to the base content directory, like `"<siteDir>/docs"`.
|
|
14
|
+
*/
|
|
8
15
|
contentPath: string;
|
|
16
|
+
/**
|
|
17
|
+
* The absolute path to the localized content directory, like
|
|
18
|
+
* `"<siteDir>/i18n/zh-Hans/plugin-content-docs"`.
|
|
19
|
+
*/
|
|
9
20
|
contentPathLocalized: string;
|
|
10
21
|
};
|
|
22
|
+
/** Data structure representing each broken Markdown link to be reported. */
|
|
11
23
|
export declare type BrokenMarkdownLink<T extends ContentPaths> = {
|
|
24
|
+
/** Absolute path to the file containing this link. */
|
|
12
25
|
filePath: string;
|
|
26
|
+
/**
|
|
27
|
+
* This is generic because it may contain extra metadata like version name,
|
|
28
|
+
* which the reporter can provide for context.
|
|
29
|
+
*/
|
|
13
30
|
contentPaths: T;
|
|
31
|
+
/**
|
|
32
|
+
* The content of the link, like `"./brokenFile.md"`
|
|
33
|
+
*/
|
|
14
34
|
link: string;
|
|
15
35
|
};
|
|
16
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Takes a Markdown file and replaces relative file references with their URL
|
|
38
|
+
* counterparts, e.g. `[link](./intro.md)` => `[link](/docs/intro)`, preserving
|
|
39
|
+
* everything else.
|
|
40
|
+
*
|
|
41
|
+
* This method uses best effort to find a matching file. The file reference can
|
|
42
|
+
* be relative to the directory of the current file (most likely) or any of the
|
|
43
|
+
* content paths (so `/tutorials/intro.md` can be resolved as
|
|
44
|
+
* `<siteDir>/docs/tutorials/intro.md`). Links that contain the `http(s):` or
|
|
45
|
+
* `@site/` prefix will always be ignored.
|
|
46
|
+
*/
|
|
47
|
+
export declare function replaceMarkdownLinks<T extends ContentPaths>({ siteDir, fileString, filePath, contentPaths, sourceToPermalink, }: {
|
|
48
|
+
/** Absolute path to the site directory, used to resolve aliased paths. */
|
|
17
49
|
siteDir: string;
|
|
50
|
+
/** The Markdown file content to be processed. */
|
|
18
51
|
fileString: string;
|
|
52
|
+
/** Absolute path to the current file containing `fileString`. */
|
|
19
53
|
filePath: string;
|
|
54
|
+
/** The content paths which the file reference may live in. */
|
|
20
55
|
contentPaths: T;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
56
|
+
/**
|
|
57
|
+
* A map from source paths to their URLs. Source paths are `@site` aliased.
|
|
58
|
+
*/
|
|
59
|
+
sourceToPermalink: {
|
|
60
|
+
[aliasedPath: string]: string;
|
|
61
|
+
};
|
|
62
|
+
}): {
|
|
63
|
+
/**
|
|
64
|
+
* The content with all Markdown file references replaced with their URLs.
|
|
65
|
+
* Unresolved links are left as-is.
|
|
66
|
+
*/
|
|
24
67
|
newContent: string;
|
|
68
|
+
/** The list of broken links, */
|
|
25
69
|
brokenMarkdownLinks: BrokenMarkdownLink<T>[];
|
|
26
70
|
};
|
|
27
|
-
export declare function replaceMarkdownLinks<T extends ContentPaths>({ siteDir, fileString, filePath, contentPaths, sourceToPermalink, }: ReplaceMarkdownLinksParams<T>): ReplaceMarkdownLinksReturn<T>;
|
|
28
71
|
//# sourceMappingURL=markdownLinks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownLinks.d.ts","sourceRoot":"","sources":["../src/markdownLinks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"markdownLinks.d.ts","sourceRoot":"","sources":["../src/markdownLinks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;GAGG;AACH,oBAAY,YAAY,GAAG;IACzB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,4EAA4E;AAC5E,oBAAY,kBAAkB,CAAC,CAAC,SAAS,YAAY,IAAI;IACvD,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,YAAY,EAAE,CAAC,CAAC;IAChB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,YAAY,EAAE,EAC3D,OAAO,EACP,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,iBAAiB,GAClB,EAAE;IACD,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,YAAY,EAAE,CAAC,CAAC;IAChB;;OAEG;IACH,iBAAiB,EAAE;QAAC,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC;CACpD,GAAG;IACF;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,mBAAmB,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC;CAC9C,CA6EA"}
|