@jpmorganchase/mosaic-plugins 0.1.0-beta.5 → 0.1.0-beta.51
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 +130 -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 +72 -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 +55 -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 +23 -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 +38 -0
- package/dist/SidebarPlugin.js +196 -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/normaliseRefs.d.ts +1 -0
- package/dist/utils/normaliseRefs.js +52 -69
- package/dist/utils/normaliseRefs.js.map +1 -1
- package/package.json +46 -15
- package/CHANGELOG.md +0 -50
- 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/$TagPlugin.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { escapeRegExp, reduce } from 'lodash-es';
|
|
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
|
+
}
|
|
9
|
+
const findKeys = (obj, targetProp, pathParts = []) => reduce(obj, (found, value, key) => {
|
|
10
|
+
if (key === targetProp) {
|
|
11
|
+
return found.concat({ $$path: pathParts.concat(String(key)), $$value: value });
|
|
12
|
+
}
|
|
13
|
+
if (typeof value === 'object') {
|
|
14
|
+
const foundParents = findKeys(value, targetProp, pathParts.concat(String(key)));
|
|
15
|
+
return found.concat(...foundParents);
|
|
16
|
+
}
|
|
17
|
+
return found;
|
|
18
|
+
}, []);
|
|
18
19
|
/**
|
|
19
20
|
* Plugin that scrapes `$tag` from page metadata and also applies all aliases stored in `config.data.tags`.
|
|
20
21
|
* Tags ultimately resolve down into refs, but are different from normal refs, in that they are applied to the
|
|
@@ -25,29 +26,25 @@ const reduce_1 = __importDefault(require("lodash/reduce"));
|
|
|
25
26
|
const $TagPlugin = {
|
|
26
27
|
// Check if the updated source has any /.tag aliases that we care about - if it does, we should re-run `afterUpdate` to
|
|
27
28
|
// make sure we pull in the latest pages
|
|
28
|
-
shouldClearCache(updatedSourceFilesystem, { config }) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// Does the updated source have tags we are interested in?
|
|
36
|
-
return (yield updatedSourceFilesystem.promises.readdir('/.tags')).some(tag => config.data.subscribedTags.includes(tag));
|
|
37
|
-
});
|
|
29
|
+
async shouldClearCache(updatedSourceFilesystem, { config }) {
|
|
30
|
+
if (!config.data?.subscribedTags ||
|
|
31
|
+
!(await updatedSourceFilesystem.promises.exists('/.tags'))) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
// Does the updated source have tags we are interested in?
|
|
35
|
+
return (await updatedSourceFilesystem.promises.readdir('/.tags')).some(tag => config.data.subscribedTags.includes(tag));
|
|
38
36
|
},
|
|
39
37
|
// Every source with tags will create symlinks with the tagged pages, inside /.tags
|
|
40
|
-
$afterSource(pages, { config, ignorePages, pageExtensions }) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
for (const page of pages) {
|
|
38
|
+
async $afterSource(pages, { config, ignorePages, pageExtensions }) {
|
|
39
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
40
|
+
for (const page of pages) {
|
|
41
|
+
try {
|
|
45
42
|
if (!isNonHiddenPage(page.fullPath)) {
|
|
46
43
|
continue;
|
|
47
44
|
}
|
|
48
45
|
const meta = page;
|
|
49
46
|
// Symlink every `tag` item to '/.tags' folder
|
|
50
|
-
if (
|
|
47
|
+
if (meta.tags?.length) {
|
|
51
48
|
config.setTags(page.fullPath, meta.tags);
|
|
52
49
|
delete meta.tags;
|
|
53
50
|
}
|
|
@@ -58,33 +55,17 @@ const $TagPlugin = {
|
|
|
58
55
|
foundTags.forEach(ref => {
|
|
59
56
|
const [tag, fragment = ''] = ref.$$value.split('#');
|
|
60
57
|
tags.add(tag);
|
|
61
|
-
config.setGlobalRef(page.fullPath, ref.$$path, `${
|
|
58
|
+
config.setGlobalRef(page.fullPath, ref.$$path, `${path.posix.join('/.tags', tag, '**')}#${fragment}`);
|
|
62
59
|
});
|
|
63
60
|
config.setData({ subscribedTags: Array.from(tags) });
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
};
|
|
70
|
-
exports.default = $TagPlugin;
|
|
71
|
-
const findKeys = (obj, targetProp, pathParts = []) => {
|
|
72
|
-
return (0, reduce_1.default)(obj, (found, value, key) => {
|
|
73
|
-
if (key === targetProp) {
|
|
74
|
-
return found.concat({ $$path: pathParts.concat(String(key)), $$value: value });
|
|
75
|
-
}
|
|
76
|
-
if (typeof value === 'object') {
|
|
77
|
-
const foundParents = findKeys(value, targetProp, pathParts.concat(String(key)));
|
|
78
|
-
return found.concat(...foundParents);
|
|
63
|
+
catch (e) {
|
|
64
|
+
throw new PluginError(e.message, page.fullPath);
|
|
65
|
+
}
|
|
79
66
|
}
|
|
80
|
-
return
|
|
81
|
-
}
|
|
67
|
+
return pages;
|
|
68
|
+
}
|
|
82
69
|
};
|
|
83
|
-
|
|
84
|
-
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp_1.default).join('|')}$`);
|
|
85
|
-
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp_1.default).join('|')}$`);
|
|
86
|
-
return file => {
|
|
87
|
-
return !ignoreTest.test(file) && extTest.test(file) && !path_1.default.basename(file).startsWith('.');
|
|
88
|
-
};
|
|
89
|
-
}
|
|
70
|
+
export default $TagPlugin;
|
|
90
71
|
//# sourceMappingURL=$TagPlugin.js.map
|
package/dist/$TagPlugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"$TagPlugin.js","sourceRoot":"","sources":["../src/$TagPlugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"$TagPlugin.js","sourceRoot":"","sources":["../src/$TagPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEjD,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,CA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EAAE,IAAI,CAAC,IAAI,QAAQ,EAAE,CACtD,CAAC;oBACJ,CAAC,CAAC,CAAC;oBACH,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;iBACtD;aACF;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,UAAU,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
import { SidebarPluginPage } from './SidebarPlugin.js';
|
|
3
|
+
export declare type Breadcrumb = {
|
|
4
|
+
label: string;
|
|
5
|
+
path: string;
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
export interface BreadcrumbsPluginPage extends SidebarPluginPage {
|
|
9
|
+
breadcrumbs?: Array<Breadcrumb>;
|
|
10
|
+
layout?: string;
|
|
11
|
+
}
|
|
12
|
+
interface BreadcrumbsPluginOptions {
|
|
13
|
+
indexPageName: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Calculates breadcrumbs for pages then embeds a `breadcrumbs` property to the metadata
|
|
17
|
+
*/
|
|
18
|
+
declare const BreadcrumbsPlugin: PluginType<BreadcrumbsPluginPage, BreadcrumbsPluginOptions>;
|
|
19
|
+
export default BreadcrumbsPlugin;
|
|
@@ -1,48 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { escapeRegExp } from 'lodash-es';
|
|
3
|
+
import PluginError from './utils/PluginError.js';
|
|
4
|
+
const createPageTest = (ignorePages, pageExtensions) => {
|
|
5
|
+
const extTest = new RegExp(`${pageExtensions.map(ext => escapeRegExp(ext)).join('|')}$`);
|
|
6
|
+
const ignoreTest = new RegExp(`${ignorePages.map(ignore => escapeRegExp(ignore)).join('|')}$`);
|
|
7
|
+
return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
|
|
10
8
|
};
|
|
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 path_1 = __importDefault(require("path"));
|
|
16
9
|
/**
|
|
17
10
|
* Calculates breadcrumbs for pages then embeds a `breadcrumbs` property to the metadata
|
|
18
11
|
*/
|
|
19
12
|
const BreadcrumbsPlugin = {
|
|
20
|
-
$afterSource(pages, {}, options) {
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
async $afterSource(pages, { ignorePages, pageExtensions }, options) {
|
|
14
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
15
|
+
for (const page of pages) {
|
|
16
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
23
20
|
const breadcrumbs = [];
|
|
24
21
|
let currentPage = page;
|
|
25
|
-
let parentDir =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
let parentDir = path.posix.normalize(path.posix.dirname(currentPage.fullPath));
|
|
23
|
+
const maxBreadcrumbCount = page.fullPath.split('/').length;
|
|
24
|
+
while (currentPage !== undefined && breadcrumbs.length < maxBreadcrumbCount) {
|
|
25
|
+
breadcrumbs.unshift({
|
|
26
|
+
label: currentPage.sidebar?.label || currentPage.title,
|
|
27
|
+
path: currentPage.route,
|
|
28
|
+
id: currentPage.fullPath
|
|
29
|
+
});
|
|
30
|
+
currentPage = pages.find(
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
32
|
+
item => item.fullPath === path.posix.join(parentDir, options.indexPageName));
|
|
35
33
|
if (currentPage) {
|
|
36
|
-
parentDir =
|
|
34
|
+
parentDir = path.posix.dirname(path.posix.join(String(currentPage.fullPath), '..'));
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
if (!page.breadcrumbs) {
|
|
40
|
-
|
|
38
|
+
// filter out any duplicate breadcrumbs
|
|
39
|
+
const map = new Map(breadcrumbs.map(crumb => [crumb.id, crumb]));
|
|
40
|
+
page.breadcrumbs = [...map.values()];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
throw new PluginError(e.message, page.fullPath);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return pages;
|
|
48
|
+
},
|
|
49
|
+
async afterUpdate(mutableFilesystem, { serialiser, globalFilesystem, ignorePages }, options) {
|
|
50
|
+
const pages = (await mutableFilesystem.promises.glob('**', {
|
|
51
|
+
onlyFiles: true,
|
|
52
|
+
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
53
|
+
cwd: '/'
|
|
54
|
+
}));
|
|
55
|
+
if (pages.length > 0) {
|
|
56
|
+
let updatedBreadcrumbs = [];
|
|
57
|
+
const { breadcrumbs } = await serialiser.deserialise(pages[0], await mutableFilesystem.promises.readFile(pages[0]));
|
|
58
|
+
// the root breadcrumb is the first breadcrumb for all pages in a source. It is essentially the "first" page in a source
|
|
59
|
+
const rootBreadcrumb = breadcrumbs?.[0] || undefined;
|
|
60
|
+
if (rootBreadcrumb) {
|
|
61
|
+
let parentDir = path.posix.join(path.posix.dirname(rootBreadcrumb.id), '../');
|
|
62
|
+
while (parentDir !== '/') {
|
|
63
|
+
const parentDirIndex = path.posix.join(parentDir, options.indexPageName);
|
|
64
|
+
// check for this file in the global fs so we have a holistic view of all site pages
|
|
65
|
+
if (await globalFilesystem.promises.exists(parentDirIndex)) {
|
|
66
|
+
const { breadcrumbs: parentDirBreadcrumbs } = await serialiser.deserialise(rootBreadcrumb.id, await globalFilesystem.promises.readFile(parentDirIndex));
|
|
67
|
+
updatedBreadcrumbs = parentDirBreadcrumbs;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
parentDir = path.posix.join(path.posix.dirname(parentDirIndex), '../');
|
|
71
|
+
}
|
|
72
|
+
if (updatedBreadcrumbs.length > 0) {
|
|
73
|
+
for (const pagePath of pages) {
|
|
74
|
+
const page = await serialiser.deserialise(pagePath, await mutableFilesystem.promises.readFile(pagePath));
|
|
75
|
+
// append the parent breadcrumbs **before** the current breadcrumbs
|
|
76
|
+
page.breadcrumbs = [...updatedBreadcrumbs, ...page.breadcrumbs];
|
|
77
|
+
await mutableFilesystem.promises.writeFile(pagePath, await serialiser.serialise(pagePath, page));
|
|
78
|
+
}
|
|
41
79
|
}
|
|
42
80
|
}
|
|
43
|
-
|
|
44
|
-
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
async shouldUpdateNamespaceSources() {
|
|
84
|
+
return true;
|
|
45
85
|
}
|
|
46
86
|
};
|
|
47
|
-
|
|
87
|
+
export default BreadcrumbsPlugin;
|
|
48
88
|
//# sourceMappingURL=BreadcrumbsPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BreadcrumbsPlugin.js","sourceRoot":"","sources":["../src/BreadcrumbsPlugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BreadcrumbsPlugin.js","sourceRoot":"","sources":["../src/BreadcrumbsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,WAAW,MAAM,wBAAwB,CAAC;AAGjD,MAAM,cAAc,GAAG,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,MAAM;qBACP;oBACD,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,KAAK,CAAC,CAAC;iBACxE;gBAED,IAAI,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE;oBACjC,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE;wBAC5B,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,WAAW,CACvC,QAAQ,EACR,MAAM,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACpD,CAAC;wBAEF,mEAAmE;wBACnE,IAAI,CAAC,WAAW,GAAG,CAAC,GAAG,kBAAkB,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;wBAChE,MAAM,iBAAiB,CAAC,QAAQ,CAAC,SAAS,CACxC,QAAQ,EACR,MAAM,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAC3C,CAAC;qBACH;iBACF;aACF;SACF;IACH,CAAC;IACD,KAAK,CAAC,4BAA4B;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
interface BrokenLinksPluginPage extends Page {
|
|
3
|
+
}
|
|
4
|
+
interface BrokenLinksPluginOptions {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
skipUrlPatterns?: Array<string | RegExp>;
|
|
7
|
+
proxyEndpoint?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const BrokenLinksPlugin: PluginType<BrokenLinksPluginPage, BrokenLinksPluginOptions>;
|
|
10
|
+
export default BrokenLinksPlugin;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { remark } from 'remark';
|
|
3
|
+
import remarkMdx from 'remark-mdx';
|
|
4
|
+
import checkLinks from 'check-links';
|
|
5
|
+
import { visit } from 'unist-util-visit';
|
|
6
|
+
import proxyAgentPkg from 'https-proxy-agent';
|
|
7
|
+
const { HttpsProxyAgent } = proxyAgentPkg;
|
|
8
|
+
async function checkPageLinks(ast, options, fullPath, headings) {
|
|
9
|
+
const urlToNodes = {};
|
|
10
|
+
const aggregate = node => {
|
|
11
|
+
const { url: urlFromNode } = node;
|
|
12
|
+
if (!urlFromNode)
|
|
13
|
+
return;
|
|
14
|
+
const isExternalUrl = /^(https?:\/\/)/.test(urlFromNode);
|
|
15
|
+
const url = isExternalUrl
|
|
16
|
+
? // full urls including internal and external
|
|
17
|
+
new URL(urlFromNode)
|
|
18
|
+
: // handles relative links
|
|
19
|
+
new URL(`${path.posix.resolve(path.posix.dirname(fullPath), urlFromNode)}`, options.baseUrl);
|
|
20
|
+
if (!isExternalUrl && url.hash !== '') {
|
|
21
|
+
const isValidHeadingLink = headings.findIndex(heading => heading.replace(/\W+/g, '-').toLowerCase() === url.hash.substring(1).toLowerCase()) !== -1;
|
|
22
|
+
if (isValidHeadingLink) {
|
|
23
|
+
// link points to a heading on the page
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (options.skipUrlPatterns &&
|
|
28
|
+
options.skipUrlPatterns.some(skipPattern => new RegExp(skipPattern).test(url.toString()))) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!urlToNodes[url.toString()]) {
|
|
32
|
+
urlToNodes[url.toString()] = [];
|
|
33
|
+
}
|
|
34
|
+
urlToNodes[url.toString()].push(node);
|
|
35
|
+
};
|
|
36
|
+
visit(ast, ['link', 'image', 'definition'], aggregate);
|
|
37
|
+
const links = Object.keys(urlToNodes);
|
|
38
|
+
const checkLinksOptions = options.proxyEndpoint
|
|
39
|
+
? {
|
|
40
|
+
agent: {
|
|
41
|
+
https: new HttpsProxyAgent(options.proxyEndpoint)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
: {};
|
|
45
|
+
const results = await checkLinks(links, checkLinksOptions);
|
|
46
|
+
links.forEach(link => {
|
|
47
|
+
const result = results[link];
|
|
48
|
+
if (result.status !== 'dead' && result.status !== 'invalid') {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const nodes = urlToNodes[link];
|
|
52
|
+
if (!nodes)
|
|
53
|
+
return;
|
|
54
|
+
console.group(`[Mosaic] Broken links found in ${fullPath}`);
|
|
55
|
+
for (const node of nodes) {
|
|
56
|
+
console.log(`Link to ${link} is dead`, node);
|
|
57
|
+
}
|
|
58
|
+
console.groupEnd();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async function findPageHeadings(ast) {
|
|
62
|
+
const headings = [];
|
|
63
|
+
visit(ast, ['heading'], node => {
|
|
64
|
+
headings.push(node.children[0]?.value);
|
|
65
|
+
});
|
|
66
|
+
return headings;
|
|
67
|
+
}
|
|
68
|
+
const processor = remark().use(remarkMdx);
|
|
69
|
+
const BrokenLinksPlugin = {
|
|
70
|
+
async $afterSource(pages, _, options) {
|
|
71
|
+
pages.forEach(async (page) => {
|
|
72
|
+
const ast = await processor.parse(page.content);
|
|
73
|
+
const headings = await findPageHeadings(ast);
|
|
74
|
+
await checkPageLinks(ast, options, page.fullPath, headings);
|
|
75
|
+
});
|
|
76
|
+
return pages;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
export default BrokenLinksPlugin;
|
|
80
|
+
//# sourceMappingURL=BrokenLinksPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrokenLinksPlugin.js","sourceRoot":"","sources":["../src/BrokenLinksPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,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9C;QACD,OAAO,CAAC,QAAQ,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,GAAG;IACjC,MAAM,QAAQ,GAAG,EAAE,CAAC;IACpB,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,EAAE;QAC7B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAU1C,MAAM,iBAAiB,GAAgE;IACrF,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO;QAClC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAC,IAAI,EAAC,EAAE;YACzB,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAChD,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,GAAG,CAAC,CAAC;YAC7C,MAAM,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { escapeRegExp } from 'lodash-es';
|
|
3
|
+
import { remark } from 'remark';
|
|
4
|
+
import remarkMdx from 'remark-mdx';
|
|
5
|
+
import remarkDirective from 'remark-directive';
|
|
6
|
+
import { visitParents } from 'unist-util-visit-parents';
|
|
7
|
+
import PluginError from './utils/PluginError.js';
|
|
8
|
+
const createPageTest = (ignorePages, pageExtensions) => {
|
|
9
|
+
const extTest = new RegExp(`${pageExtensions.map(ext => escapeRegExp(ext)).join('|')}$`);
|
|
10
|
+
const ignoreTest = new RegExp(`${ignorePages.map(ignore => escapeRegExp(ignore)).join('|')}$`);
|
|
11
|
+
return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
|
|
12
|
+
};
|
|
13
|
+
function getFullPath(fullPath, relativePath) {
|
|
14
|
+
const pathSegments = fullPath.split('/');
|
|
15
|
+
const relativeSegments = relativePath.split('/');
|
|
16
|
+
pathSegments.pop();
|
|
17
|
+
for (const segment of relativeSegments) {
|
|
18
|
+
if (segment === '..') {
|
|
19
|
+
pathSegments.pop();
|
|
20
|
+
}
|
|
21
|
+
else if (segment !== '.') {
|
|
22
|
+
pathSegments.push(segment);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return pathSegments.join('/');
|
|
26
|
+
}
|
|
27
|
+
async function processTree(tree, serialiser, mutableFilesystem, fullPath, isNonHiddenPage) {
|
|
28
|
+
const nodesToProcess = [];
|
|
29
|
+
visitParents(tree, (node, ancestors) => {
|
|
30
|
+
if (node.type === 'code') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const match = node.name === 'fragment' && node.attributes.src;
|
|
34
|
+
if (match) {
|
|
35
|
+
const parent = ancestors[ancestors.length - 1];
|
|
36
|
+
const index = parent.children.indexOf(node);
|
|
37
|
+
nodesToProcess.push({ node, parent, index });
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
for (const { node, parent, index } of nodesToProcess) {
|
|
41
|
+
const fragmentFullPath = getFullPath(fullPath, node.attributes.src);
|
|
42
|
+
if (!isNonHiddenPage(fragmentFullPath)) {
|
|
43
|
+
console.warn(`Invalid file reference: '${node.attributes.src}'. Skipping.`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const fragmentPage = await serialiser.deserialise(fragmentFullPath, await mutableFilesystem.promises.readFile(fragmentFullPath));
|
|
47
|
+
// Create a new node with the content from fragmentPage.content
|
|
48
|
+
const newNode = {
|
|
49
|
+
type: 'html',
|
|
50
|
+
value: fragmentPage.content
|
|
51
|
+
};
|
|
52
|
+
// Replace the original node with the newNode in the tree
|
|
53
|
+
parent.children.splice(index, 1, newNode);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return tree;
|
|
57
|
+
}
|
|
58
|
+
const FragmentPlugin = {
|
|
59
|
+
async $beforeSend(mutableFilesystem, { serialiser, ignorePages, pageExtensions }) {
|
|
60
|
+
const pages = await Promise.all((await mutableFilesystem.promises.glob('**', {
|
|
61
|
+
onlyFiles: true,
|
|
62
|
+
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
63
|
+
cwd: '/'
|
|
64
|
+
})).map(async (pagePath) => {
|
|
65
|
+
const deserialisedPage = await serialiser.deserialise(pagePath, await mutableFilesystem.promises.readFile(pagePath));
|
|
66
|
+
return deserialisedPage;
|
|
67
|
+
}));
|
|
68
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
69
|
+
for (const page of pages) {
|
|
70
|
+
try {
|
|
71
|
+
const { fullPath } = page;
|
|
72
|
+
if (!isNonHiddenPage(fullPath)) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const tree = remark().use(remarkMdx).use(remarkDirective).parse(page.content);
|
|
76
|
+
const processedTree = await processTree(tree, serialiser, mutableFilesystem, fullPath, isNonHiddenPage);
|
|
77
|
+
page.content = remark()
|
|
78
|
+
.data('settings', { fences: true })
|
|
79
|
+
.use(remarkMdx)
|
|
80
|
+
.use(remarkDirective)
|
|
81
|
+
.stringify(processedTree);
|
|
82
|
+
const updatedFileData = await serialiser.serialise(fullPath, page);
|
|
83
|
+
await mutableFilesystem.promises.writeFile(fullPath, updatedFileData);
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
throw new PluginError(e.message, page.fullPath);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
export default FragmentPlugin;
|
|
92
|
+
//# sourceMappingURL=FragmentPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FragmentPlugin.js","sourceRoot":"","sources":["../src/FragmentPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,WAAW,MAAM,wBAAwB,CAAC;AAOjD,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,cAAc,EAAE,EAAE;IACrD,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzF,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/F,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,CAAC;AAEF,SAAS,WAAW,CAAC,QAAgB,EAAE,YAAoB;IACzD,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM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,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,IAAI;gBACF,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;gBAC1B,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE;oBAC9B,SAAS;iBACV;gBAED,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAC9E,MAAM,aAAa,GAAG,MAAM,WAAW,CACrC,IAAI,EACJ,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,eAAe,CAChB,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,SAAS,CAAC,aAAa,CAAC,CAAC;gBAE5B,MAAM,eAAe,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBACnE,MAAM,iBAAiB,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;aACvE;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;aACjD;SACF;IACH,CAAC;CACF,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
interface LazyPagePluginPage extends Page {
|
|
3
|
+
aliases: {
|
|
4
|
+
[key: string]: Set<string>;
|
|
5
|
+
};
|
|
6
|
+
hddPaths: {
|
|
7
|
+
[key: string]: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
interface LazyPagePluginOptions {
|
|
11
|
+
cacheDir?: string;
|
|
12
|
+
}
|
|
13
|
+
declare const LazyPagePlugin: PluginType<LazyPagePluginPage, LazyPagePluginOptions>;
|
|
14
|
+
export default LazyPagePlugin;
|