@jpmorganchase/mosaic-plugins 0.1.0-beta.8 → 0.1.0-beta.81
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 +49 -228
- package/dist/$AliasPlugin.js.map +1 -1
- package/dist/$CodeModPlugin.d.ts +7 -0
- package/dist/$CodeModPlugin.js +18 -118
- package/dist/$CodeModPlugin.js.map +1 -1
- package/dist/$RefPlugin.d.ts +31 -0
- package/dist/$RefPlugin.js +123 -451
- package/dist/$RefPlugin.js.map +1 -1
- package/dist/$TagPlugin.d.ts +28 -0
- package/dist/$TagPlugin.js +51 -234
- package/dist/$TagPlugin.js.map +1 -1
- package/dist/BreadcrumbsPlugin.d.ts +19 -0
- package/dist/BreadcrumbsPlugin.js +87 -112
- 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 +3 -0
- package/dist/FragmentPlugin.js +61 -0
- package/dist/FragmentPlugin.js.map +1 -0
- package/dist/LazyPagePlugin.d.ts +14 -0
- package/dist/LazyPagePlugin.js +50 -254
- package/dist/LazyPagePlugin.js.map +1 -1
- package/dist/PagesWithoutFileExtPlugin.d.ts +9 -0
- package/dist/PagesWithoutFileExtPlugin.js +20 -118
- 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 +39 -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 +129 -168
- package/dist/SharedConfigPlugin.js.map +1 -1
- package/dist/SidebarPlugin.d.ts +45 -0
- package/dist/SidebarPlugin.js +285 -324
- package/dist/SidebarPlugin.js.map +1 -1
- package/dist/SiteMapPlugin.d.ts +9 -0
- package/dist/SiteMapPlugin.js +23 -91
- package/dist/SiteMapPlugin.js.map +1 -1
- package/dist/TableOfContentsPlugin.d.ts +20 -0
- package/dist/TableOfContentsPlugin.js +44 -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/createPageTest.d.ts +1 -0
- package/dist/utils/createPageTest.js +8 -0
- package/dist/utils/createPageTest.js.map +1 -0
- package/dist/utils/mergePageContent.d.ts +16 -0
- package/dist/utils/mergePageContent.js +23 -0
- package/dist/utils/mergePageContent.js.map +1 -0
- package/dist/utils/normaliseRefs.d.ts +1 -0
- package/dist/utils/normaliseRefs.js +56 -275
- package/dist/utils/normaliseRefs.js.map +1 -1
- package/dist/utils/sortSidebarData.d.ts +29 -0
- package/dist/utils/sortSidebarData.js +47 -0
- package/dist/utils/sortSidebarData.js.map +1 -0
- package/package.json +41 -19
- package/CHANGELOG.md +0 -93
- package/dist/LocalFolderSavePlugin.js +0 -165
- package/dist/LocalFolderSavePlugin.js.map +0 -1
- package/dist/NextPrevPagePlugin.js +0 -173
- package/dist/NextPrevPagePlugin.js.map +0 -1
- package/dist/ReadingTimePlugin.mjs +0 -119
- package/dist/ReadingTimePlugin.mjs.map +0 -1
- package/dist/SearchIndexPlugin.mjs +0 -268
- package/dist/SearchIndexPlugin.mjs.map +0 -1
- package/dist/TableOfContentsPlugin.mjs +0 -131
- package/dist/TableOfContentsPlugin.mjs.map +0 -1
- package/dist/__tests__/BreadcrumbsPlugin.test.js +0 -160
- package/dist/__tests__/BreadcrumbsPlugin.test.js.map +0 -1
|
@@ -1,128 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _asyncToGenerator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
import regeneratorRuntime from "regenerator-runtime";
|
|
31
|
-
import { escapeRegExp } from "lodash";
|
|
32
|
-
import path from "path";
|
|
33
|
-
function createPageTest(ignorePages, pageExtensions) {
|
|
34
|
-
var extTest = new RegExp("".concat(pageExtensions.map(escapeRegExp).join("|"), "$"));
|
|
35
|
-
var ignoreTest = new RegExp("".concat(ignorePages.map(escapeRegExp).join("|"), "$"));
|
|
36
|
-
return function(file) {
|
|
37
|
-
return !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith(".");
|
|
38
|
-
};
|
|
39
|
-
}
|
|
1
|
+
import { escapeRegExp } from 'lodash-es';
|
|
2
|
+
import PluginError from './utils/PluginError.js';
|
|
3
|
+
import { createPageTest } from './utils/createPageTest.js';
|
|
40
4
|
/**
|
|
41
5
|
* Plugin that creates aliases without the file extension for every page emitted by the source.
|
|
42
6
|
* This allows pages to be retrieved from the filesystem without specifying `.mdx` (or whatever file extension is specified in `options.stripExt`).
|
|
43
7
|
* The plugin also modifies the `route` to point to the shorter alias. Friendly fullPaths are the shortest possible paths that
|
|
44
8
|
* will point to the page (see `Page` docs)
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
pageTest = new RegExp("".concat(pageExtensions.map(escapeRegExp).join("|"), "$"));
|
|
55
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
56
|
-
_ctx.prev = 3;
|
|
57
|
-
_iterator = pages[Symbol.iterator]();
|
|
58
|
-
case 5:
|
|
59
|
-
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
|
|
60
|
-
_ctx.next = 14;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
page = _step.value;
|
|
64
|
-
if (isNonHiddenPage(page.fullPath)) {
|
|
65
|
-
_ctx.next = 9;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
return _ctx.abrupt("continue", 11);
|
|
69
|
-
case 9:
|
|
70
|
-
page.route = page.route.replace(pageTest, "");
|
|
71
|
-
config.setAliases(page.fullPath, [
|
|
72
|
-
page.route
|
|
73
|
-
]);
|
|
74
|
-
case 11:
|
|
75
|
-
_iteratorNormalCompletion = true;
|
|
76
|
-
_ctx.next = 5;
|
|
77
|
-
break;
|
|
78
|
-
case 14:
|
|
79
|
-
_ctx.next = 20;
|
|
80
|
-
break;
|
|
81
|
-
case 16:
|
|
82
|
-
_ctx.prev = 16;
|
|
83
|
-
_ctx.t0 = _ctx["catch"](3);
|
|
84
|
-
_didIteratorError = true;
|
|
85
|
-
_iteratorError = _ctx.t0;
|
|
86
|
-
case 20:
|
|
87
|
-
_ctx.prev = 20;
|
|
88
|
-
_ctx.prev = 21;
|
|
89
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
90
|
-
_iterator.return();
|
|
91
|
-
}
|
|
92
|
-
case 23:
|
|
93
|
-
_ctx.prev = 23;
|
|
94
|
-
if (!_didIteratorError) {
|
|
95
|
-
_ctx.next = 26;
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
throw _iteratorError;
|
|
99
|
-
case 26:
|
|
100
|
-
return _ctx.finish(23);
|
|
101
|
-
case 27:
|
|
102
|
-
return _ctx.finish(20);
|
|
103
|
-
case 28:
|
|
104
|
-
return _ctx.abrupt("return", pages);
|
|
105
|
-
case 29:
|
|
106
|
-
case "end":
|
|
107
|
-
return _ctx.stop();
|
|
9
|
+
*/
|
|
10
|
+
const PagesWithoutFileExtPlugin = {
|
|
11
|
+
async $afterSource(pages, { config, ignorePages, pageExtensions }) {
|
|
12
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
13
|
+
const pageTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
14
|
+
for (const page of pages) {
|
|
15
|
+
try {
|
|
16
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
17
|
+
continue;
|
|
108
18
|
}
|
|
109
|
-
|
|
110
|
-
[
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
21,
|
|
118
|
-
,
|
|
119
|
-
23,
|
|
120
|
-
27
|
|
121
|
-
]
|
|
122
|
-
]);
|
|
123
|
-
}))();
|
|
19
|
+
page.route = page.route.replace(pageTest, '');
|
|
20
|
+
config.setAliases(page.fullPath, [page.route]);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
throw new PluginError(e.message, page.fullPath);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return pages;
|
|
124
27
|
}
|
|
125
28
|
};
|
|
126
29
|
export default PagesWithoutFileExtPlugin;
|
|
127
|
-
|
|
128
30
|
//# sourceMappingURL=PagesWithoutFileExtPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"PagesWithoutFileExtPlugin.js","sourceRoot":"","sources":["../src/PagesWithoutFileExtPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,WAAW,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D;;;;;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,CA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,CAAC,CAAC,CAAC,GAAG,EAAE;iCACvE;6BACF;yBACF;qBACF,CAAC,CACH,CAAC;oBAEF,MAAM,KAAK,GAAG,CAAC,YAAY,EAAE,GAAG,SAAS,CAAC,CAAC;oBAE3C,uEAAuE;oBACvE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;oBACpB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;gBACxB,CAAC,CACF,CAAC;gBAEF,IAAI,CAAC,OAAO,GAAG,MAAM,EAAE;qBACpB,IAAI,CAAC,UAAU,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,39 @@
|
|
|
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
|
+
function isValid(node) {
|
|
13
|
+
return node.type === 'text' || node.type === 'code';
|
|
14
|
+
}
|
|
15
|
+
const processor = unified().use(markdown);
|
|
16
|
+
/**
|
|
17
|
+
* Calculates reading time of MDX pages and adds to frontmatter
|
|
18
|
+
*/
|
|
19
|
+
const ReadingTimePlugin = {
|
|
20
|
+
async $afterSource(pages, { ignorePages, pageExtensions }) {
|
|
21
|
+
if (pageExtensions.includes('.mdx')) {
|
|
22
|
+
for (const page of pages) {
|
|
23
|
+
const isNonHiddenPage = createPageTest(ignorePages, ['.mdx']);
|
|
24
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const tree = processor.parse(page.content);
|
|
28
|
+
let textContent = '';
|
|
29
|
+
visit(tree, isValid, (node) => {
|
|
30
|
+
textContent += node.value;
|
|
31
|
+
});
|
|
32
|
+
page.readingTime = getReadingTime(textContent);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return pages;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export default ReadingTimePlugin;
|
|
39
|
+
//# sourceMappingURL=ReadingTimePlugin.js.map
|
|
@@ -0,0 +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IAC3D,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,cAAc,EAAE;QACvD,IAAI,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACnC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,MAAM,eAAe,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC9D,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;oBACnC,SAAS;iBACV;gBACD,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAC3C,IAAI,WAAW,GAAG,EAAE,CAAC;gBAErB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,IAAa,EAAE,EAAE;oBACrC,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC;gBAC5B,CAAC,CAAC,CAAC;gBACH,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;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import markdown from 'remark-parse';
|
|
3
|
+
import remarkMdx from 'remark-mdx';
|
|
4
|
+
import { visit } from 'unist-util-visit';
|
|
5
|
+
const defaultRelevancyOptions = {
|
|
6
|
+
includeScore: true,
|
|
7
|
+
includeMatches: true,
|
|
8
|
+
maxPatternLength: 240,
|
|
9
|
+
ignoreLocation: true,
|
|
10
|
+
threshold: 0.3
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* We need these keys to *always* be included in the search index.
|
|
14
|
+
* Without the title, there would be no way to display the search results.
|
|
15
|
+
* Without the route, there would be no way to navigate to the page.
|
|
16
|
+
*/
|
|
17
|
+
const requiredKeys = ['title', 'route'];
|
|
18
|
+
/**
|
|
19
|
+
* If there are no keys specified in the plugin options, we'll use these
|
|
20
|
+
*/
|
|
21
|
+
const fallbackKeys = [...requiredKeys, 'content'];
|
|
22
|
+
/**
|
|
23
|
+
* There are three scenarios for the "keys":
|
|
24
|
+
*
|
|
25
|
+
* 1. No keys are specified in the plugin options. In this case, we'll use the fallback keys.
|
|
26
|
+
* 2. The keys are specified as an array of strings. In this case, we'll add the required keys to the array.
|
|
27
|
+
* 3. The keys are specified as an array of objects. In this case, we can assume "weighting" is being applied
|
|
28
|
+
* so we'll only return the keys that have been specified in the options.
|
|
29
|
+
*
|
|
30
|
+
* @param optionKeys array of keys specified in the plugin options
|
|
31
|
+
* @returns array of keys to be used in the search index
|
|
32
|
+
*/
|
|
33
|
+
export function parseKeys(optionKeys = []) {
|
|
34
|
+
if (optionKeys.length < 1)
|
|
35
|
+
return fallbackKeys;
|
|
36
|
+
if (typeof optionKeys[0] === 'string')
|
|
37
|
+
return [...requiredKeys, ...optionKeys];
|
|
38
|
+
return optionKeys;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Converts raw content string into an array of sentences suitable for inclusion
|
|
42
|
+
* in the search index
|
|
43
|
+
*
|
|
44
|
+
* @param options.content the raw content string
|
|
45
|
+
* @param options.title the title of the page (used for adding context to parse errors)
|
|
46
|
+
* @param options.maxLineLength the maximum length of a sentence (set this to match the
|
|
47
|
+
* "location" option in your Fuse.js configuration). Sentences longer than this value will be
|
|
48
|
+
* truncated.
|
|
49
|
+
* @param options.maxLineCount the maximum number of lines to include in the search index for
|
|
50
|
+
* each page. Pages with more lines than this value will be truncated.
|
|
51
|
+
* @returns array of sentence strings
|
|
52
|
+
*/
|
|
53
|
+
export const optimizeContentForSearch = async ({ content: rawContent, title, maxLineLength, maxLineCount }) => {
|
|
54
|
+
// Normalize line endings
|
|
55
|
+
const content = rawContent.replaceAll('\r', '');
|
|
56
|
+
if (!content || content.length < 1)
|
|
57
|
+
return [content];
|
|
58
|
+
const processor = unified().use(markdown).use(remarkMdx);
|
|
59
|
+
let tree;
|
|
60
|
+
try {
|
|
61
|
+
tree = await processor.parse(content);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
console.error(`Search Index Plugin failed to parse content for ${title}`, err.reason);
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
const sentences = [];
|
|
68
|
+
const segmenter = new Intl.Segmenter('en', { granularity: 'sentence' });
|
|
69
|
+
visit(tree, (node) => node.type === 'text' || node.type === 'code', (node) => {
|
|
70
|
+
const segments = [...segmenter.segment(node.value)].map(segment => segment.segment);
|
|
71
|
+
segments.forEach(segment => {
|
|
72
|
+
if (maxLineLength) {
|
|
73
|
+
sentences.push(segment.slice(0, maxLineLength));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
sentences.push(segment);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
if (maxLineCount) {
|
|
81
|
+
return sentences.slice(0, maxLineCount);
|
|
82
|
+
}
|
|
83
|
+
return sentences;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Creates a search-data.json file that contains all the information
|
|
87
|
+
* from each page that is required to generate a search index.
|
|
88
|
+
*/
|
|
89
|
+
const SearchIndexPlugin = {
|
|
90
|
+
/**
|
|
91
|
+
* For each source, parse the data we want to add to the search index and
|
|
92
|
+
* save it to the global config (to be saved to the filesystem later when
|
|
93
|
+
* all sources have been loaded).
|
|
94
|
+
*/
|
|
95
|
+
async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages }, { maxLineLength, maxLineCount, keys: optionKeys }) {
|
|
96
|
+
const pages = await Promise.all((await mutableFilesystem.promises.glob('**', {
|
|
97
|
+
onlyFiles: true,
|
|
98
|
+
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
99
|
+
cwd: '/'
|
|
100
|
+
})).map(async (pagePath) => {
|
|
101
|
+
const deserialisedPage = await serialiser.deserialise(pagePath, await mutableFilesystem.promises.readFile(pagePath));
|
|
102
|
+
return deserialisedPage;
|
|
103
|
+
}));
|
|
104
|
+
const searchData = await Promise.all(pages.map(async (page) => {
|
|
105
|
+
const content = await optimizeContentForSearch({
|
|
106
|
+
content: page.content || '',
|
|
107
|
+
title: page.title || '',
|
|
108
|
+
maxLineLength,
|
|
109
|
+
maxLineCount
|
|
110
|
+
});
|
|
111
|
+
const keys = parseKeys(optionKeys);
|
|
112
|
+
/**
|
|
113
|
+
* If the "content" key is specified, we want to include the result of
|
|
114
|
+
* the optimizeContentForSearch() function. Otherwise, we include the
|
|
115
|
+
* key value directly from the page data.
|
|
116
|
+
*/
|
|
117
|
+
return keys.reduce((acc, key) => ({ ...acc, [key]: key === 'content' ? content : page[key] }), {});
|
|
118
|
+
}));
|
|
119
|
+
/**
|
|
120
|
+
* Convert the searchData into an object where each page has a unique key (the
|
|
121
|
+
* route) so that the "merge" in `config.setData()` will correctly combine all
|
|
122
|
+
* the results from multiple sources.
|
|
123
|
+
*/
|
|
124
|
+
const searchDataKeyedByRoute = searchData.reduce((acc, curr) => ({
|
|
125
|
+
...acc,
|
|
126
|
+
[curr.route]: curr
|
|
127
|
+
}), {});
|
|
128
|
+
config.setData({
|
|
129
|
+
searchIndices: searchDataKeyedByRoute
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
/**
|
|
133
|
+
* Once we have all the sources' search data added to `globalConfig`, convert it
|
|
134
|
+
* to JSON and save it to the filesystem.
|
|
135
|
+
*/
|
|
136
|
+
async afterUpdate(_, { sharedFilesystem, globalConfig }, { keys: optionKeys, relevancy }) {
|
|
137
|
+
if (!globalConfig.data.searchIndices)
|
|
138
|
+
return;
|
|
139
|
+
const globalSearchIndices = globalConfig.data.searchIndices;
|
|
140
|
+
const searchData = Object.values(globalSearchIndices);
|
|
141
|
+
const condensedSearchData = searchData.map(page => ({ title: page.title, route: page.route }));
|
|
142
|
+
const keys = parseKeys(optionKeys);
|
|
143
|
+
const searchConfig = {
|
|
144
|
+
...defaultRelevancyOptions,
|
|
145
|
+
...relevancy,
|
|
146
|
+
keys
|
|
147
|
+
};
|
|
148
|
+
await sharedFilesystem.promises.writeFile('/search-config.json', JSON.stringify(searchConfig));
|
|
149
|
+
await sharedFilesystem.promises.writeFile('/search-data.json', JSON.stringify(searchData));
|
|
150
|
+
await sharedFilesystem.promises.writeFile('/search-data-condensed.json', JSON.stringify(condensedSearchData));
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
export default SearchIndexPlugin;
|
|
154
|
+
//# sourceMappingURL=SearchIndexPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchIndexPlugin.js","sourceRoot":"","sources":["../src/SearchIndexPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,QAAQ,MAAM,cAAc,CAAC;AACpC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAqCzC,MAAM,uBAAuB,GAAG;IAC9B,YAAY,EAAE,IAAI;IAClB,cAAc,EAAE,IAAI;IACpB,gBAAgB,EAAE,GAAG;IACrB,cAAc,EAAE,IAAI;IACpB,SAAS,EAAE,GAAG;CACf,CAAC;AAEF;;;;GAIG;AACH,MAAM,YAAY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gBAAgB,EAAE,YAAY,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE;QACtF,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa;YAAE,OAAO;QAC7C,MAAM,mBAAmB,GAAG,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC;QAC5D,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACtD,MAAM,mBAAmB,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC/F,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;QACnC,MAAM,YAAY,GAAG;YACnB,GAAG,uBAAuB;YAC1B,GAAG,SAAS;YACZ,IAAI;SACL,CAAC;QACF,MAAM,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;QAC/F,MAAM,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;QAC3F,MAAM,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CACvC,6BAA6B,EAC7B,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACpC,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
export interface SharedConfigPluginPage extends Page {
|
|
3
|
+
sharedConfig?: string;
|
|
4
|
+
frameOverrides?: any;
|
|
5
|
+
}
|
|
6
|
+
export interface SharedConfigPluginOptions {
|
|
7
|
+
filename: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Plugin that crawls the page hierarchy to find the closest `sharedConfig` from any parent index's page metadata.
|
|
11
|
+
* It then exports a JSON file (name: `options.filename`) into each directory with the merged config for that level
|
|
12
|
+
*/
|
|
13
|
+
declare const SharedConfigPlugin: PluginType<SharedConfigPluginPage, SharedConfigPluginOptions>;
|
|
14
|
+
export default SharedConfigPlugin;
|