@jpmorganchase/mosaic-plugins 0.1.0-beta.6 → 0.1.0-beta.60
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/dist/$AliasPlugin.d.ts +10 -0
- package/dist/$AliasPlugin.js +39 -48
- package/dist/$AliasPlugin.js.map +1 -1
- package/dist/$CodeModPlugin.d.ts +7 -0
- package/dist/$CodeModPlugin.js +18 -30
- package/dist/$CodeModPlugin.js.map +1 -1
- package/dist/$RefPlugin.d.ts +31 -0
- package/dist/$RefPlugin.js +131 -127
- package/dist/$RefPlugin.js.map +1 -1
- package/dist/$TagPlugin.d.ts +28 -0
- package/dist/$TagPlugin.js +37 -56
- package/dist/$TagPlugin.js.map +1 -1
- package/dist/BreadcrumbsPlugin.d.ts +19 -0
- package/dist/BreadcrumbsPlugin.js +84 -32
- package/dist/BreadcrumbsPlugin.js.map +1 -1
- package/dist/BrokenLinksPlugin.d.ts +10 -0
- package/dist/BrokenLinksPlugin.js +80 -0
- package/dist/BrokenLinksPlugin.js.map +1 -0
- package/dist/FragmentPlugin.d.ts +7 -0
- package/dist/FragmentPlugin.js +92 -0
- package/dist/FragmentPlugin.js.map +1 -0
- package/dist/LazyPagePlugin.d.ts +14 -0
- package/dist/LazyPagePlugin.js +57 -87
- package/dist/LazyPagePlugin.js.map +1 -1
- package/dist/PagesWithoutFileExtPlugin.d.ts +9 -0
- package/dist/PagesWithoutFileExtPlugin.js +19 -31
- package/dist/PagesWithoutFileExtPlugin.js.map +1 -1
- package/dist/PropsTablePlugin.d.ts +6 -0
- package/dist/PropsTablePlugin.js +88 -0
- package/dist/PropsTablePlugin.js.map +1 -0
- package/dist/PublicAssetsPlugin.d.ts +18 -0
- package/dist/PublicAssetsPlugin.js +28 -0
- package/dist/PublicAssetsPlugin.js.map +1 -0
- package/dist/ReadingTimePlugin.d.ts +10 -0
- package/dist/ReadingTimePlugin.js +36 -0
- package/dist/ReadingTimePlugin.js.map +1 -0
- package/dist/SearchIndexPlugin.d.ts +56 -0
- package/dist/SearchIndexPlugin.js +154 -0
- package/dist/SearchIndexPlugin.js.map +1 -0
- package/dist/SharedConfigPlugin.d.ts +14 -0
- package/dist/SharedConfigPlugin.js +134 -38
- package/dist/SharedConfigPlugin.js.map +1 -1
- package/dist/SidebarPlugin.d.ts +44 -0
- package/dist/SidebarPlugin.js +246 -95
- package/dist/SidebarPlugin.js.map +1 -1
- package/dist/SiteMapPlugin.d.ts +9 -0
- package/dist/SiteMapPlugin.js +20 -36
- package/dist/SiteMapPlugin.js.map +1 -1
- package/dist/TableOfContentsPlugin.d.ts +20 -0
- package/dist/TableOfContentsPlugin.js +43 -0
- package/dist/TableOfContentsPlugin.js.map +1 -0
- package/dist/utils/PluginError.d.ts +7 -0
- package/dist/utils/PluginError.js +13 -0
- package/dist/utils/PluginError.js.map +1 -0
- package/dist/utils/mergePageConent.d.ts +16 -0
- package/dist/utils/mergePageConent.js +23 -0
- package/dist/utils/mergePageConent.js.map +1 -0
- package/dist/utils/normaliseRefs.d.ts +1 -0
- package/dist/utils/normaliseRefs.js +52 -69
- package/dist/utils/normaliseRefs.js.map +1 -1
- package/dist/utils/sortSidebarData.d.ts +19 -0
- package/dist/utils/sortSidebarData.js +35 -0
- package/dist/utils/sortSidebarData.js.map +1 -0
- package/package.json +48 -15
- package/CHANGELOG.md +0 -58
- package/dist/NextPrevPagePlugin.js +0 -63
- package/dist/NextPrevPagePlugin.js.map +0 -1
- package/dist/ReadingTimePlugin.mjs +0 -119
- package/dist/ReadingTimePlugin.mjs.map +0 -1
- package/dist/TableOfContentsPlugin.mjs +0 -140
- package/dist/TableOfContentsPlugin.mjs.map +0 -1
package/dist/LazyPagePlugin.js
CHANGED
|
@@ -1,95 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const fs_1 = __importDefault(require("fs"));
|
|
27
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
28
|
-
const merge_1 = __importDefault(require("lodash/merge"));
|
|
29
|
-
const escapeRegExp_1 = __importDefault(require("lodash/escapeRegExp"));
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import fsExtra from 'fs-extra';
|
|
3
|
+
import { escapeRegExp } from 'lodash-es';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { mergePageContent } from './utils/mergePageConent.js';
|
|
6
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
7
|
+
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
8
|
+
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp).join('|')}$`);
|
|
9
|
+
return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
|
|
10
|
+
}
|
|
11
|
+
function createFileGlob(url, pageExtensions) {
|
|
12
|
+
if (pageExtensions.length === 1) {
|
|
13
|
+
return `${url}${pageExtensions[0]}`;
|
|
14
|
+
}
|
|
15
|
+
return `${url}{${pageExtensions.join(',')}}`;
|
|
16
|
+
}
|
|
31
17
|
const LazyPagePlugin = {
|
|
32
|
-
afterUpdate(mutableFilesystem, { ignorePages, config, pageExtensions, serialiser }) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
18
|
+
async afterUpdate(mutableFilesystem, { ignorePages, config, pageExtensions, serialiser }) {
|
|
19
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
20
|
+
// This adds a hook that triggers every time a non-cached page is read from the filesystem.
|
|
21
|
+
mutableFilesystem.__internal_do_not_use_addReadFileHook(async (pagePath, fileData) => {
|
|
22
|
+
// If this is a 'page' - read the original file from disk and try to inject anything that's missing.
|
|
23
|
+
if (isNonHiddenPage(pagePath)) {
|
|
24
|
+
const currentPage = await serialiser.deserialise(pagePath, fileData);
|
|
25
|
+
if (config.data.hddPaths?.[pagePath]) {
|
|
26
|
+
const page = await serialiser.deserialise(pagePath, await fs.promises.readFile(config.data.hddPaths[pagePath]));
|
|
27
|
+
const mergedPage = mergePageContent(page, currentPage);
|
|
28
|
+
const completePage = await serialiser.serialise(pagePath, mergePageContent(mergedPage, { content: page.content }));
|
|
29
|
+
return completePage;
|
|
45
30
|
}
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
}
|
|
32
|
+
return fileData;
|
|
48
33
|
});
|
|
49
34
|
},
|
|
50
|
-
$beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, options) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
onlyFiles: true
|
|
59
|
-
});
|
|
60
|
-
const baseDir = path_1.default.join(process.cwd(), options.cacheDir || '.mosaic-lazy-page-plugin-cache');
|
|
61
|
-
yield fs_extra_1.default.ensureDir(baseDir);
|
|
62
|
-
for (const filePath of allPages) {
|
|
63
|
-
const rawPage = yield mutableFilesystem.promises.readFile(String(filePath));
|
|
64
|
-
const page = yield serialiser.deserialise(String(filePath), rawPage);
|
|
65
|
-
originalDiskSize += rawPage.length;
|
|
66
|
-
yield fs_1.default.promises.mkdir(path_1.default.dirname(path_1.default.join(baseDir, String(filePath))), {
|
|
67
|
-
recursive: true
|
|
68
|
-
});
|
|
69
|
-
yield fs_1.default.promises.writeFile(path_1.default.join(baseDir, String(filePath)), yield serialiser.serialise(String(filePath), page));
|
|
70
|
-
const { content } = page, pageRest = __rest(page, ["content"]);
|
|
71
|
-
hddPaths[String(filePath)] = path_1.default.join(baseDir, String(filePath));
|
|
72
|
-
const redactedPage = yield serialiser.serialise(String(filePath), pageRest);
|
|
73
|
-
newDiskSize += redactedPage.length;
|
|
74
|
-
}
|
|
75
|
-
config.setData({ hddPaths });
|
|
76
|
-
const reduction = originalDiskSize - newDiskSize;
|
|
77
|
-
console.info(`[PullDocs] LazyPagePlugin moved ${((reduction / originalDiskSize) * 100).toFixed(2)}% of virtual filesystem content to the hard disk. This reduced the virtual filesystem size from ${(originalDiskSize / 1000000).toFixed(2)}mb to ${(newDiskSize / 1000000).toFixed(2)}mb (yay!)`);
|
|
35
|
+
async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, options) {
|
|
36
|
+
const hddPaths = {};
|
|
37
|
+
let originalDiskSize = 0;
|
|
38
|
+
let newDiskSize = 0;
|
|
39
|
+
const allPages = await mutableFilesystem.promises.glob(createFileGlob('**', pageExtensions), {
|
|
40
|
+
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
41
|
+
cwd: '/',
|
|
42
|
+
onlyFiles: true
|
|
78
43
|
});
|
|
44
|
+
const baseDir = path.join(process.cwd(), options.cacheDir || '.mosaic-lazy-page-plugin-cache');
|
|
45
|
+
await fsExtra.ensureDir(baseDir);
|
|
46
|
+
for (const filePath of allPages) {
|
|
47
|
+
const rawPage = await mutableFilesystem.promises.readFile(String(filePath));
|
|
48
|
+
const page = await serialiser.deserialise(String(filePath), rawPage);
|
|
49
|
+
originalDiskSize += rawPage.length;
|
|
50
|
+
await fs.promises.mkdir(path.dirname(path.join(baseDir, String(filePath))), {
|
|
51
|
+
recursive: true
|
|
52
|
+
});
|
|
53
|
+
await fs.promises.writeFile(path.join(baseDir, String(filePath)), await serialiser.serialise(String(filePath), page));
|
|
54
|
+
const { content, ...pageRest } = page;
|
|
55
|
+
hddPaths[String(filePath)] = path.join(baseDir, String(filePath));
|
|
56
|
+
const redactedPage = await serialiser.serialise(String(filePath), pageRest);
|
|
57
|
+
newDiskSize += redactedPage.length;
|
|
58
|
+
}
|
|
59
|
+
config.setData({ hddPaths });
|
|
60
|
+
const reduction = originalDiskSize - newDiskSize;
|
|
61
|
+
console.info(`[Mosaic] LazyPagePlugin moved ${((reduction / originalDiskSize) * 100).toFixed(2)}% of virtual filesystem content to the hard disk. This reduced the virtual filesystem size from ${(originalDiskSize / 1000000).toFixed(2)}mb to ${(newDiskSize / 1000000).toFixed(2)}mb (yay!)`);
|
|
79
62
|
}
|
|
80
63
|
};
|
|
81
|
-
|
|
82
|
-
if (pageExtensions.length === 1) {
|
|
83
|
-
return `${url}${pageExtensions[0]}`;
|
|
84
|
-
}
|
|
85
|
-
return `${url}{${pageExtensions.join(',')}}`;
|
|
86
|
-
}
|
|
87
|
-
exports.default = LazyPagePlugin;
|
|
88
|
-
function createPageTest(ignorePages, pageExtensions) {
|
|
89
|
-
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp_1.default).join('|')}$`);
|
|
90
|
-
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp_1.default).join('|')}$`);
|
|
91
|
-
return file => {
|
|
92
|
-
return !ignoreTest.test(file) && extTest.test(file) && !path_1.default.basename(file).startsWith('.');
|
|
93
|
-
};
|
|
94
|
-
}
|
|
64
|
+
export default LazyPagePlugin;
|
|
95
65
|
//# sourceMappingURL=LazyPagePlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LazyPagePlugin.js","sourceRoot":"","sources":["../src/LazyPagePlugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LazyPagePlugin.js","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Q,CAAC,EAAE,QAAQ,CAAC,CAAC;YAC5E,WAAW,IAAI,YAAY,CAAC,MAAM,CAAC;SACpC;QAED,MAAM,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QAE7B,MAAM,SAAS,GAAG,gBAAgB,GAAG,WAAW,CAAC;QACjD,OAAO,CAAC,IAAI,CACV,iCAAiC,CAAC,CAAC,SAAS,GAAG,gBAAgB,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAC7E,CAAC,CACF,mGAAmG,CAClG,gBAAgB,GAAG,OAAO,CAC3B,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,GAAG,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CACnE,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
/**
|
|
3
|
+
* Plugin that creates aliases without the file extension for every page emitted by the source.
|
|
4
|
+
* This allows pages to be retrieved from the filesystem without specifying `.mdx` (or whatever file extension is specified in `options.stripExt`).
|
|
5
|
+
* The plugin also modifies the `route` to point to the shorter alias. Friendly fullPaths are the shortest possible paths that
|
|
6
|
+
* will point to the page (see `Page` docs)
|
|
7
|
+
*/
|
|
8
|
+
declare const PagesWithoutFileExtPlugin: PluginType;
|
|
9
|
+
export default PagesWithoutFileExtPlugin;
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const lodash_1 = require("lodash");
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
1
|
+
import { escapeRegExp } from 'lodash-es';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import PluginError from './utils/PluginError.js';
|
|
4
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
5
|
+
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
6
|
+
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp).join('|')}$`);
|
|
7
|
+
return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
|
|
8
|
+
}
|
|
17
9
|
/**
|
|
18
10
|
* Plugin that creates aliases without the file extension for every page emitted by the source.
|
|
19
11
|
* This allows pages to be retrieved from the filesystem without specifying `.mdx` (or whatever file extension is specified in `options.stripExt`).
|
|
@@ -21,27 +13,23 @@ const path_1 = __importDefault(require("path"));
|
|
|
21
13
|
* will point to the page (see `Page` docs)
|
|
22
14
|
*/
|
|
23
15
|
const PagesWithoutFileExtPlugin = {
|
|
24
|
-
$afterSource(pages, { config, ignorePages, pageExtensions }) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
async $afterSource(pages, { config, ignorePages, pageExtensions }) {
|
|
17
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
18
|
+
const pageTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
19
|
+
for (const page of pages) {
|
|
20
|
+
try {
|
|
29
21
|
if (!isNonHiddenPage(page.fullPath)) {
|
|
30
22
|
continue;
|
|
31
23
|
}
|
|
32
24
|
page.route = page.route.replace(pageTest, '');
|
|
33
25
|
config.setAliases(page.fullPath, [page.route]);
|
|
34
26
|
}
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
catch (e) {
|
|
28
|
+
throw new PluginError(e.message, page.fullPath);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return pages;
|
|
37
32
|
}
|
|
38
33
|
};
|
|
39
|
-
|
|
40
|
-
function createPageTest(ignorePages, pageExtensions) {
|
|
41
|
-
const extTest = new RegExp(`${pageExtensions.map(lodash_1.escapeRegExp).join('|')}$`);
|
|
42
|
-
const ignoreTest = new RegExp(`${ignorePages.map(lodash_1.escapeRegExp).join('|')}$`);
|
|
43
|
-
return file => {
|
|
44
|
-
return !ignoreTest.test(file) && extTest.test(file) && !path_1.default.basename(file).startsWith('.');
|
|
45
|
-
};
|
|
46
|
-
}
|
|
34
|
+
export default PagesWithoutFileExtPlugin;
|
|
47
35
|
//# sourceMappingURL=PagesWithoutFileExtPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PagesWithoutFileExtPlugin.js","sourceRoot":"","sources":["../src/PagesWithoutFileExtPlugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PagesWithoutFileExtPlugin.js","sourceRoot":"","sources":["../src/PagesWithoutFileExtPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,WAAW,MAAM,wBAAwB,CAAC;AAEjD,SAAS,cAAc,CAAC,WAAW,EAAE,cAAc;IACjD,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7E,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC,EAAE,CACZ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACzF,CAAC;AAED;;;;;GAKG;AACH,MAAM,yBAAyB,GAAe;IAC5C,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE;QAC/D,MAAM,eAAe,GAAG,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QACpE,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAE9E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,IAAI;gBACF,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;oBACnC,SAAS;iBACV;gBACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBAC9C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;aAChD;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;aACjD;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import remarkDirective from 'remark-directive';
|
|
2
|
+
import remarkGfm from 'remark-gfm';
|
|
3
|
+
import { remark } from 'remark';
|
|
4
|
+
import remarkMdx from 'remark-mdx';
|
|
5
|
+
import { visit } from 'unist-util-visit';
|
|
6
|
+
import { parse } from 'react-docgen-typescript';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import PluginError from './utils/PluginError.js';
|
|
9
|
+
const options = {
|
|
10
|
+
propFilter: prop => !/@types[\\/]react[\\/]/.test(prop.parent?.fileName || '')
|
|
11
|
+
};
|
|
12
|
+
const PropsTablePlugin = {
|
|
13
|
+
// TODO: add support for active mode
|
|
14
|
+
async $afterSource(pages) {
|
|
15
|
+
const processor = remark().use(remarkMdx).use(remarkDirective).use(remarkGfm);
|
|
16
|
+
for (const page of pages) {
|
|
17
|
+
try {
|
|
18
|
+
const tree = await processor.parse(page.content);
|
|
19
|
+
visit(tree, (node) => node.type === 'textDirective', (node) => {
|
|
20
|
+
if (node.name !== 'propsTable')
|
|
21
|
+
return;
|
|
22
|
+
const componentPath = path.resolve(node.attributes.src);
|
|
23
|
+
const propsTableData = parse(componentPath, options)[0]?.props;
|
|
24
|
+
const tableHeaders = {
|
|
25
|
+
type: 'tableRow',
|
|
26
|
+
children: [
|
|
27
|
+
{
|
|
28
|
+
type: 'tableCell',
|
|
29
|
+
children: [{ type: 'text', value: 'Name' }]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: 'tableCell',
|
|
33
|
+
children: [{ type: 'text', value: 'Type' }]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: 'tableCell',
|
|
37
|
+
children: [{ type: 'text', value: 'Description' }]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: 'tableCell',
|
|
41
|
+
children: [{ type: 'text', value: 'Default' }]
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
};
|
|
45
|
+
const tableBody = Object.values(propsTableData).map(({ name, type, description, defaultValue }) => ({
|
|
46
|
+
type: 'tableRow',
|
|
47
|
+
children: [
|
|
48
|
+
{
|
|
49
|
+
type: 'tableCell',
|
|
50
|
+
children: [{ type: 'text', value: name }]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'tableCell',
|
|
54
|
+
children: [{ type: 'inlineCode', value: type.name }]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: 'tableCell',
|
|
58
|
+
children: [{ type: 'html', value: description.replace(/\n/g, ' ') }]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: 'tableCell',
|
|
62
|
+
children: [
|
|
63
|
+
{ type: 'inlineCode', value: defaultValue ? defaultValue.value : '-' }
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}));
|
|
68
|
+
const table = [tableHeaders, ...tableBody];
|
|
69
|
+
// Replaces the current node with a new table node containing the props
|
|
70
|
+
node.type = 'table';
|
|
71
|
+
node.children = table;
|
|
72
|
+
});
|
|
73
|
+
page.content = remark()
|
|
74
|
+
.data('settings', { fences: true })
|
|
75
|
+
.use(remarkMdx)
|
|
76
|
+
.use(remarkDirective)
|
|
77
|
+
.use(remarkGfm)
|
|
78
|
+
.stringify(tree);
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
throw new PluginError(e.message, page.fullPath);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return pages;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
export default PropsTablePlugin;
|
|
88
|
+
//# sourceMappingURL=PropsTablePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PropsTablePlugin.js","sourceRoot":"","sources":["../src/PropsTablePlugin.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,WAAW,MAAM,wBAAwB,CAAC;AAEjD,MAAM,OAAO,GAAG;IACd,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,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AAU,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;qBAClC,GAAG,CAAC,SAAS,CAAC;qBACd,GAAG,CAAC,eAAe,CAAC;qBACpB,GAAG,CAAC,SAAS,CAAC;qBACd,SAAS,CAAC,IAAI,CAAC,CAAC;aACpB;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;aACjD;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
interface PublicAssetsPluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The directory to copy the assets to
|
|
5
|
+
* @default './public'
|
|
6
|
+
*/
|
|
7
|
+
outputDir?: string;
|
|
8
|
+
/**
|
|
9
|
+
* A collection of filenames to copy to the outputDir
|
|
10
|
+
*/
|
|
11
|
+
assets?: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Plugin that finds `assets` in the Mosaic filesytem and copies them to the specified outputDir.
|
|
15
|
+
* Typical use case is for assets like a sitemap
|
|
16
|
+
*/
|
|
17
|
+
declare const PublicAssetsPlugin: PluginType<Page, PublicAssetsPluginOptions>;
|
|
18
|
+
export default PublicAssetsPlugin;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import fsExtra from 'fs-extra';
|
|
4
|
+
/**
|
|
5
|
+
* Plugin that finds `assets` in the Mosaic filesytem and copies them to the specified outputDir.
|
|
6
|
+
* Typical use case is for assets like a sitemap
|
|
7
|
+
*/
|
|
8
|
+
const PublicAssetsPlugin = {
|
|
9
|
+
async afterUpdate(_, { sharedFilesystem }, { assets = [], outputDir = './public' }) {
|
|
10
|
+
if (assets.length > 0) {
|
|
11
|
+
await fsExtra.ensureDir(outputDir);
|
|
12
|
+
await Promise.all(assets.map(async (asset) => {
|
|
13
|
+
const allFiles = await sharedFilesystem.promises.glob(`**/${asset}`, {
|
|
14
|
+
cwd: '/',
|
|
15
|
+
onlyFiles: true
|
|
16
|
+
});
|
|
17
|
+
if (allFiles?.length > 0) {
|
|
18
|
+
await Promise.all(allFiles.map(async (file) => {
|
|
19
|
+
const data = await sharedFilesystem.promises.readFile(file);
|
|
20
|
+
await fs.promises.writeFile(path.posix.join(path.posix.resolve(outputDir), file), data);
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export default PublicAssetsPlugin;
|
|
28
|
+
//# sourceMappingURL=PublicAssetsPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PublicAssetsPlugin.js","sourceRoot":"","sources":["../src/PublicAssetsPlugin.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,OAAO,MAAM,UAAU,CAAC;AAc/B;;;GAGG;AACH,MAAM,kBAAkB,GAAgD;IACtE,KAAK,CAAC,WAAW,CAAC,CAAC,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE,SAAS,GAAG,UAAU,EAAE;QAChF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YACrB,MAAM,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YAEnC,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,GAAG,CAAC,KAAK,EAAC,KAAK,EAAC,EAAE;gBACvB,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,KAAK,EAAE,EAAE;oBACnE,GAAG,EAAE,GAAG;oBACR,SAAS,EAAE,IAAI;iBAChB,CAAC,CAAC;gBAEH,IAAI,QAAQ,EAAE,MAAM,GAAG,CAAC,EAAE;oBACxB,MAAM,OAAO,CAAC,GAAG,CACf,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAC,IAAI,EAAC,EAAE;wBACxB,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;wBAC5D,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CACzB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,EACpD,IAAI,CACL,CAAC;oBACJ,CAAC,CAAC,CACH,CAAC;iBACH;YACH,CAAC,CAAC,CACH,CAAC;SACH;IACH,CAAC;CACF,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
import getReadingTime from 'reading-time';
|
|
3
|
+
export interface ReadingTimePluginPage extends Page {
|
|
4
|
+
readingTime?: ReturnType<typeof getReadingTime>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Calculates reading time of MDX pages and adds to frontmatter
|
|
8
|
+
*/
|
|
9
|
+
declare const ReadingTimePlugin: PluginType<ReadingTimePluginPage>;
|
|
10
|
+
export default ReadingTimePlugin;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { escapeRegExp } from 'lodash-es';
|
|
3
|
+
import getReadingTime from 'reading-time';
|
|
4
|
+
import markdown from 'remark-parse';
|
|
5
|
+
import { unified } from 'unified';
|
|
6
|
+
import { visit } from 'unist-util-visit';
|
|
7
|
+
const createPageTest = (ignorePages, pageExtensions) => {
|
|
8
|
+
const extTest = new RegExp(`${pageExtensions.map(ext => escapeRegExp(ext)).join('|')}$`);
|
|
9
|
+
const ignoreTest = new RegExp(`${ignorePages.map(ignore => escapeRegExp(ignore)).join('|')}$`);
|
|
10
|
+
return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Calculates reading time of MDX pages and adds to frontmatter
|
|
14
|
+
*/
|
|
15
|
+
const ReadingTimePlugin = {
|
|
16
|
+
async $afterSource(pages, { ignorePages, pageExtensions }) {
|
|
17
|
+
const processor = unified().use(markdown);
|
|
18
|
+
if (pageExtensions.includes('.mdx')) {
|
|
19
|
+
for (const page of pages) {
|
|
20
|
+
const isNonHiddenPage = createPageTest(ignorePages, ['.mdx']);
|
|
21
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const tree = await processor.parse(page.content);
|
|
25
|
+
let textContent = '';
|
|
26
|
+
visit(tree, node => node.type === 'text' || node.type === 'code', (node) => {
|
|
27
|
+
textContent += node.value;
|
|
28
|
+
});
|
|
29
|
+
page.readingTime = getReadingTime(textContent);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return pages;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export default ReadingTimePlugin;
|
|
36
|
+
//# sourceMappingURL=ReadingTimePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReadingTimePlugin.js","sourceRoot":"","sources":["../src/ReadingTimePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,cAAc,MAAM,cAAc,CAAC;AAC1C,OAAO,QAAQ,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGzC,MAAM,cAAc,GAAG,CAA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AI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EACpD,CAAC,IAAc,EAAE,EAAE;oBACjB,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC;gBAC5B,CAAC,CACF,CAAC;gBACF,IAAI,CAAC,WAAW,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;aAChD;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
interface SearchRelevancy {
|
|
3
|
+
includeScore?: boolean;
|
|
4
|
+
includeMatches?: boolean;
|
|
5
|
+
maxPatternLength?: number;
|
|
6
|
+
ignoreLocation?: boolean;
|
|
7
|
+
threshold?: number;
|
|
8
|
+
keys?: string[] | {
|
|
9
|
+
name: string;
|
|
10
|
+
weight: number;
|
|
11
|
+
}[];
|
|
12
|
+
}
|
|
13
|
+
interface SearchIndexPluginOptions {
|
|
14
|
+
maxLineLength?: number;
|
|
15
|
+
maxLineCount?: number;
|
|
16
|
+
keys?: string[];
|
|
17
|
+
relevancy?: SearchRelevancy;
|
|
18
|
+
}
|
|
19
|
+
interface Optimization {
|
|
20
|
+
content: string;
|
|
21
|
+
title: string;
|
|
22
|
+
maxLineCount?: number;
|
|
23
|
+
maxLineLength?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* There are three scenarios for the "keys":
|
|
27
|
+
*
|
|
28
|
+
* 1. No keys are specified in the plugin options. In this case, we'll use the fallback keys.
|
|
29
|
+
* 2. The keys are specified as an array of strings. In this case, we'll add the required keys to the array.
|
|
30
|
+
* 3. The keys are specified as an array of objects. In this case, we can assume "weighting" is being applied
|
|
31
|
+
* so we'll only return the keys that have been specified in the options.
|
|
32
|
+
*
|
|
33
|
+
* @param optionKeys array of keys specified in the plugin options
|
|
34
|
+
* @returns array of keys to be used in the search index
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseKeys(optionKeys?: any[]): any[];
|
|
37
|
+
/**
|
|
38
|
+
* Converts raw content string into an array of sentences suitable for inclusion
|
|
39
|
+
* in the search index
|
|
40
|
+
*
|
|
41
|
+
* @param options.content the raw content string
|
|
42
|
+
* @param options.title the title of the page (used for adding context to parse errors)
|
|
43
|
+
* @param options.maxLineLength the maximum length of a sentence (set this to match the
|
|
44
|
+
* "location" option in your Fuse.js configuration). Sentences longer than this value will be
|
|
45
|
+
* truncated.
|
|
46
|
+
* @param options.maxLineCount the maximum number of lines to include in the search index for
|
|
47
|
+
* each page. Pages with more lines than this value will be truncated.
|
|
48
|
+
* @returns array of sentence strings
|
|
49
|
+
*/
|
|
50
|
+
export declare const optimizeContentForSearch: ({ content: rawContent, title, maxLineLength, maxLineCount }: Optimization) => Promise<string[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a search-data.json file that contains all the information
|
|
53
|
+
* from each page that is required to generate a search index.
|
|
54
|
+
*/
|
|
55
|
+
declare const SearchIndexPlugin: PluginType<Page, SearchIndexPluginOptions>;
|
|
56
|
+
export default SearchIndexPlugin;
|