@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
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import markdown from 'remark-parse';
|
|
3
|
+
import remarkMdx from 'remark-mdx';
|
|
4
|
+
import { visit } from 'unist-util-visit';
|
|
5
|
+
const defaultRelevancyOptions = {
|
|
6
|
+
includeScore: true,
|
|
7
|
+
includeMatches: true,
|
|
8
|
+
maxPatternLength: 240,
|
|
9
|
+
ignoreLocation: true,
|
|
10
|
+
threshold: 0.3
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* We need these keys to *always* be included in the search index.
|
|
14
|
+
* Without the title, there would be no way to display the search results.
|
|
15
|
+
* Without the route, there would be no way to navigate to the page.
|
|
16
|
+
*/
|
|
17
|
+
const requiredKeys = ['title', 'route'];
|
|
18
|
+
/**
|
|
19
|
+
* If there are no keys specified in the plugin options, we'll use these
|
|
20
|
+
*/
|
|
21
|
+
const fallbackKeys = [...requiredKeys, 'content'];
|
|
22
|
+
/**
|
|
23
|
+
* There are three scenarios for the "keys":
|
|
24
|
+
*
|
|
25
|
+
* 1. No keys are specified in the plugin options. In this case, we'll use the fallback keys.
|
|
26
|
+
* 2. The keys are specified as an array of strings. In this case, we'll add the required keys to the array.
|
|
27
|
+
* 3. The keys are specified as an array of objects. In this case, we can assume "weighting" is being applied
|
|
28
|
+
* so we'll only return the keys that have been specified in the options.
|
|
29
|
+
*
|
|
30
|
+
* @param optionKeys array of keys specified in the plugin options
|
|
31
|
+
* @returns array of keys to be used in the search index
|
|
32
|
+
*/
|
|
33
|
+
export function parseKeys(optionKeys = []) {
|
|
34
|
+
if (optionKeys.length < 1)
|
|
35
|
+
return fallbackKeys;
|
|
36
|
+
if (typeof optionKeys[0] === 'string')
|
|
37
|
+
return [...requiredKeys, ...optionKeys];
|
|
38
|
+
return optionKeys;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Converts raw content string into an array of sentences suitable for inclusion
|
|
42
|
+
* in the search index
|
|
43
|
+
*
|
|
44
|
+
* @param options.content the raw content string
|
|
45
|
+
* @param options.title the title of the page (used for adding context to parse errors)
|
|
46
|
+
* @param options.maxLineLength the maximum length of a sentence (set this to match the
|
|
47
|
+
* "location" option in your Fuse.js configuration). Sentences longer than this value will be
|
|
48
|
+
* truncated.
|
|
49
|
+
* @param options.maxLineCount the maximum number of lines to include in the search index for
|
|
50
|
+
* each page. Pages with more lines than this value will be truncated.
|
|
51
|
+
* @returns array of sentence strings
|
|
52
|
+
*/
|
|
53
|
+
export const optimizeContentForSearch = async ({ content: rawContent, title, maxLineLength, maxLineCount }) => {
|
|
54
|
+
// Normalize line endings
|
|
55
|
+
const content = rawContent.replaceAll('\r', '');
|
|
56
|
+
if (!content || content.length < 1)
|
|
57
|
+
return [content];
|
|
58
|
+
const processor = unified().use(markdown).use(remarkMdx);
|
|
59
|
+
let tree;
|
|
60
|
+
try {
|
|
61
|
+
tree = await processor.parse(content);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
console.error(`Search Index Plugin failed to parse content for ${title}`, err.reason);
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
const sentences = [];
|
|
68
|
+
const segmenter = new Intl.Segmenter('en', { granularity: 'sentence' });
|
|
69
|
+
visit(tree, (node) => node.type === 'text' || node.type === 'code', (node) => {
|
|
70
|
+
const segments = [...segmenter.segment(node.value)].map(segment => segment.segment);
|
|
71
|
+
segments.forEach(segment => {
|
|
72
|
+
if (maxLineLength) {
|
|
73
|
+
sentences.push(segment.slice(0, maxLineLength));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
sentences.push(segment);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
if (maxLineCount) {
|
|
81
|
+
return sentences.slice(0, maxLineCount);
|
|
82
|
+
}
|
|
83
|
+
return sentences;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Creates a search-data.json file that contains all the information
|
|
87
|
+
* from each page that is required to generate a search index.
|
|
88
|
+
*/
|
|
89
|
+
const SearchIndexPlugin = {
|
|
90
|
+
/**
|
|
91
|
+
* For each source, parse the data we want to add to the search index and
|
|
92
|
+
* save it to the global config (to be saved to the filesystem later when
|
|
93
|
+
* all sources have been loaded).
|
|
94
|
+
*/
|
|
95
|
+
async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages }, { maxLineLength, maxLineCount, keys: optionKeys }) {
|
|
96
|
+
const pages = await Promise.all((await mutableFilesystem.promises.glob('**', {
|
|
97
|
+
onlyFiles: true,
|
|
98
|
+
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
99
|
+
cwd: '/'
|
|
100
|
+
})).map(async (pagePath) => {
|
|
101
|
+
const deserialisedPage = await serialiser.deserialise(pagePath, await mutableFilesystem.promises.readFile(pagePath));
|
|
102
|
+
return deserialisedPage;
|
|
103
|
+
}));
|
|
104
|
+
const searchData = await Promise.all(pages.map(async (page) => {
|
|
105
|
+
const content = await optimizeContentForSearch({
|
|
106
|
+
content: page.content || '',
|
|
107
|
+
title: page.title || '',
|
|
108
|
+
maxLineLength,
|
|
109
|
+
maxLineCount
|
|
110
|
+
});
|
|
111
|
+
const keys = parseKeys(optionKeys);
|
|
112
|
+
/**
|
|
113
|
+
* If the "content" key is specified, we want to include the result of
|
|
114
|
+
* the optimizeContentForSearch() function. Otherwise, we include the
|
|
115
|
+
* key value directly from the page data.
|
|
116
|
+
*/
|
|
117
|
+
return keys.reduce((acc, key) => ({ ...acc, [key]: key === 'content' ? content : page[key] }), {});
|
|
118
|
+
}));
|
|
119
|
+
/**
|
|
120
|
+
* Convert the searchData into an object where each page has a unique key (the
|
|
121
|
+
* route) so that the "merge" in `config.setData()` will correctly combine all
|
|
122
|
+
* the results from multiple sources.
|
|
123
|
+
*/
|
|
124
|
+
const searchDataKeyedByRoute = searchData.reduce((acc, curr) => ({
|
|
125
|
+
...acc,
|
|
126
|
+
[curr.route]: curr
|
|
127
|
+
}), {});
|
|
128
|
+
config.setData({
|
|
129
|
+
searchIndices: searchDataKeyedByRoute
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
/**
|
|
133
|
+
* Once we have all the sources' search data added to `globalConfig`, convert it
|
|
134
|
+
* to JSON and save it to the filesystem.
|
|
135
|
+
*/
|
|
136
|
+
async afterUpdate(_, { sharedFilesystem, globalConfig }, { keys: optionKeys, relevancy }) {
|
|
137
|
+
if (!globalConfig.data.searchIndices)
|
|
138
|
+
return;
|
|
139
|
+
const globalSearchIndices = globalConfig.data.searchIndices;
|
|
140
|
+
const searchData = Object.values(globalSearchIndices);
|
|
141
|
+
const condensedSearchData = searchData.map(page => ({ title: page.title, route: page.route }));
|
|
142
|
+
const keys = parseKeys(optionKeys);
|
|
143
|
+
const searchConfig = {
|
|
144
|
+
...defaultRelevancyOptions,
|
|
145
|
+
...relevancy,
|
|
146
|
+
keys
|
|
147
|
+
};
|
|
148
|
+
await sharedFilesystem.promises.writeFile('/search-config.json', JSON.stringify(searchConfig));
|
|
149
|
+
await sharedFilesystem.promises.writeFile('/search-data.json', JSON.stringify(searchData));
|
|
150
|
+
await sharedFilesystem.promises.writeFile('/search-data-condensed.json', JSON.stringify(condensedSearchData));
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
export default SearchIndexPlugin;
|
|
154
|
+
//# sourceMappingURL=SearchIndexPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchIndexPlugin.js","sourceRoot":"","sources":["../src/SearchIndexPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,QAAQ,MAAM,cAAc,CAAC;AACpC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAqCzC,MAAM,uBAAuB,GAAG;IAC9B,YAAY,EAAE,IAAI;IAClB,cAAc,EAAE,IAAI;IACpB,gBAAgB,EAAE,GAAG;IACrB,cAAc,EAAE,IAAI;IACpB,SAAS,EAAE,GAAG;CACf,CAAC;AAEF;;;;GAIG;AACH,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,YAAY,GAAG,CAAC,GAAG,YAAY,EAAE,SAAS,CAAC,CAAC;AAElD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAAC,UAAU,GAAG,EAAE;IACvC,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,YAAY,CAAC;IAC/C,IAAI,OAAO,UAAU,CAAC,CAAC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,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC/F,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;QACnC,MAAM,YAAY,GAAG;YACnB,GAAG,uBAAuB;YAC1B,GAAG,SAAS;YACZ,IAAI;SACL,CAAC;QACF,MAAM,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;QAC/F,MAAM,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;QAC3F,MAAM,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CACvC,6BAA6B,EAC7B,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACpC,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
export interface SharedConfigPluginPage extends Page {
|
|
3
|
+
sharedConfig?: string;
|
|
4
|
+
frameOverrides?: any;
|
|
5
|
+
}
|
|
6
|
+
export interface SharedConfigPluginOptions {
|
|
7
|
+
filename: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Plugin that crawls the page hierarchy to find the closest `sharedConfig` from any parent index's page metadata.
|
|
11
|
+
* It then exports a JSON file (name: `options.filename`) into each directory with the merged config for that level
|
|
12
|
+
*/
|
|
13
|
+
declare const SharedConfigPlugin: PluginType<SharedConfigPluginPage, SharedConfigPluginOptions>;
|
|
14
|
+
export default SharedConfigPlugin;
|
|
@@ -1,50 +1,146 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { flatten, escapeRegExp } from 'lodash-es';
|
|
4
|
+
import deepmerge from 'deepmerge';
|
|
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
|
+
/**
|
|
17
|
+
* https://stackoverflow.com/a/50549047
|
|
18
|
+
* compute inner relative to outer
|
|
19
|
+
* If it's not contained, the first component of the resulting path will be .., so that's what we check for
|
|
20
|
+
*/
|
|
21
|
+
function isWithin(outer, inner) {
|
|
22
|
+
const outerParentDir = path.posix.resolve(path.posix.dirname(outer), '../');
|
|
23
|
+
const innerParentDir = path.posix.resolve(path.posix.dirname(inner), '../');
|
|
24
|
+
const rel = path.posix.relative(outerParentDir, innerParentDir);
|
|
25
|
+
return !rel.startsWith('../') && rel !== '..';
|
|
26
|
+
}
|
|
17
27
|
/**
|
|
18
28
|
* Plugin that crawls the page hierarchy to find the closest `sharedConfig` from any parent index's page metadata.
|
|
19
29
|
* It then exports a JSON file (name: `options.filename`) into each directory with the merged config for that level
|
|
20
30
|
*/
|
|
21
31
|
const SharedConfigPlugin = {
|
|
22
|
-
$
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
async $afterSource(pages, { ignorePages, pageExtensions, config, namespace }) {
|
|
33
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
34
|
+
let finalSharedConfig;
|
|
35
|
+
const indexPages = pages.filter(page => path.posix.basename(page.fullPath, path.posix.extname(page.fullPath)) === 'index' &&
|
|
36
|
+
isNonHiddenPage(page.fullPath));
|
|
37
|
+
const indexPagesWithSharedConfig = indexPages.filter(page => page.sharedConfig !== undefined);
|
|
38
|
+
if (indexPagesWithSharedConfig.length === 0 && indexPages.length > 0) {
|
|
39
|
+
const rootPath = indexPages[0].fullPath;
|
|
40
|
+
const applyNamespaceSharedConfig = {
|
|
41
|
+
[`${crypto.randomUUID()}`]: {
|
|
42
|
+
paths: indexPages.map(indexPage => indexPage.fullPath),
|
|
43
|
+
rootPath,
|
|
44
|
+
namespace
|
|
34
45
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
};
|
|
47
|
+
config.setData({ applyNamespaceSharedConfig });
|
|
48
|
+
return pages;
|
|
49
|
+
}
|
|
50
|
+
for (const page of indexPagesWithSharedConfig) {
|
|
51
|
+
if (finalSharedConfig === undefined) {
|
|
52
|
+
// first shared config we have found so seed the finalSharedConfig
|
|
53
|
+
finalSharedConfig = page.sharedConfig;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
for (let i = 1; i < indexPagesWithSharedConfig.length; i++) {
|
|
57
|
+
if (isWithin(indexPagesWithSharedConfig[i].fullPath, page.fullPath)) {
|
|
58
|
+
// found another shared config so merge and apply to the page
|
|
59
|
+
finalSharedConfig = deepmerge(finalSharedConfig, page.sharedConfig);
|
|
60
|
+
page.sharedConfig = finalSharedConfig;
|
|
61
|
+
page.frameOverrides = { $ref: '#/sharedConfig' };
|
|
62
|
+
}
|
|
38
63
|
}
|
|
39
64
|
}
|
|
65
|
+
}
|
|
66
|
+
return pages;
|
|
67
|
+
},
|
|
68
|
+
async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, options) {
|
|
69
|
+
const indexPagePaths = await mutableFilesystem.promises.glob(createFileGlob('**/index', pageExtensions), {
|
|
70
|
+
ignore: [options.filename, ...flatten(ignorePages.map(ignore => [ignore, `**/${ignore}`]))],
|
|
71
|
+
cwd: '/'
|
|
40
72
|
});
|
|
73
|
+
const sharedConfigFiles = [];
|
|
74
|
+
const indexPagesWithoutConfig = [];
|
|
75
|
+
for (const indexPagePath of indexPagePaths) {
|
|
76
|
+
const sharedConfigFile = path.posix.join(path.posix.dirname(String(indexPagePath)), options.filename);
|
|
77
|
+
const page = await serialiser.deserialise(String(indexPagePath), await mutableFilesystem.promises.readFile(String(indexPagePath)));
|
|
78
|
+
if (page.sharedConfig) {
|
|
79
|
+
config.setRef(sharedConfigFile, ['config', '$ref'], `${String(indexPagePath)}#/sharedConfig`);
|
|
80
|
+
await mutableFilesystem.promises.writeFile(sharedConfigFile, '{}');
|
|
81
|
+
sharedConfigFiles.push(sharedConfigFile);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
indexPagesWithoutConfig.push(page.fullPath);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// apply closest shared config
|
|
88
|
+
if (sharedConfigFiles.length > 0) {
|
|
89
|
+
let closestSharedConfigIndex = 0;
|
|
90
|
+
for (const pagePath of indexPagesWithoutConfig) {
|
|
91
|
+
for (let i = 0; i < sharedConfigFiles.length; i++) {
|
|
92
|
+
if (isWithin(sharedConfigFiles[i], pagePath)) {
|
|
93
|
+
closestSharedConfigIndex = i;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const sharedConfigFile = path.posix.join(path.posix.dirname(String(pagePath)), options.filename);
|
|
97
|
+
const closestSharedConfig = path.posix.resolve(path.dirname(String(pagePath)), sharedConfigFiles[closestSharedConfigIndex]);
|
|
98
|
+
config.setAliases(closestSharedConfig, [sharedConfigFile]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
async afterUpdate(mutableFilesystem, { sharedFilesystem, globalConfig, namespace }, options) {
|
|
103
|
+
const { applyNamespaceSharedConfig } = globalConfig.data;
|
|
104
|
+
if (applyNamespaceSharedConfig === undefined) {
|
|
105
|
+
// there is no source that exists that has told us it needs to share a namespace shared-config
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
// find all the entries that match the namespace the plugin is running against
|
|
109
|
+
const namespaceSharedConfigs = Object.keys(applyNamespaceSharedConfig)
|
|
110
|
+
.filter(key => applyNamespaceSharedConfig[key].namespace === namespace)
|
|
111
|
+
.map(key => applyNamespaceSharedConfig?.[key] || []);
|
|
112
|
+
for (const namespaceSharedConfig of namespaceSharedConfigs) {
|
|
113
|
+
if (await mutableFilesystem.promises.exists(namespaceSharedConfig.rootPath)) {
|
|
114
|
+
// a source does need a namespace shared config but the source running this plugin is the source that needs it
|
|
115
|
+
// so we don't need to do anything here
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
for (const applyPath of namespaceSharedConfig.paths) {
|
|
119
|
+
if (!(await sharedFilesystem.promises.exists(applyPath))) {
|
|
120
|
+
sharedFilesystem.promises.mkdir(path.posix.dirname(String(applyPath)), {
|
|
121
|
+
recursive: true
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
let parentDir = path.posix.join(path.posix.dirname(String(applyPath)), '../');
|
|
125
|
+
let closestSharedConfigPath = path.posix.join(parentDir, options.filename);
|
|
126
|
+
while (parentDir !== path.posix.sep) {
|
|
127
|
+
// walk up the directories in the path to find the closest shared config file
|
|
128
|
+
closestSharedConfigPath = path.posix.join(parentDir, options.filename);
|
|
129
|
+
if (await mutableFilesystem.promises.exists(closestSharedConfigPath)) {
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
parentDir = path.posix.join(path.posix.dirname(String(closestSharedConfigPath)), '../');
|
|
133
|
+
}
|
|
134
|
+
const aliasSharedConfigPath = path.posix.join(path.posix.dirname(String(applyPath)), options.filename);
|
|
135
|
+
if ((await mutableFilesystem.promises.exists(closestSharedConfigPath)) &&
|
|
136
|
+
!(await sharedFilesystem.promises.exists(aliasSharedConfigPath))) {
|
|
137
|
+
console.log(`[Mosaic][Plugin] Source has no shared config. Root index page is: ${namespaceSharedConfig.rootPath}`);
|
|
138
|
+
console.log('[Mosaic][Plugin] Copying shared config ', closestSharedConfigPath, '-->', aliasSharedConfigPath);
|
|
139
|
+
await sharedFilesystem.promises.writeFile(aliasSharedConfigPath, await mutableFilesystem.promises.readFile(closestSharedConfigPath));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
41
143
|
}
|
|
42
144
|
};
|
|
43
|
-
|
|
44
|
-
function createFileGlob(url, pageExtensions) {
|
|
45
|
-
if (pageExtensions.length === 1) {
|
|
46
|
-
return `${url}${pageExtensions[0]}`;
|
|
47
|
-
}
|
|
48
|
-
return `${url}{${pageExtensions.join(',')}}`;
|
|
49
|
-
}
|
|
145
|
+
export default SharedConfigPlugin;
|
|
50
146
|
//# sourceMappingURL=SharedConfigPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SharedConfigPlugin.js","sourceRoot":"","sources":["../src/SharedConfigPlugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SharedConfigPlugin.js","sourceRoot":"","sources":["../src/SharedConfigPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,SAAS,cAAc,CAAC,WAAW,EAAE,cAAc;IACjD,M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,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CACnE,CAAC;iBACH;aACF;SACF;IACH,CAAC;CACF,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Plugin as PluginType, Page } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
interface SidebarPluginConfigData {
|
|
3
|
+
dirs: string[];
|
|
4
|
+
refs: {
|
|
5
|
+
[key: string]: {
|
|
6
|
+
$$path: (number | string)[];
|
|
7
|
+
$$value: string;
|
|
8
|
+
}[];
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface SidebarPluginPage extends Page {
|
|
12
|
+
sidebar?: {
|
|
13
|
+
label?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
interface SidebarPluginOptions {
|
|
17
|
+
/**
|
|
18
|
+
* filename of the sidebar json, linked to each related page via ref
|
|
19
|
+
*/
|
|
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;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Sorts the pages in a folder by priority and then exports a JSON file with the
|
|
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
|
|
36
|
+
*/
|
|
37
|
+
declare const SidebarPlugin: PluginType<SidebarPluginPage, SidebarPluginOptions, SidebarPluginConfigData>;
|
|
38
|
+
export default SidebarPlugin;
|