@jpmorganchase/mosaic-plugins 0.1.0-beta.3 → 0.1.0-beta.30
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 +55 -0
- package/dist/$AliasPlugin.js.map +1 -0
- package/dist/$CodeModPlugin.d.ts +7 -0
- package/dist/$CodeModPlugin.js +24 -0
- package/dist/$CodeModPlugin.js.map +1 -0
- package/dist/$RefPlugin.d.ts +31 -0
- package/dist/$RefPlugin.js +119 -0
- package/dist/$RefPlugin.js.map +1 -0
- package/dist/$TagPlugin.d.ts +28 -0
- package/dist/$TagPlugin.js +65 -0
- package/dist/$TagPlugin.js.map +1 -0
- package/dist/BreadcrumbsPlugin.d.ts +18 -0
- package/dist/BreadcrumbsPlugin.js +38 -0
- package/dist/BreadcrumbsPlugin.js.map +1 -0
- package/dist/BrokenLinksPlugin.d.ts +10 -0
- package/dist/BrokenLinksPlugin.js +80 -0
- package/dist/BrokenLinksPlugin.js.map +1 -0
- package/dist/LazyPagePlugin.d.ts +14 -0
- package/dist/LazyPagePlugin.js +63 -0
- package/dist/LazyPagePlugin.js.map +1 -0
- package/dist/LocalFolderSavePlugin.d.ts +6 -0
- package/dist/LocalFolderSavePlugin.js +21 -0
- package/dist/LocalFolderSavePlugin.js.map +1 -0
- package/dist/PagesWithoutFileExtPlugin.d.ts +9 -0
- package/dist/PagesWithoutFileExtPlugin.js +29 -0
- package/dist/PagesWithoutFileExtPlugin.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 +152 -0
- package/dist/SearchIndexPlugin.js.map +1 -0
- package/dist/SharedConfigPlugin.d.ts +13 -0
- package/dist/SharedConfigPlugin.js +34 -0
- package/dist/SharedConfigPlugin.js.map +1 -0
- package/dist/SidebarPlugin.d.ts +38 -0
- package/dist/SidebarPlugin.js +207 -0
- package/dist/SidebarPlugin.js.map +1 -0
- package/dist/SiteMapPlugin.d.ts +6 -0
- package/dist/SiteMapPlugin.js +27 -0
- package/dist/SiteMapPlugin.js.map +1 -0
- package/dist/TableOfContentsPlugin.d.ts +20 -0
- package/dist/TableOfContentsPlugin.js +43 -0
- package/dist/TableOfContentsPlugin.js.map +1 -0
- package/dist/utils/normaliseRefs.d.ts +1 -0
- package/dist/utils/normaliseRefs.js +66 -0
- package/dist/utils/normaliseRefs.js.map +1 -0
- package/package.json +41 -15
- package/.turbo/turbo-build.log +0 -14
- package/CHANGELOG.md +0 -34
- package/src/$AliasPlugin.ts +0 -62
- package/src/$CodeModPlugin.ts +0 -34
- package/src/$RefPlugin.ts +0 -200
- package/src/$TagPlugin.ts +0 -99
- package/src/BreadcrumbsPlugin.ts +0 -43
- package/src/LazyPagePlugin.ts +0 -101
- package/src/NextPrevPagePlugin.ts +0 -80
- package/src/PagesWithoutFileExtPlugin.ts +0 -38
- package/src/ReadingTimePlugin.mjs.ts +0 -32
- package/src/SharedConfigPlugin.ts +0 -49
- package/src/SidebarPlugin.ts +0 -154
- package/src/SiteMapPlugin.ts +0 -44
- package/src/TableOfContentsPlugin.mjs.ts +0 -52
- package/src/utils/normaliseRefs.ts +0 -85
- package/tsconfig.json +0 -21
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
interface AliasPluginPage extends Page {
|
|
3
|
+
aliases?: string[];
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Plugin that scrapes `aliases` from page metadata and also applies all aliases stored in `config.data.aliases`
|
|
7
|
+
* Other plugins can use `setAliases` to apply new aliases, as long as they call it before this plugin has reaches `$beforeSend`
|
|
8
|
+
*/
|
|
9
|
+
declare const $AliasPlugin: PluginType<AliasPluginPage>;
|
|
10
|
+
export default $AliasPlugin;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { escapeRegExp } from 'lodash-es';
|
|
3
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
4
|
+
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
5
|
+
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp).join('|')}$`);
|
|
6
|
+
return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Plugin that scrapes `aliases` from page metadata and also applies all aliases stored in `config.data.aliases`
|
|
10
|
+
* Other plugins can use `setAliases` to apply new aliases, as long as they call it before this plugin has reaches `$beforeSend`
|
|
11
|
+
*/
|
|
12
|
+
const $AliasPlugin = {
|
|
13
|
+
async $afterSource(pages, { config, ignorePages, pageExtensions }) {
|
|
14
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
15
|
+
// Group together all aliases defined in the frontmatter and store them in the alias config object
|
|
16
|
+
for (const page of pages) {
|
|
17
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (page.aliases) {
|
|
21
|
+
config.setAliases(page.fullPath, page.aliases);
|
|
22
|
+
}
|
|
23
|
+
delete page.aliases;
|
|
24
|
+
}
|
|
25
|
+
return pages;
|
|
26
|
+
},
|
|
27
|
+
async $beforeSend(mutableFilesystem, { config }) {
|
|
28
|
+
// Prevent any more aliases being set after this lifecycle has been called - as they won't take effect
|
|
29
|
+
config.setAliases = () => {
|
|
30
|
+
throw new Error('Cannot set aliases after `$AliasPlugin` has reached `$beforeSend` lifecycle phase.');
|
|
31
|
+
};
|
|
32
|
+
if (!config.data.aliases) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
for (const fullPath in config.data.aliases) {
|
|
36
|
+
for (const alias of config.data.aliases[fullPath]) {
|
|
37
|
+
const aliasPath = path.posix.resolve(path.dirname(fullPath), alias).toLowerCase();
|
|
38
|
+
const aliasDir = path.dirname(aliasPath);
|
|
39
|
+
if (!(await mutableFilesystem.promises.exists(aliasDir))) {
|
|
40
|
+
await mutableFilesystem.promises.mkdir(aliasDir, {
|
|
41
|
+
recursive: true
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (!(await mutableFilesystem.promises.exists(aliasPath))) {
|
|
45
|
+
await mutableFilesystem.promises.symlink(fullPath, aliasPath);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
console.warn(`Alias '${aliasPath}' already exists. Is there a duplicate alias, or a page with the same name but different file extensions?`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
export default $AliasPlugin;
|
|
55
|
+
//# sourceMappingURL=$AliasPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"$AliasPlugin.js","sourceRoot":"","sources":["../src/$AliasPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,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,IAA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F,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;gBACzC,IAAI,CAAC,CAAC,MAAM,iBAAiB,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE;oBACxD,MAAM,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE;wBAC/C,SAAS,EAAE,IAAI;qBAChB,CAAC,CAAC;iBACJ;gBACD,IAAI,CAAC,CAAC,MAAM,iBAAiB,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE;oBACzD,MAAM,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;iBAC/D;qBAAM;oBACL,OAAO,CAAC,IAAI,CACV,UAAU,SAAS,2GAA2G,CAC/H,CAAC;iBACH;aACF;SACF;IACH,CAAC;CACF,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
interface CodeModPluginPage extends Page {
|
|
3
|
+
frameOverrides?: Record<string, unknown>;
|
|
4
|
+
sharedConfig?: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
declare const $CodeModPlugin: PluginType<CodeModPluginPage>;
|
|
7
|
+
export default $CodeModPlugin;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { escapeRegExp } from 'lodash-es';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
4
|
+
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
5
|
+
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp).join('|')}$`);
|
|
6
|
+
return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
|
|
7
|
+
}
|
|
8
|
+
const $CodeModPlugin = {
|
|
9
|
+
async $afterSource(pages, { ignorePages, pageExtensions }) {
|
|
10
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
11
|
+
for (const page of pages) {
|
|
12
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (page.frameOverrides) {
|
|
16
|
+
page.sharedConfig = page.frameOverrides;
|
|
17
|
+
page.frameOverrides = { $ref: '#/sharedConfig' };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return pages;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export default $CodeModPlugin;
|
|
24
|
+
//# sourceMappingURL=$CodeModPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"$CodeModPlugin.js","sourceRoot":"","sources":["../src/$CodeModPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,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;AAOD,MAAM,cAAc,GAAkC;IACpD,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,cAAc,EAAE;QACvD,MAAM,eAAe,GAAG,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAEpE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;gBACnC,SAAS;aACV;YACD,IAAI,IAAI,CAAC,cAAc,EAAE;gBACvB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC;gBACxC,IAAI,CAAC,cAAc,GAAG,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC;aAClD;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
interface RefsPluginConfigData {
|
|
3
|
+
refs: {
|
|
4
|
+
[key: string]: {
|
|
5
|
+
$$path: string[];
|
|
6
|
+
$$value: string;
|
|
7
|
+
}[];
|
|
8
|
+
};
|
|
9
|
+
globalRefs: {
|
|
10
|
+
[key: string]: {
|
|
11
|
+
$$path: string[];
|
|
12
|
+
$$value: string;
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
15
|
+
subscribedTags: string[];
|
|
16
|
+
}
|
|
17
|
+
interface RefsPluginPage {
|
|
18
|
+
fullPath: string;
|
|
19
|
+
refs: {
|
|
20
|
+
[key: string]: {
|
|
21
|
+
$$path: string[];
|
|
22
|
+
$$value: string;
|
|
23
|
+
}[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Plugin that scrapes `$ref` properties from page metadata and also applies all refs stored in `config.data.refs`.
|
|
28
|
+
* Other plugins can use `setRef` to apply new refs, as long as they call it before this plugin has reaches `$beforeSend`
|
|
29
|
+
*/
|
|
30
|
+
declare const $RefPlugin: PluginType<RefsPluginPage, unknown, RefsPluginConfigData>;
|
|
31
|
+
export default $RefPlugin;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { reduce, omit, merge, escapeRegExp } from 'lodash-es';
|
|
3
|
+
import $RefParser from '@apidevtools/json-schema-ref-parser';
|
|
4
|
+
import normaliseRefs from './utils/normaliseRefs.js';
|
|
5
|
+
function createRefResolver(normalisedRefs, serialiser, mutableFilesystem) {
|
|
6
|
+
return {
|
|
7
|
+
file: {
|
|
8
|
+
canRead: true,
|
|
9
|
+
order: 1,
|
|
10
|
+
async read(file, callback) {
|
|
11
|
+
try {
|
|
12
|
+
const refedPage = normalisedRefs[file.url] ||
|
|
13
|
+
(await serialiser.deserialise(file.url, await mutableFilesystem.promises.readFile(file.url)));
|
|
14
|
+
return callback(null, omit(refedPage, 'content'));
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
return callback(e, null);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const findKeys = (obj, targetProp, pathParts = []) => reduce(obj, (found, value, key) => {
|
|
24
|
+
if (key === targetProp) {
|
|
25
|
+
return found.concat([[pathParts.concat(String(key)), value]]);
|
|
26
|
+
}
|
|
27
|
+
if (typeof value === 'object') {
|
|
28
|
+
const foundParents = findKeys(value, targetProp, pathParts.concat(String(key)));
|
|
29
|
+
return found.concat(foundParents);
|
|
30
|
+
}
|
|
31
|
+
return found;
|
|
32
|
+
}, []);
|
|
33
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
34
|
+
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
35
|
+
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp).join('|')}$`);
|
|
36
|
+
return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Plugin that scrapes `$ref` properties from page metadata and also applies all refs stored in `config.data.refs`.
|
|
40
|
+
* Other plugins can use `setRef` to apply new refs, as long as they call it before this plugin has reaches `$beforeSend`
|
|
41
|
+
*/
|
|
42
|
+
const $RefPlugin = {
|
|
43
|
+
async afterUpdate(mutableFilesystem, { ignorePages, globalFilesystem, serialiser, pageExtensions, globalConfig }) {
|
|
44
|
+
mutableFilesystem.__internal_do_not_use_addReadFileHook(async (pagePath, fileData) => {
|
|
45
|
+
if (globalConfig.data.globalRefs[pagePath]) {
|
|
46
|
+
const normalisedRef = merge(await serialiser.deserialise(pagePath, fileData), await normaliseRefs(String(pagePath), globalConfig.data.globalRefs[pagePath], globalFilesystem, pageExtensions, ignorePages));
|
|
47
|
+
const resolve = createRefResolver({
|
|
48
|
+
[pagePath]: normalisedRef
|
|
49
|
+
}, serialiser, globalFilesystem);
|
|
50
|
+
const refParser = new $RefParser();
|
|
51
|
+
try {
|
|
52
|
+
const resolved = await refParser.dereference(String(pagePath), normalisedRef, {
|
|
53
|
+
resolve,
|
|
54
|
+
dereference: { circular: false }
|
|
55
|
+
});
|
|
56
|
+
const serialisedPage = await serialiser.serialise(pagePath, merge(normalisedRef, resolved));
|
|
57
|
+
return serialisedPage;
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
console.warn(`Error resolving ref(s) for page '${pagePath}'. ${e.message.replace(/\.$/, '')} in '${e.source}'`);
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return fileData;
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
async $beforeSend(mutableFilesystem, { config, serialiser, pageExtensions, ignorePages }) {
|
|
68
|
+
// Prevent any more refs being set after this lifecycle has been called - as they won't take effect
|
|
69
|
+
config.setRef = () => {
|
|
70
|
+
throw new Error('Cannot set refs after `RefPlugin` has reached `$beforeSend` lifecycle phase.');
|
|
71
|
+
};
|
|
72
|
+
const normalisedRefs = {};
|
|
73
|
+
if (config.data.refs) {
|
|
74
|
+
// First pass of refs, normalises any $ref entries to expand wildcards
|
|
75
|
+
for (const fullPath in config.data.refs) {
|
|
76
|
+
const page = await serialiser.deserialise(fullPath, await mutableFilesystem.promises.readFile(fullPath));
|
|
77
|
+
normalisedRefs[fullPath] = merge(page, await normaliseRefs(String(fullPath), config.data.refs[fullPath], mutableFilesystem, pageExtensions, ignorePages));
|
|
78
|
+
}
|
|
79
|
+
const resolve = createRefResolver(normalisedRefs, serialiser, mutableFilesystem);
|
|
80
|
+
const refParser = new $RefParser();
|
|
81
|
+
// Second pass of refs, resolves the refs
|
|
82
|
+
for (const fullPath in normalisedRefs) {
|
|
83
|
+
const page = normalisedRefs[fullPath];
|
|
84
|
+
try {
|
|
85
|
+
const resolved = await refParser.dereference(String(fullPath), page, {
|
|
86
|
+
resolve,
|
|
87
|
+
dereference: { circular: false }
|
|
88
|
+
});
|
|
89
|
+
normalisedRefs[fullPath] = { ...page, ...resolved };
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
console.warn(`Error resolving ref(s) for page '${fullPath}'. ${e.message.replace(/\.$/, '')} in '${e.source}'`);
|
|
93
|
+
throw e;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Third pass, write out the files
|
|
97
|
+
for (const fullPath in normalisedRefs) {
|
|
98
|
+
await mutableFilesystem.promises.writeFile(fullPath, await serialiser.serialise(fullPath, normalisedRefs[fullPath]));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
async $afterSource(pages, { config, ignorePages, pageExtensions }) {
|
|
103
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
104
|
+
for (const page of pages) {
|
|
105
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const refs = findKeys(page, '$ref');
|
|
109
|
+
if (refs.length) {
|
|
110
|
+
for (const ref of refs) {
|
|
111
|
+
config.setRef(page.fullPath, ...ref);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return pages;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
export default $RefPlugin;
|
|
119
|
+
//# sourceMappingURL=$RefPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"$RefPlugin.js","sourceRoot":"","sources":["../src/$RefPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,UAAU,MAAM,qCAAqC,CAAC;AAG7D,OAAO,aAAa,MAAM,0BAA0B,CAAC;AAErD,SAAS,iBAAiB,CAAC,cAAc,EAAE,UAAU,EAAE,iBAAiB;IACtE,OAAO;QACL,IAAI,EAAE;YACJ,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,CAAC;YACR,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ;gBACvB,IAAI;oBACF,MAAM,SAAS,GACb,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC;wBACxB,CAAC,MAAM,UAAU,CAAC,WAAW,CAC3B,IAAI,CAAC,GAAG,EACR,MAAM,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CACpD,CAAC,CAAC;oBACL,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;iBACnD;gBAAC,OAAO,CAAC,EAAE;oBACV,OAAO,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;iBAC1B;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,YAAsB,EAAE,EAAwB,EAAE,CACnF,MAAM,CACJ,GAAG,EACH,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;IACpB,IAAI,GAAG,KAAK,UA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AAO,CAAC,KAAK,EAAE,EAAE,CAAC,QAC5E,CAAC,CAAC,MACJ,GAAG,CACJ,CAAC;oBACF,MAAM,CAAC,CAAC;iBACT;aACF;YACD,kCAAkC;YAClC,KAAK,MAAM,QAAQ,IAAI,cAAc,EAAE;gBACrC,MAAM,iBAAiB,CAAC,QAAQ,CAAC,SAAS,CACxC,QAAQ,EACR,MAAM,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC,CAC/D,CAAC;aACH;SACF;IACH,CAAC;IACD,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;QAEpE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;gBACnC,SAAS;aACV;YACD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAEpC,IAAI,IAAI,CAAC,MAAM,EAAE;gBACf,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;oBACtB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,GAAG,CAAC,CAAC;iBACtC;aACF;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
interface TagPluginPage extends Page {
|
|
3
|
+
tags?: string[];
|
|
4
|
+
}
|
|
5
|
+
interface TagPluginConfigData {
|
|
6
|
+
tagRefs: {
|
|
7
|
+
[key: string]: {
|
|
8
|
+
$$path: string[];
|
|
9
|
+
$$value: string[];
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
globalRefs: {
|
|
13
|
+
[key: string]: {
|
|
14
|
+
$$path: string[];
|
|
15
|
+
$$value: string[];
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
subscribedTags: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Plugin that scrapes `$tag` from page metadata and also applies all aliases stored in `config.data.tags`.
|
|
22
|
+
* Tags ultimately resolve down into refs, but are different from normal refs, in that they are applied to the
|
|
23
|
+
* union filesystem (all merged filesystems), not to the individual source filesystem that they were defined on.
|
|
24
|
+
* Other plugins can use `setData()` and modify the `tags` property, to apply new global refs, as long as
|
|
25
|
+
* they do so before this plugin has reaches `$beforeSend`
|
|
26
|
+
*/
|
|
27
|
+
declare const $TagPlugin: PluginType<TagPluginPage, unknown, TagPluginConfigData>;
|
|
28
|
+
export default $TagPlugin;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { escapeRegExp, reduce } from 'lodash-es';
|
|
3
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
4
|
+
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
5
|
+
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp).join('|')}$`);
|
|
6
|
+
return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
|
|
7
|
+
}
|
|
8
|
+
const findKeys = (obj, targetProp, pathParts = []) => reduce(obj, (found, value, key) => {
|
|
9
|
+
if (key === targetProp) {
|
|
10
|
+
return found.concat({ $$path: pathParts.concat(String(key)), $$value: value });
|
|
11
|
+
}
|
|
12
|
+
if (typeof value === 'object') {
|
|
13
|
+
const foundParents = findKeys(value, targetProp, pathParts.concat(String(key)));
|
|
14
|
+
return found.concat(...foundParents);
|
|
15
|
+
}
|
|
16
|
+
return found;
|
|
17
|
+
}, []);
|
|
18
|
+
/**
|
|
19
|
+
* Plugin that scrapes `$tag` from page metadata and also applies all aliases stored in `config.data.tags`.
|
|
20
|
+
* Tags ultimately resolve down into refs, but are different from normal refs, in that they are applied to the
|
|
21
|
+
* union filesystem (all merged filesystems), not to the individual source filesystem that they were defined on.
|
|
22
|
+
* Other plugins can use `setData()` and modify the `tags` property, to apply new global refs, as long as
|
|
23
|
+
* they do so before this plugin has reaches `$beforeSend`
|
|
24
|
+
*/
|
|
25
|
+
const $TagPlugin = {
|
|
26
|
+
// Check if the updated source has any /.tag aliases that we care about - if it does, we should re-run `afterUpdate` to
|
|
27
|
+
// make sure we pull in the latest pages
|
|
28
|
+
async shouldClearCache(updatedSourceFilesystem, { config }) {
|
|
29
|
+
if (!config.data?.subscribedTags ||
|
|
30
|
+
!(await updatedSourceFilesystem.promises.exists('/.tags'))) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
// Does the updated source have tags we are interested in?
|
|
34
|
+
return (await updatedSourceFilesystem.promises.readdir('/.tags')).some(tag => config.data.subscribedTags.includes(tag));
|
|
35
|
+
},
|
|
36
|
+
// Every source with tags will create symlinks with the tagged pages, inside /.tags
|
|
37
|
+
async $afterSource(pages, { config, ignorePages, pageExtensions }) {
|
|
38
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
39
|
+
for (const page of pages) {
|
|
40
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const meta = page;
|
|
44
|
+
// Symlink every `tag` item to '/.tags' folder
|
|
45
|
+
if (meta.tags?.length) {
|
|
46
|
+
config.setTags(page.fullPath, meta.tags);
|
|
47
|
+
delete meta.tags;
|
|
48
|
+
}
|
|
49
|
+
// Find any references to $tag
|
|
50
|
+
const foundTags = findKeys(page, '$tag');
|
|
51
|
+
if (foundTags.length) {
|
|
52
|
+
const tags = new Set();
|
|
53
|
+
foundTags.forEach(ref => {
|
|
54
|
+
const [tag, fragment = ''] = ref.$$value.split('#');
|
|
55
|
+
tags.add(tag);
|
|
56
|
+
config.setGlobalRef(page.fullPath, ref.$$path, `${path.join('/.tags', tag, '**')}#${fragment}`);
|
|
57
|
+
});
|
|
58
|
+
config.setData({ subscribedTags: Array.from(tags) });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return pages;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
export default $TagPlugin;
|
|
65
|
+
//# sourceMappingURL=$TagPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAGjD,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,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,YAAsB,EAAE,EAAE,EAAE,CAC7D,MAAM,CACJ,GAAG,EACH,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;IACpB,IAAI,GAAG,KAAK,UAAU,EAAE;QACtB,OAAO,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,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ClB,8CAA8C;YAC9C,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE;gBACrB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBACzC,OAAO,IAAI,CAAC,IAAI,CAAC;aAClB;YAED,8BAA8B;YAC9B,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACzC,IAAI,SAAS,CAAC,MAAM,EAAE;gBACpB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;gBAE/B,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;oBACtB,MAAM,CAAC,GAAG,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBAEpD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;oBAEd,MAAM,CAAC,YAAY,CACjB,IAAI,CAAC,QAAQ,EACb,GAAG,CAAC,MAAM,EACV,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,QAAQ,EAAE,CAChD,CAAC;gBACJ,CAAC,CAAC,CAAC;gBACH,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aACtD;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
export declare type Breadcrumb = {
|
|
3
|
+
label: string;
|
|
4
|
+
path: string;
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
export interface BreadcrumbsPluginPage extends Page {
|
|
8
|
+
breadcrumbs?: Array<Breadcrumb>;
|
|
9
|
+
layout?: string;
|
|
10
|
+
}
|
|
11
|
+
interface BreadcrumbsPluginOptions {
|
|
12
|
+
indexPageName: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Calculates breadcrumbs for pages then embeds a `breadcrumbs` property to the metadata
|
|
16
|
+
*/
|
|
17
|
+
declare const BreadcrumbsPlugin: PluginType<BreadcrumbsPluginPage, BreadcrumbsPluginOptions>;
|
|
18
|
+
export default BreadcrumbsPlugin;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { breadcrumbsLayoutSchema } from '@jpmorganchase/mosaic-schemas';
|
|
3
|
+
/**
|
|
4
|
+
* Calculates breadcrumbs for pages then embeds a `breadcrumbs` property to the metadata
|
|
5
|
+
*/
|
|
6
|
+
const BreadcrumbsPlugin = {
|
|
7
|
+
async $afterSource(pages, _, options) {
|
|
8
|
+
for (const page of pages) {
|
|
9
|
+
if (breadcrumbsLayoutSchema.safeParse(page?.layout).success) {
|
|
10
|
+
const breadcrumbs = [];
|
|
11
|
+
let currentPage = page;
|
|
12
|
+
let parentDir = path.posix.normalize(path.posix.dirname(currentPage.fullPath));
|
|
13
|
+
const maxBreadcrumbCount = page.fullPath.split('/').length;
|
|
14
|
+
while (currentPage !== undefined && breadcrumbs.length < maxBreadcrumbCount) {
|
|
15
|
+
breadcrumbs.unshift({
|
|
16
|
+
label: currentPage.title,
|
|
17
|
+
path: currentPage.route,
|
|
18
|
+
id: currentPage.fullPath
|
|
19
|
+
});
|
|
20
|
+
currentPage = pages.find(
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
22
|
+
item => item.fullPath === path.posix.join(parentDir, options.indexPageName));
|
|
23
|
+
if (currentPage) {
|
|
24
|
+
parentDir = path.posix.dirname(path.posix.join(String(currentPage.fullPath), '..'));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!page.breadcrumbs) {
|
|
28
|
+
// filter out any duplicate breadcrumbs
|
|
29
|
+
const map = new Map(breadcrumbs.map(crumb => [crumb.id, crumb]));
|
|
30
|
+
page.breadcrumbs = [...map.values()];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return pages;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export default BreadcrumbsPlugin;
|
|
38
|
+
//# sourceMappingURL=BreadcrumbsPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BreadcrumbsPlugin.js","sourceRoot":"","sources":["../src/BreadcrumbsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAaxE;;GAEG;AACH,MAAM,iBAAiB,GAAgE;IACrF,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO;QAClC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,IAAI,uBAAuB,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,EAAE;gBAC3D,MAAM,WAAW,GAAsB,EAAE,CAAC;gBAC1C,IAAI,WAAW,GAAG,IAAI,CAAC;gBACvB,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAC/E,MAAM,kBAAkB,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;gBAE3D,OAAO,WAAW,KAAK,SAAS,IAAI,WAAW,CAAC,MAAM,GAAG,kBAAkB,EAAE;oBAC3E,WAAW,CAAC,OAAO,CAAC;wBAClB,KAAK,EAAE,WAAW,CAAC,KAAK;wBACxB,IAAI,EAAE,WAAW,CAAC,KAAK;wBACvB,EAAE,EAAE,WAAW,CAAC,QAAQ;qBACzB,CAAC,CAAC;oBAEH,WAAW,GAAG,KAAK,CAAC,IAAI;oBACtB,2DAA2D;oBAC3D,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,aAAa,CAAC,CAC5E,CAAC;oBACF,IAAI,WAAW,EAAE;wBACf,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;qBACrF;iBACF;gBAED,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;oBACrB,uCAAuC;oBACvC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;oBACjE,IAAI,CAAC,WAAW,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;iBACtC;aACF;SACF;QAED,OAAO,KAAK,CAAC;IACf,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;AACr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AAC;SAC9C;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,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;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import fsExtra from 'fs-extra';
|
|
3
|
+
import { merge, escapeRegExp } from 'lodash-es';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
6
|
+
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
7
|
+
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp).join('|')}$`);
|
|
8
|
+
return file => !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
|
|
9
|
+
}
|
|
10
|
+
function createFileGlob(url, pageExtensions) {
|
|
11
|
+
if (pageExtensions.length === 1) {
|
|
12
|
+
return `${url}${pageExtensions[0]}`;
|
|
13
|
+
}
|
|
14
|
+
return `${url}{${pageExtensions.join(',')}}`;
|
|
15
|
+
}
|
|
16
|
+
const LazyPagePlugin = {
|
|
17
|
+
async afterUpdate(mutableFilesystem, { ignorePages, config, pageExtensions, serialiser }) {
|
|
18
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
19
|
+
// This adds a hook that triggers everytime a non-cached page is read from the filesystem.
|
|
20
|
+
mutableFilesystem.__internal_do_not_use_addReadFileHook(async (pagePath, fileData) => {
|
|
21
|
+
// If this is a 'page' - read the original file from disk and try to inject anything that's missing.
|
|
22
|
+
if (isNonHiddenPage(pagePath)) {
|
|
23
|
+
const currentPage = await serialiser.deserialise(pagePath, fileData);
|
|
24
|
+
if (config.data.hddPaths?.[pagePath]) {
|
|
25
|
+
const page = await serialiser.deserialise(pagePath, await fs.promises.readFile(config.data.hddPaths[pagePath]));
|
|
26
|
+
const completePage = await serialiser.serialise(pagePath, merge(page, currentPage, { content: page.content }));
|
|
27
|
+
return completePage;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return fileData;
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, options) {
|
|
34
|
+
const hddPaths = {};
|
|
35
|
+
let originalDiskSize = 0;
|
|
36
|
+
let newDiskSize = 0;
|
|
37
|
+
const allPages = await mutableFilesystem.promises.glob(createFileGlob('**', pageExtensions), {
|
|
38
|
+
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
39
|
+
cwd: '/',
|
|
40
|
+
onlyFiles: true
|
|
41
|
+
});
|
|
42
|
+
const baseDir = path.join(process.cwd(), options.cacheDir || '.mosaic-lazy-page-plugin-cache');
|
|
43
|
+
await fsExtra.ensureDir(baseDir);
|
|
44
|
+
for (const filePath of allPages) {
|
|
45
|
+
const rawPage = await mutableFilesystem.promises.readFile(String(filePath));
|
|
46
|
+
const page = await serialiser.deserialise(String(filePath), rawPage);
|
|
47
|
+
originalDiskSize += rawPage.length;
|
|
48
|
+
await fs.promises.mkdir(path.dirname(path.join(baseDir, String(filePath))), {
|
|
49
|
+
recursive: true
|
|
50
|
+
});
|
|
51
|
+
await fs.promises.writeFile(path.join(baseDir, String(filePath)), await serialiser.serialise(String(filePath), page));
|
|
52
|
+
const { content, ...pageRest } = page;
|
|
53
|
+
hddPaths[String(filePath)] = path.join(baseDir, String(filePath));
|
|
54
|
+
const redactedPage = await serialiser.serialise(String(filePath), pageRest);
|
|
55
|
+
newDiskSize += redactedPage.length;
|
|
56
|
+
}
|
|
57
|
+
config.setData({ hddPaths });
|
|
58
|
+
const reduction = originalDiskSize - newDiskSize;
|
|
59
|
+
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!)`);
|
|
60
|
+
}
|
|
61
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