@jpmorganchase/mosaic-plugins 0.1.0-beta.24 → 0.1.0-beta.26
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/BrokenLinksPlugin.d.ts +10 -0
- package/dist/BrokenLinksPlugin.js +64 -0
- package/dist/BrokenLinksPlugin.js.map +1 -0
- package/dist/SearchIndexPlugin.d.ts +44 -1
- package/dist/SearchIndexPlugin.js +63 -16
- package/dist/SearchIndexPlugin.js.map +1 -1
- package/dist/SidebarPlugin.d.ts +15 -1
- package/dist/SidebarPlugin.js +76 -17
- package/dist/SidebarPlugin.js.map +1 -1
- package/package.json +12 -8
- package/dist/NextPrevPagePlugin.d.ts +0 -22
- package/dist/NextPrevPagePlugin.js +0 -50
- package/dist/NextPrevPagePlugin.js.map +0 -1
|
@@ -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,64 @@
|
|
|
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) {
|
|
9
|
+
const urlToNodes = {};
|
|
10
|
+
const aggregate = node => {
|
|
11
|
+
const { url: urlFromNode } = node;
|
|
12
|
+
if (!urlFromNode)
|
|
13
|
+
return;
|
|
14
|
+
const url = /^(https?:\/\/)/.test(urlFromNode)
|
|
15
|
+
? // full urls including internal and external
|
|
16
|
+
new URL(urlFromNode)
|
|
17
|
+
: // handles relative links
|
|
18
|
+
new URL(`${path.posix.resolve(path.posix.dirname(fullPath), urlFromNode)}`, options.baseUrl);
|
|
19
|
+
if (options.skipUrlPatterns &&
|
|
20
|
+
options.skipUrlPatterns.some(skipPattern => new RegExp(skipPattern).test(url.toString()))) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!urlToNodes[url.toString()]) {
|
|
24
|
+
urlToNodes[url.toString()] = [];
|
|
25
|
+
}
|
|
26
|
+
urlToNodes[url.toString()].push(node);
|
|
27
|
+
};
|
|
28
|
+
visit(ast, ['link', 'image', 'definition'], aggregate);
|
|
29
|
+
const links = Object.keys(urlToNodes);
|
|
30
|
+
const checkLinksOptions = options.proxyEndpoint
|
|
31
|
+
? {
|
|
32
|
+
agent: {
|
|
33
|
+
https: new HttpsProxyAgent(options.proxyEndpoint)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
: {};
|
|
37
|
+
const results = await checkLinks(links, checkLinksOptions);
|
|
38
|
+
links.forEach(link => {
|
|
39
|
+
const result = results[link];
|
|
40
|
+
if (result.status !== 'dead' && result.status !== 'invalid') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const nodes = urlToNodes[link];
|
|
44
|
+
if (!nodes)
|
|
45
|
+
return;
|
|
46
|
+
console.group(`[Mosaic] Broken links found in ${fullPath}`);
|
|
47
|
+
for (const node of nodes) {
|
|
48
|
+
console.log(`Link to ${link} is dead`, node);
|
|
49
|
+
}
|
|
50
|
+
console.groupEnd();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const processor = remark().use(remarkMdx);
|
|
54
|
+
const BrokenLinksPlugin = {
|
|
55
|
+
async $afterSource(pages, _, options) {
|
|
56
|
+
pages.forEach(async (page) => {
|
|
57
|
+
const ast = await processor.parse(page.content);
|
|
58
|
+
await checkPageLinks(ast, options, page.fullPath);
|
|
59
|
+
});
|
|
60
|
+
return pages;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export default BrokenLinksPlugin;
|
|
64
|
+
//# 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,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,aAAa,MAAM,mBAAmB,CAAC;AAE9C,MAAM,EAAE,eAAe,EAAE,GAAG,aAAa,CAAC;AAE1C,KAAK,UAAU,cAAc,CAAC,GAAY,EAAE,OAAiC,EAAE,QAAgB;IAC7F,MAAM,UAAU,GAAG,EAAE,CAAC;IAEtB,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE;QACvB,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;QAClC,IAAI,CAAC,WAAW;YAAE,OAAO;QAEzB,MAAM,GAAG,GAAG,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC;YAC5C,CAAC,CAAC,4CAA4C;gBAC5C,IAAI,GAAG,CAAC,WAAW,CAAC;YACtB,CAAC,CAAC,yBAAyB;gBACzB,IAAI,GAAG,CACL,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,EAAE,EAClE,OAAO,CAAC,OAAO,CAChB,CAAC;QAEN,I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MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,UAAU,EAAE,IAAI,CAAC,CAAC;SAC9C;QACD,OAAO,CAAC,QAAQ,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,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,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -1,10 +1,53 @@
|
|
|
1
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
|
+
}
|
|
2
13
|
interface SearchIndexPluginOptions {
|
|
3
14
|
maxLineLength?: number;
|
|
4
15
|
maxLineCount?: number;
|
|
5
16
|
keys?: string[];
|
|
6
|
-
|
|
17
|
+
relevancy?: SearchRelevancy;
|
|
18
|
+
}
|
|
19
|
+
interface Optimization {
|
|
20
|
+
content: string;
|
|
21
|
+
title: string;
|
|
22
|
+
maxLineCount?: number;
|
|
23
|
+
maxLineLength?: number;
|
|
7
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, title, maxLineLength, maxLineCount }: Optimization) => Promise<string[]>;
|
|
8
51
|
/**
|
|
9
52
|
* Creates a search-data.json file that contains all the information
|
|
10
53
|
* from each page that is required to generate a search index.
|
|
@@ -2,6 +2,41 @@ import { unified } from 'unified';
|
|
|
2
2
|
import markdown from 'remark-parse';
|
|
3
3
|
import remarkMdx from 'remark-mdx';
|
|
4
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
|
+
}
|
|
5
40
|
/**
|
|
6
41
|
* Converts raw content string into an array of sentences suitable for inclusion
|
|
7
42
|
* in the search index
|
|
@@ -15,7 +50,7 @@ import { visit } from 'unist-util-visit';
|
|
|
15
50
|
* each page. Pages with more lines than this value will be truncated.
|
|
16
51
|
* @returns array of sentence strings
|
|
17
52
|
*/
|
|
18
|
-
const optimizeContentForSearch = async ({ content, title, maxLineLength, maxLineCount }) => {
|
|
53
|
+
export const optimizeContentForSearch = async ({ content, title, maxLineLength, maxLineCount }) => {
|
|
19
54
|
if (!content || content.length < 1)
|
|
20
55
|
return [content];
|
|
21
56
|
const processor = unified().use(markdown).use(remarkMdx);
|
|
@@ -28,15 +63,19 @@ const optimizeContentForSearch = async ({ content, title, maxLineLength, maxLine
|
|
|
28
63
|
return [];
|
|
29
64
|
}
|
|
30
65
|
const sentences = [];
|
|
66
|
+
const segmenter = new Intl.Segmenter('en', { granularity: 'sentence' });
|
|
31
67
|
visit(tree, (node) => node.type === 'text' || node.type === 'code', (node) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
68
|
+
const segments = [...segmenter.segment(node.value)].map(segment => segment.segment);
|
|
69
|
+
segments.forEach(segment => {
|
|
70
|
+
if (maxLineLength) {
|
|
71
|
+
sentences.push(segment.slice(0, maxLineLength));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
sentences.push(segment);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
38
77
|
});
|
|
39
|
-
if (
|
|
78
|
+
if (maxLineCount) {
|
|
40
79
|
return sentences.slice(0, maxLineCount);
|
|
41
80
|
}
|
|
42
81
|
return sentences;
|
|
@@ -51,7 +90,7 @@ const SearchIndexPlugin = {
|
|
|
51
90
|
* save it to the global config (to be saved to the filesystem later when
|
|
52
91
|
* all sources have been loaded).
|
|
53
92
|
*/
|
|
54
|
-
async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages }, { maxLineLength, maxLineCount, keys }) {
|
|
93
|
+
async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages }, { maxLineLength, maxLineCount, keys: optionKeys }) {
|
|
55
94
|
const pages = await Promise.all((await mutableFilesystem.promises.glob('**', {
|
|
56
95
|
onlyFiles: true,
|
|
57
96
|
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
@@ -67,12 +106,13 @@ const SearchIndexPlugin = {
|
|
|
67
106
|
maxLineLength,
|
|
68
107
|
maxLineCount
|
|
69
108
|
});
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
109
|
+
const keys = parseKeys(optionKeys);
|
|
110
|
+
/**
|
|
111
|
+
* If the "content" key is specified, we want to include the result of
|
|
112
|
+
* the optimizeContentForSearch() function. Otherwise, we include the
|
|
113
|
+
* key value directly from the page data.
|
|
114
|
+
*/
|
|
115
|
+
return keys.reduce((acc, key) => ({ ...acc, [key]: key === 'content' ? content : page[key] }), {});
|
|
76
116
|
}));
|
|
77
117
|
/**
|
|
78
118
|
* Convert the searchData into an object where each page has a unique key (the
|
|
@@ -91,11 +131,18 @@ const SearchIndexPlugin = {
|
|
|
91
131
|
* Once we have all the sources' search data added to `globalConfig`, convert it
|
|
92
132
|
* to JSON and save it to the filesystem.
|
|
93
133
|
*/
|
|
94
|
-
async afterUpdate(_, { sharedFilesystem, globalConfig }) {
|
|
134
|
+
async afterUpdate(_, { sharedFilesystem, globalConfig }, { keys: optionKeys, relevancy }) {
|
|
95
135
|
if (!globalConfig.data.searchIndices)
|
|
96
136
|
return;
|
|
97
137
|
const globalSearchIndices = globalConfig.data.searchIndices;
|
|
98
138
|
const searchData = Object.values(globalSearchIndices);
|
|
139
|
+
const keys = parseKeys(optionKeys);
|
|
140
|
+
const searchConfig = {
|
|
141
|
+
...defaultRelevancyOptions,
|
|
142
|
+
...relevancy,
|
|
143
|
+
keys
|
|
144
|
+
};
|
|
145
|
+
await sharedFilesystem.promises.writeFile('/search-config.json', JSON.stringify(searchConfig));
|
|
99
146
|
await sharedFilesystem.promises.writeFile('/search-data.json', JSON.stringify(searchData));
|
|
100
147
|
}
|
|
101
148
|
};
|
|
@@ -1 +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,OAA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**
|
|
18
|
+
* filename of the sidebar json, linked to each related page via ref
|
|
19
|
+
*/
|
|
17
20
|
filename: string;
|
|
21
|
+
/**
|
|
22
|
+
* Glob pattern for matching directories which should be the root of the sidebar
|
|
23
|
+
* * creates a root level sidebar containing all pages underneath root
|
|
24
|
+
* *\/* creates a separate sidebar under each of the root directories
|
|
25
|
+
*/
|
|
26
|
+
rootDirGlob: string;
|
|
18
27
|
}
|
|
19
28
|
/**
|
|
20
|
-
* Sorts the pages in a folder by priority and then exports a JSON file
|
|
29
|
+
* Sorts the pages in a folder by priority and then exports a JSON file with the
|
|
21
30
|
* sidebar tree from that directory downwards and adds sidebar data into frontmatter for each page.
|
|
31
|
+
*
|
|
32
|
+
* Additionally, add to frontmatter
|
|
33
|
+
* navigation -> prev -> { title, route }
|
|
34
|
+
* navigation -> next -> { title, route }
|
|
35
|
+
* to define the previous/next page in the page sequence, as defined by sidebar label and priority
|
|
22
36
|
*/
|
|
23
37
|
declare const SidebarPlugin: PluginType<SidebarPluginPage, SidebarPluginOptions, SidebarPluginConfigData>;
|
|
24
38
|
export default SidebarPlugin;
|
package/dist/SidebarPlugin.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { cloneDeep } from 'lodash-es';
|
|
3
|
-
// Which level does sidebar creation start
|
|
4
|
-
const sidebarRootLevel = 1;
|
|
5
3
|
function createFileGlob(patterns, pageExtensions) {
|
|
6
4
|
if (Array.isArray(patterns)) {
|
|
7
5
|
return patterns.map(pattern => createFileGlob(pattern, pageExtensions));
|
|
@@ -20,20 +18,35 @@ function sortByPathLevel(pathA, pathB) {
|
|
|
20
18
|
return pathBLevel - pathALevel;
|
|
21
19
|
}
|
|
22
20
|
/**
|
|
23
|
-
* Sorts the pages in a folder by priority and then exports a JSON file
|
|
21
|
+
* Sorts the pages in a folder by priority and then exports a JSON file with the
|
|
24
22
|
* sidebar tree from that directory downwards and adds sidebar data into frontmatter for each page.
|
|
23
|
+
*
|
|
24
|
+
* Additionally, add to frontmatter
|
|
25
|
+
* navigation -> prev -> { title, route }
|
|
26
|
+
* navigation -> next -> { title, route }
|
|
27
|
+
* to define the previous/next page in the page sequence, as defined by sidebar label and priority
|
|
25
28
|
*/
|
|
26
29
|
const SidebarPlugin = {
|
|
27
|
-
async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions },
|
|
30
|
+
async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, { filename = 'sidebar.json', rootDirGlob = '*' }) {
|
|
28
31
|
/**
|
|
29
32
|
* Create a list of pages that should be used to build a sidebar.json
|
|
30
33
|
* @param dirName - root path of sidebar
|
|
31
34
|
*/
|
|
32
|
-
async function createPageList(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
async function createPageList(rootDir) {
|
|
36
|
+
const isChildOfRootDir = pagePath => {
|
|
37
|
+
const pageDir = path.dirname(pagePath);
|
|
38
|
+
return pageDir.indexOf(rootDir) === 0;
|
|
39
|
+
};
|
|
40
|
+
const pagePaths = (await mutableFilesystem.promises.glob(createFileGlob(['**'], pageExtensions), {
|
|
41
|
+
cwd: String(rootDir),
|
|
35
42
|
ignore: ignorePages.map(ignore => `**/${ignore}`)
|
|
36
|
-
}))
|
|
43
|
+
}));
|
|
44
|
+
const filteredPagePaths = pagePaths.filter(isChildOfRootDir);
|
|
45
|
+
const pageList = await Promise.all(filteredPagePaths.map(async (pagePath) => {
|
|
46
|
+
return mutableFilesystem.promises.readFile(pagePath).then(serializedContent => {
|
|
47
|
+
return serialiser.deserialise(pagePath, serializedContent);
|
|
48
|
+
});
|
|
49
|
+
}));
|
|
37
50
|
return pageList;
|
|
38
51
|
}
|
|
39
52
|
/**
|
|
@@ -50,6 +63,7 @@ const SidebarPlugin = {
|
|
|
50
63
|
const level = getPageLevel(page);
|
|
51
64
|
const newChildNode = {
|
|
52
65
|
id,
|
|
66
|
+
fullPath: page.fullPath,
|
|
53
67
|
name,
|
|
54
68
|
priority,
|
|
55
69
|
data: { level, link: page.route },
|
|
@@ -100,13 +114,57 @@ const SidebarPlugin = {
|
|
|
100
114
|
*/
|
|
101
115
|
function addSidebarDataToFrontmatter(pages, dirName) {
|
|
102
116
|
pages.forEach(page => {
|
|
103
|
-
config.setRef(String(page.fullPath), ['sidebarData', '$ref'], path.posix.join(dirName,
|
|
117
|
+
config.setRef(String(page.fullPath), ['sidebarData', '$ref'], path.posix.join(dirName, filename, '#', 'pages'));
|
|
104
118
|
});
|
|
105
119
|
}
|
|
106
|
-
const
|
|
120
|
+
const createNavigationRefs = (currPage, prevPage, nextPage) => {
|
|
121
|
+
if (prevPage) {
|
|
122
|
+
config.setRef(currPage, ['navigation', 'prev', 'title', '$ref'], `${prevPage}#/title`);
|
|
123
|
+
config.setRef(currPage, ['navigation', 'prev', 'route', '$ref'], `${prevPage}#/route`);
|
|
124
|
+
}
|
|
125
|
+
if (nextPage) {
|
|
126
|
+
config.setRef(currPage, ['navigation', 'next', 'title', '$ref'], `${nextPage}#/title`);
|
|
127
|
+
config.setRef(currPage, ['navigation', 'next', 'route', '$ref'], `${nextPage}#/route`);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
function addNavigationToFrontmatter(pages) {
|
|
131
|
+
let prevParentPage, nextParentPage;
|
|
132
|
+
const getLastPage = pages => {
|
|
133
|
+
if (pages[pages.length - 1].childNodes?.length) {
|
|
134
|
+
return getLastPage(pages[pages.length - 1].childNodes);
|
|
135
|
+
}
|
|
136
|
+
return pages[pages.length - 1];
|
|
137
|
+
};
|
|
138
|
+
const lastPage = getLastPage(pages);
|
|
139
|
+
const isFirstPage = page => page === pages[0];
|
|
140
|
+
const isLastPage = page => page === lastPage;
|
|
141
|
+
function recursiveAddNavigation(pages) {
|
|
142
|
+
pages.forEach((page, pageIndex) => {
|
|
143
|
+
const { fullPath: currPage } = page;
|
|
144
|
+
let prevPage, nextPage;
|
|
145
|
+
prevPage = prevParentPage;
|
|
146
|
+
prevParentPage = isFirstPage(page) ? undefined : pages[pageIndex].fullPath;
|
|
147
|
+
if (page.childNodes?.length) {
|
|
148
|
+
nextPage = page.childNodes[0].fullPath;
|
|
149
|
+
nextParentPage =
|
|
150
|
+
pageIndex < pages.length - 1 ? pages[pageIndex + 1].fullPath : nextParentPage;
|
|
151
|
+
}
|
|
152
|
+
else if (pageIndex < pages.length - 1) {
|
|
153
|
+
nextPage = pages[pageIndex + 1].fullPath;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
nextPage = isLastPage(page) ? undefined : nextParentPage;
|
|
157
|
+
}
|
|
158
|
+
createNavigationRefs(currPage, prevPage, nextPage);
|
|
159
|
+
recursiveAddNavigation(page.childNodes);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
recursiveAddNavigation(pages);
|
|
163
|
+
}
|
|
164
|
+
const rootUserJourneys = await mutableFilesystem.promises.glob(rootDirGlob, {
|
|
107
165
|
onlyDirectories: true,
|
|
108
|
-
|
|
109
|
-
|
|
166
|
+
extglob: true,
|
|
167
|
+
cwd: '/'
|
|
110
168
|
});
|
|
111
169
|
const removeExcludedPages = page => !(page.sidebar && page.sidebar.exclude);
|
|
112
170
|
function sortPagesByPriority(sidebarData) {
|
|
@@ -122,15 +180,16 @@ const SidebarPlugin = {
|
|
|
122
180
|
});
|
|
123
181
|
return pagesByPriority;
|
|
124
182
|
}
|
|
125
|
-
await Promise.all(rootUserJourneys.map(async (
|
|
126
|
-
const sidebarFilePath = path.posix.join(String(
|
|
127
|
-
let pages = await createPageList(
|
|
183
|
+
await Promise.all(rootUserJourneys.map(async (rootDir) => {
|
|
184
|
+
const sidebarFilePath = path.posix.join(String(rootDir), filename);
|
|
185
|
+
let pages = await createPageList(rootDir);
|
|
128
186
|
pages = pages.filter(page => removeExcludedPages(page));
|
|
129
187
|
const groupMap = createGroupMap(pages);
|
|
130
|
-
const sidebarData = linkGroupMap(groupMap,
|
|
188
|
+
const sidebarData = linkGroupMap(groupMap, rootDir);
|
|
131
189
|
const pagesByPriority = sortPagesByPriority(sidebarData);
|
|
190
|
+
addNavigationToFrontmatter(pagesByPriority);
|
|
132
191
|
await mutableFilesystem.promises.writeFile(sidebarFilePath, JSON.stringify({ pages: pagesByPriority }));
|
|
133
|
-
addSidebarDataToFrontmatter(pages,
|
|
192
|
+
addSidebarDataToFrontmatter(pages, rootDir);
|
|
134
193
|
}));
|
|
135
194
|
}
|
|
136
195
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SidebarPlugin.js","sourceRoot":"","sources":["../src/SidebarPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,
|
|
1
|
+
{"version":3,"file":"SidebarPlugin.js","sourceRoot":"","sources":["../src/SidebarPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,SAAS,cAAc,CAAC,QAAQ,EAAE,cAAc;IAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;KACzE;IACD,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;QAC/B,OAAO,GAAG,QAAQ,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1C;IACD,OAAO,GAAG,QAAQ,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AACpD,CAAC;AAED,SAAS,YAAY,CAAC,IAAI;IACxB,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,eAAe,CAAC,KAAK,EAAE,KAAK;IACnC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CAAC;YAC1C,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC;YACxD,MAAM,QAAQ,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;YACvC,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACpD,MAAM,eAAe,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;YACzD,0BAA0B,CAAC,eAAe,CAAC,CAAC;YAC5C,MAAM,iBAAiB,CAAC,QAAQ,CAAC,SAAS,CACxC,eAAe,EACf,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAC3C,CAAC;YACF,2BAA2B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC9C,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAC;AACJ,eAAe,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jpmorganchase/mosaic-plugins",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.26",
|
|
4
4
|
"author": "",
|
|
5
5
|
"description": "Mosaic plugins for core file system",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|
|
16
|
-
"node": "
|
|
16
|
+
"node": ">=16.10.0 || >=18.0.0"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|
|
@@ -33,25 +33,29 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@apidevtools/json-schema-ref-parser": "^9.0.9",
|
|
36
|
-
"@jpmorganchase/mosaic-schemas": "^0.1.0-beta.
|
|
37
|
-
"@jpmorganchase/mosaic-serialisers": "^0.1.0-beta.
|
|
38
|
-
"@jpmorganchase/mosaic-source-git-repo": "^0.1.0-beta.
|
|
39
|
-
"@jpmorganchase/mosaic-source-local-folder": "^0.1.0-beta.
|
|
40
|
-
"@jpmorganchase/mosaic-types": "^0.1.0-beta.
|
|
36
|
+
"@jpmorganchase/mosaic-schemas": "^0.1.0-beta.26",
|
|
37
|
+
"@jpmorganchase/mosaic-serialisers": "^0.1.0-beta.26",
|
|
38
|
+
"@jpmorganchase/mosaic-source-git-repo": "^0.1.0-beta.26",
|
|
39
|
+
"@jpmorganchase/mosaic-source-local-folder": "^0.1.0-beta.26",
|
|
40
|
+
"@jpmorganchase/mosaic-types": "^0.1.0-beta.26",
|
|
41
41
|
"@types/github-slugger": "^1.3.0",
|
|
42
42
|
"@vcarl/remark-headings": "^0.1.0",
|
|
43
|
+
"check-links": "^2.0.0",
|
|
43
44
|
"fs-extra": "^10.1.0",
|
|
44
45
|
"github-slugger": "^1.4.0",
|
|
46
|
+
"https-proxy-agent": "^5.0.1",
|
|
45
47
|
"lodash-es": "^4.17.21",
|
|
46
48
|
"memfs": "^3.4.12",
|
|
47
49
|
"react-pro-sidebar": "^1.0.0",
|
|
48
50
|
"reading-time": "^1.5.0",
|
|
51
|
+
"remark": "^14.0.2",
|
|
49
52
|
"remark-mdx": "^2.1.5",
|
|
50
53
|
"remark-parse": "^10.0.1",
|
|
51
54
|
"remark-stringify": "^10.0.2",
|
|
52
55
|
"rxjs": "^7.5.5",
|
|
53
56
|
"unified": "^10.1.2",
|
|
54
57
|
"unist-util-visit": "^4.1.1",
|
|
55
|
-
"uuid": "^7.0.3"
|
|
58
|
+
"uuid": "^7.0.3",
|
|
59
|
+
"vfile-reporter": "^7.0.5"
|
|
56
60
|
}
|
|
57
61
|
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
-
interface NextPrevPluginPage extends Page {
|
|
3
|
-
nextPrev: {
|
|
4
|
-
[key: string]: string[];
|
|
5
|
-
};
|
|
6
|
-
refs: {
|
|
7
|
-
[key: string]: {
|
|
8
|
-
$$path: (number | string)[];
|
|
9
|
-
$$value: string;
|
|
10
|
-
}[];
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
interface NextPrevPluginOptions {
|
|
14
|
-
indexFirst?: boolean;
|
|
15
|
-
sortBy?: string;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Sorts the pages in a folder alphabetically and then embeds a `navigation` property to the metadata with ordered
|
|
19
|
-
* next/prev pages
|
|
20
|
-
*/
|
|
21
|
-
declare const NextPrevPlugin: PluginType<NextPrevPluginPage, NextPrevPluginOptions>;
|
|
22
|
-
export default NextPrevPlugin;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { escapeRegExp } from 'lodash-es';
|
|
2
|
-
function createFileGlob(url, pageExtensions) {
|
|
3
|
-
if (pageExtensions.length === 1) {
|
|
4
|
-
return `${url}${pageExtensions[0]}`;
|
|
5
|
-
}
|
|
6
|
-
return `${url}{${pageExtensions.join(',')}}`;
|
|
7
|
-
}
|
|
8
|
-
function createSortFn(pageExtensions, { sortBy: _sortBy, indexFirst }) {
|
|
9
|
-
const indexRegExp = indexFirst && new RegExp(`index${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
10
|
-
// TODO: Switch out the algorithm here, based on `sortBy`
|
|
11
|
-
return function sortFn(fullPathA, fullPathB) {
|
|
12
|
-
// Always pin /index to the front
|
|
13
|
-
if (indexFirst && indexRegExp.test(fullPathA)) {
|
|
14
|
-
return -1;
|
|
15
|
-
}
|
|
16
|
-
return fullPathA.localeCompare(fullPathB);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Sorts the pages in a folder alphabetically and then embeds a `navigation` property to the metadata with ordered
|
|
21
|
-
* next/prev pages
|
|
22
|
-
*/
|
|
23
|
-
const NextPrevPlugin = {
|
|
24
|
-
async $beforeSend(mutableFilesystem, { config, pageExtensions, ignorePages }, { indexFirst, sortBy }) {
|
|
25
|
-
const pageDirs = (await mutableFilesystem.promises.glob('**', {
|
|
26
|
-
onlyDirectories: true,
|
|
27
|
-
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
28
|
-
cwd: '/'
|
|
29
|
-
}));
|
|
30
|
-
for (const dirName of pageDirs) {
|
|
31
|
-
const pages = (await mutableFilesystem.promises.glob(createFileGlob('*', pageExtensions), {
|
|
32
|
-
onlyFiles: true,
|
|
33
|
-
cwd: dirName,
|
|
34
|
-
ignore: ignorePages
|
|
35
|
-
})).sort(createSortFn(pageExtensions, { indexFirst, sortBy }));
|
|
36
|
-
for (let i = 0; i < pages.length; i++) {
|
|
37
|
-
if (i > 0) {
|
|
38
|
-
config.setRef(pages[i], ['navigation', 'prev', 'title', '$ref'], `${pages[i - 1]}#/title`);
|
|
39
|
-
config.setRef(pages[i], ['navigation', 'prev', 'fullPath', '$ref'], `${pages[i - 1]}#/route`);
|
|
40
|
-
}
|
|
41
|
-
if (i < pages.length - 1) {
|
|
42
|
-
config.setRef(pages[i], ['navigation', 'next', 'title', '$ref'], `${pages[i + 1]}#/title`);
|
|
43
|
-
config.setRef(pages[i], ['navigation', 'next', 'fullPath', '$ref'], `${pages[i + 1]}#/route`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
export default NextPrevPlugin;
|
|
50
|
-
//# sourceMappingURL=NextPrevPagePlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NextPrevPagePlugin.js","sourceRoot":"","sources":["../src/NextPrevPagePlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,SAAS,cAAc,CAAC,GAAG,EAAE,cAAc;IACzC,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;QAC/B,OAAO,GAAG,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,E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