@jpmorganchase/mosaic-plugins 0.1.0-beta.4 → 0.1.0-beta.40
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 +43 -63
- package/dist/$AliasPlugin.js.map +1 -1
- package/dist/$CodeModPlugin.d.ts +7 -0
- package/dist/$CodeModPlugin.js +19 -37
- package/dist/$CodeModPlugin.js.map +1 -1
- package/dist/$RefPlugin.d.ts +31 -0
- package/dist/$RefPlugin.js +108 -128
- package/dist/$RefPlugin.js.map +1 -1
- package/dist/$TagPlugin.d.ts +28 -0
- package/dist/$TagPlugin.js +49 -74
- package/dist/$TagPlugin.js.map +1 -1
- package/dist/BreadcrumbsPlugin.d.ts +18 -0
- package/dist/BreadcrumbsPlugin.js +23 -33
- 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 +86 -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/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 +18 -36
- package/dist/PagesWithoutFileExtPlugin.js.map +1 -1
- package/dist/PropsTablePlugin.d.ts +6 -0
- package/dist/PropsTablePlugin.js +80 -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 +13 -0
- package/dist/SharedConfigPlugin.js +25 -41
- package/dist/SharedConfigPlugin.js.map +1 -1
- package/dist/SidebarPlugin.d.ts +38 -0
- package/dist/SidebarPlugin.js +191 -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/normaliseRefs.d.ts +1 -0
- package/dist/utils/normaliseRefs.js +52 -69
- package/dist/utils/normaliseRefs.js.map +1 -1
- package/package.json +41 -15
- package/CHANGELOG.md +0 -42
- package/dist/NextPrevPagePlugin.js +0 -59
- 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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AAM,mBAAmB,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC/F,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;QACnC,MAAM,YAAY,GAAG;YACnB,GAAG,uBAAuB;YAC1B,GAAG,SAAS;YACZ,IAAI;SACL,CAAC;QACF,MAAM,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;QAC/F,MAAM,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;QAC3F,MAAM,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CACvC,6BAA6B,EAC7B,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACpC,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
interface SharedConfigPluginPage extends Page {
|
|
3
|
+
sharedConfig?: string;
|
|
4
|
+
}
|
|
5
|
+
interface SharedConfigPluginOptions {
|
|
6
|
+
filename: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Plugin that crawls the page hierarchy to find the closest `sharedConfig` from any parent index's page metadata.
|
|
10
|
+
* It then exports a JSON file (name: `options.filename`) into each directory with the merged config for that level
|
|
11
|
+
*/
|
|
12
|
+
declare const SharedConfigPlugin: PluginType<SharedConfigPluginPage, SharedConfigPluginOptions>;
|
|
13
|
+
export default SharedConfigPlugin;
|
|
@@ -1,50 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const flatten_1 = __importDefault(require("lodash/flatten"));
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
1
|
+
import { flatten } from 'lodash-es';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
function createFileGlob(url, pageExtensions) {
|
|
4
|
+
if (pageExtensions.length === 1) {
|
|
5
|
+
return `${url}${pageExtensions[0]}`;
|
|
6
|
+
}
|
|
7
|
+
return `${url}{${pageExtensions.join(',')}}`;
|
|
8
|
+
}
|
|
17
9
|
/**
|
|
18
10
|
* Plugin that crawls the page hierarchy to find the closest `sharedConfig` from any parent index's page metadata.
|
|
19
11
|
* It then exports a JSON file (name: `options.filename`) into each directory with the merged config for that level
|
|
20
12
|
*/
|
|
21
13
|
const SharedConfigPlugin = {
|
|
22
|
-
$beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, options) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
cwd: '/'
|
|
27
|
-
});
|
|
28
|
-
for (const pagePath of pagePaths) {
|
|
29
|
-
const sharedConfigFile = path_1.default.join(path_1.default.dirname(String(pagePath)), options.filename);
|
|
30
|
-
const page = yield serialiser.deserialise(String(pagePath), yield mutableFilesystem.promises.readFile(String(pagePath)));
|
|
31
|
-
if (page.sharedConfig) {
|
|
32
|
-
config.setRef(sharedConfigFile, ['config', '$ref'], `${String(pagePath)}#/sharedConfig`);
|
|
33
|
-
yield mutableFilesystem.promises.writeFile(sharedConfigFile, '{}');
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
const baseDir = path_1.default.resolve(path_1.default.dirname(String(pagePath)), '../');
|
|
37
|
-
config.setAliases(path_1.default.join(baseDir, options.filename), [sharedConfigFile]);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
14
|
+
async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, options) {
|
|
15
|
+
const pagePaths = await mutableFilesystem.promises.glob(createFileGlob('**/index', pageExtensions), {
|
|
16
|
+
ignore: [options.filename, ...flatten(ignorePages.map(ignore => [ignore, `**/${ignore}`]))],
|
|
17
|
+
cwd: '/'
|
|
40
18
|
});
|
|
19
|
+
for (const pagePath of pagePaths) {
|
|
20
|
+
const sharedConfigFile = path.posix.join(path.dirname(String(pagePath)), options.filename);
|
|
21
|
+
const page = await serialiser.deserialise(String(pagePath), await mutableFilesystem.promises.readFile(String(pagePath)));
|
|
22
|
+
if (page.sharedConfig) {
|
|
23
|
+
config.setRef(sharedConfigFile, ['config', '$ref'], `${String(pagePath)}#/sharedConfig`);
|
|
24
|
+
await mutableFilesystem.promises.writeFile(sharedConfigFile, '{}');
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const baseDir = path.posix.resolve(path.dirname(String(pagePath)), '../');
|
|
28
|
+
config.setAliases(path.join(baseDir, options.filename), [sharedConfigFile]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
41
31
|
}
|
|
42
32
|
};
|
|
43
|
-
|
|
44
|
-
function createFileGlob(url, pageExtensions) {
|
|
45
|
-
if (pageExtensions.length === 1) {
|
|
46
|
-
return `${url}${pageExtensions[0]}`;
|
|
47
|
-
}
|
|
48
|
-
return `${url}{${pageExtensions.join(',')}}`;
|
|
49
|
-
}
|
|
33
|
+
export default SharedConfigPlugin;
|
|
50
34
|
//# 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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AC;YACF,IAAI,IAAI,CAAC,YAAY,EAAE;gBACrB,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;gBACzF,MAAM,iBAAiB,CAAC,QAAQ,CAAC,SAAS,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;aACpE;iBAAM;gBACL,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;gBAE1E,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;aAC7E;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
|
+
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;
|
package/dist/SidebarPlugin.js
CHANGED
|
@@ -1,109 +1,205 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { cloneDeep } from 'lodash-es';
|
|
3
|
+
function createFileGlob(patterns, pageExtensions) {
|
|
4
|
+
if (Array.isArray(patterns)) {
|
|
5
|
+
return patterns.map(pattern => createFileGlob(pattern, pageExtensions));
|
|
6
|
+
}
|
|
7
|
+
if (pageExtensions.length === 1) {
|
|
8
|
+
return `${patterns}${pageExtensions[0]}`;
|
|
9
|
+
}
|
|
10
|
+
return `${patterns}{${pageExtensions.join(',')}}`;
|
|
11
|
+
}
|
|
12
|
+
function getPageLevel(page) {
|
|
13
|
+
return page.route.split('/').length - 2;
|
|
14
|
+
}
|
|
15
|
+
function sortByPathLevel(pathA, pathB) {
|
|
16
|
+
const pathALevel = pathA.split('/').length;
|
|
17
|
+
const pathBLevel = pathB.split('/').length;
|
|
18
|
+
return pathBLevel - pathALevel;
|
|
19
|
+
}
|
|
16
20
|
/**
|
|
17
|
-
* 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
|
|
18
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
|
|
19
28
|
*/
|
|
20
29
|
const SidebarPlugin = {
|
|
21
|
-
$beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions },
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
async $beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, { filename = 'sidebar.json', rootDirGlob = '*' }) {
|
|
31
|
+
/**
|
|
32
|
+
* Create a list of pages that should be used to build a sidebar.json
|
|
33
|
+
* @param dirName - root path of sidebar
|
|
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),
|
|
42
|
+
ignore: ignorePages.map(ignore => `**/${ignore}`)
|
|
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
|
+
}));
|
|
50
|
+
return pageList;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Group the pages into parent/child hierachy
|
|
54
|
+
* @param pages - sidebar pages
|
|
55
|
+
*/
|
|
56
|
+
function createGroupMap(pages) {
|
|
57
|
+
return pages.reduce((result, page) => {
|
|
58
|
+
const name = page.sidebar?.label || page.title;
|
|
59
|
+
const priority = page.sidebar?.priority;
|
|
60
|
+
const id = page.route;
|
|
61
|
+
const isGroup = /\/index$/.test(page.route);
|
|
62
|
+
const groupPath = path.posix.dirname(page.fullPath);
|
|
63
|
+
const level = getPageLevel(page);
|
|
64
|
+
const newChildNode = {
|
|
65
|
+
id,
|
|
66
|
+
fullPath: page.fullPath,
|
|
67
|
+
name,
|
|
68
|
+
priority,
|
|
69
|
+
data: { level, link: page.route },
|
|
70
|
+
childNodes: []
|
|
71
|
+
};
|
|
72
|
+
if (isGroup) {
|
|
73
|
+
result[groupPath] = {
|
|
74
|
+
...newChildNode,
|
|
75
|
+
...result[groupPath]
|
|
76
|
+
};
|
|
42
77
|
}
|
|
43
|
-
|
|
78
|
+
else {
|
|
79
|
+
const childNodes = Object.prototype.hasOwnProperty.call(result, groupPath)
|
|
80
|
+
? result[groupPath].childNodes
|
|
81
|
+
: [];
|
|
82
|
+
result[groupPath] = {
|
|
83
|
+
...result[groupPath],
|
|
84
|
+
childNodes: [...childNodes, newChildNode]
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}, {});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Link the group map to their parents
|
|
92
|
+
* @param groupMap - unlinked groups of pages
|
|
93
|
+
* @param dirName - root path of sidebar
|
|
94
|
+
*/
|
|
95
|
+
function linkGroupMap(groupMap, dirName) {
|
|
96
|
+
const linkedGroupMap = cloneDeep(groupMap);
|
|
97
|
+
const sortedGroupMapKeys = Object.keys(linkedGroupMap).sort(sortByPathLevel);
|
|
98
|
+
sortedGroupMapKeys.forEach(groupPath => {
|
|
99
|
+
let parentGroupPath = path.posix.dirname(groupPath);
|
|
100
|
+
if (linkedGroupMap[parentGroupPath] === undefined) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
linkedGroupMap[parentGroupPath].childNodes = [
|
|
104
|
+
...linkedGroupMap[parentGroupPath].childNodes,
|
|
105
|
+
linkedGroupMap[groupPath]
|
|
106
|
+
];
|
|
107
|
+
});
|
|
108
|
+
return [linkedGroupMap[dirName]];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Link each page to a sidebar.json file via ref
|
|
112
|
+
* @param pages - sidebar pages
|
|
113
|
+
* @param dirName - root path of sidebar
|
|
114
|
+
*/
|
|
115
|
+
function addSidebarDataToFrontmatter(pages, dirName) {
|
|
116
|
+
pages.forEach(page => {
|
|
117
|
+
config.setRef(String(page.fullPath), ['sidebarData', '$ref'], path.posix.join(dirName, filename, '#', 'pages'));
|
|
118
|
+
});
|
|
119
|
+
}
|
|
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`);
|
|
44
124
|
}
|
|
45
|
-
|
|
46
|
-
config.setRef(
|
|
47
|
-
|
|
48
|
-
? config.setRef(sidebarFilePath, ['pages', `${i}`, 'name', '$ref'], `${page.fullPath}#/sidebar/label`)
|
|
49
|
-
: config.setRef(sidebarFilePath, ['pages', `${i}`, 'name', '$ref'], `${page.fullPath}#/title`);
|
|
50
|
-
config.setRef(sidebarFilePath, ['pages', `${i}`, 'data', 'link', '$ref'], `${page.fullPath}#/route`);
|
|
125
|
+
if (nextPage) {
|
|
126
|
+
config.setRef(currPage, ['navigation', 'next', 'title', '$ref'], `${nextPage}#/title`);
|
|
127
|
+
config.setRef(currPage, ['navigation', 'next', 'route', '$ref'], `${nextPage}#/route`);
|
|
51
128
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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;
|
|
69
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
|
+
if (currPage !== undefined) {
|
|
159
|
+
createNavigationRefs(currPage, prevPage, nextPage);
|
|
160
|
+
}
|
|
161
|
+
recursiveAddNavigation(page.childNodes);
|
|
70
162
|
});
|
|
71
163
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
164
|
+
recursiveAddNavigation(pages);
|
|
165
|
+
}
|
|
166
|
+
const rootUserJourneys = await mutableFilesystem.promises.glob(rootDirGlob, {
|
|
167
|
+
onlyDirectories: true,
|
|
168
|
+
extglob: true,
|
|
169
|
+
cwd: '/'
|
|
79
170
|
});
|
|
171
|
+
const removeExcludedPages = page => !(page.sidebar && page.sidebar.exclude);
|
|
172
|
+
function sortPagesByPriority(sidebarData) {
|
|
173
|
+
const pagesByPriority = sidebarData.map(page => {
|
|
174
|
+
if (page.childNodes?.length > 1) {
|
|
175
|
+
const pagesByPriority = page.childNodes.sort((pageA, pageB) => (pageB.priority ? pageB.priority : -1) - (pageA.priority ? pageA.priority : -1));
|
|
176
|
+
sortPagesByPriority(page.childNodes);
|
|
177
|
+
return { ...page, childNodes: pagesByPriority };
|
|
178
|
+
}
|
|
179
|
+
return page;
|
|
180
|
+
});
|
|
181
|
+
return pagesByPriority;
|
|
182
|
+
}
|
|
183
|
+
function moveRootPageDown(pagesByPriority) {
|
|
184
|
+
const rootPage = pagesByPriority[0];
|
|
185
|
+
const pagesWithRootMovedDown = rootPage.childNodes;
|
|
186
|
+
pagesWithRootMovedDown.unshift(rootPage);
|
|
187
|
+
rootPage.childNodes = [];
|
|
188
|
+
return pagesWithRootMovedDown;
|
|
189
|
+
}
|
|
190
|
+
await Promise.all(rootUserJourneys.map(async (rootDir) => {
|
|
191
|
+
const sidebarFilePath = path.posix.join(String(rootDir), filename);
|
|
192
|
+
let pages = await createPageList(rootDir);
|
|
193
|
+
pages = pages.filter(page => removeExcludedPages(page));
|
|
194
|
+
const groupMap = createGroupMap(pages);
|
|
195
|
+
const sidebarData = linkGroupMap(groupMap, rootDir);
|
|
196
|
+
const pagesByPriority = sortPagesByPriority(sidebarData);
|
|
197
|
+
addNavigationToFrontmatter(pagesByPriority);
|
|
198
|
+
const pagesWithRootMovedDown = moveRootPageDown(pagesByPriority);
|
|
199
|
+
await mutableFilesystem.promises.writeFile(sidebarFilePath, JSON.stringify({ pages: pagesWithRootMovedDown }));
|
|
200
|
+
addSidebarDataToFrontmatter(pages, rootDir);
|
|
201
|
+
}));
|
|
80
202
|
}
|
|
81
203
|
};
|
|
82
|
-
|
|
83
|
-
function createFileGlob(patterns, pageExtensions) {
|
|
84
|
-
if (Array.isArray(patterns)) {
|
|
85
|
-
return patterns.map(pattern => createFileGlob(pattern, pageExtensions));
|
|
86
|
-
}
|
|
87
|
-
if (pageExtensions.length === 1) {
|
|
88
|
-
return `${patterns}${pageExtensions[0]}`;
|
|
89
|
-
}
|
|
90
|
-
return `${patterns}{${pageExtensions.join(',')}}`;
|
|
91
|
-
}
|
|
92
|
-
function isSubfolderIndex(page, dirName) {
|
|
93
|
-
return page.fullPath.split('/').length == String(dirName).split('/').length + 2;
|
|
94
|
-
}
|
|
95
|
-
function sortFn(pageA, pageB, dirName) {
|
|
96
|
-
// Always pin /index to the front
|
|
97
|
-
if (pageA.route === dirName + '/index') {
|
|
98
|
-
return -1;
|
|
99
|
-
}
|
|
100
|
-
if (pageB.route === dirName + '/index') {
|
|
101
|
-
return 1;
|
|
102
|
-
}
|
|
103
|
-
return ((pageB.sidebar && pageB.sidebar.priority ? pageB.sidebar.priority : -1) -
|
|
104
|
-
(pageA.sidebar && pageA.sidebar.priority ? pageA.sidebar.priority : -1));
|
|
105
|
-
}
|
|
106
|
-
function filterFn(page) {
|
|
107
|
-
return !(page.sidebar && page.sidebar.exclude);
|
|
108
|
-
}
|
|
204
|
+
export default SidebarPlugin;
|
|
109
205
|
//# sourceMappingURL=SidebarPlugin.js.map
|