@jpmorganchase/mosaic-plugins 0.1.0-beta.8 → 0.1.0-beta.80
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 +49 -228
- package/dist/$AliasPlugin.js.map +1 -1
- package/dist/$CodeModPlugin.d.ts +7 -0
- package/dist/$CodeModPlugin.js +18 -118
- package/dist/$CodeModPlugin.js.map +1 -1
- package/dist/$RefPlugin.d.ts +31 -0
- package/dist/$RefPlugin.js +123 -451
- package/dist/$RefPlugin.js.map +1 -1
- package/dist/$TagPlugin.d.ts +28 -0
- package/dist/$TagPlugin.js +51 -234
- package/dist/$TagPlugin.js.map +1 -1
- package/dist/BreadcrumbsPlugin.d.ts +19 -0
- package/dist/BreadcrumbsPlugin.js +87 -112
- 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 +3 -0
- package/dist/FragmentPlugin.js +61 -0
- package/dist/FragmentPlugin.js.map +1 -0
- package/dist/LazyPagePlugin.d.ts +14 -0
- package/dist/LazyPagePlugin.js +50 -254
- package/dist/LazyPagePlugin.js.map +1 -1
- package/dist/PagesWithoutFileExtPlugin.d.ts +9 -0
- package/dist/PagesWithoutFileExtPlugin.js +20 -118
- 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 +39 -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 +129 -168
- package/dist/SharedConfigPlugin.js.map +1 -1
- package/dist/SidebarPlugin.d.ts +45 -0
- package/dist/SidebarPlugin.js +285 -324
- package/dist/SidebarPlugin.js.map +1 -1
- package/dist/SiteMapPlugin.d.ts +9 -0
- package/dist/SiteMapPlugin.js +23 -91
- package/dist/SiteMapPlugin.js.map +1 -1
- package/dist/TableOfContentsPlugin.d.ts +20 -0
- package/dist/TableOfContentsPlugin.js +44 -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/createPageTest.d.ts +1 -0
- package/dist/utils/createPageTest.js +8 -0
- package/dist/utils/createPageTest.js.map +1 -0
- package/dist/utils/mergePageContent.d.ts +16 -0
- package/dist/utils/mergePageContent.js +23 -0
- package/dist/utils/mergePageContent.js.map +1 -0
- package/dist/utils/normaliseRefs.d.ts +1 -0
- package/dist/utils/normaliseRefs.js +56 -275
- package/dist/utils/normaliseRefs.js.map +1 -1
- package/dist/utils/sortSidebarData.d.ts +29 -0
- package/dist/utils/sortSidebarData.js +47 -0
- package/dist/utils/sortSidebarData.js.map +1 -0
- package/package.json +41 -19
- package/CHANGELOG.md +0 -93
- package/dist/LocalFolderSavePlugin.js +0 -165
- package/dist/LocalFolderSavePlugin.js.map +0 -1
- package/dist/NextPrevPagePlugin.js +0 -173
- package/dist/NextPrevPagePlugin.js.map +0 -1
- package/dist/ReadingTimePlugin.mjs +0 -119
- package/dist/ReadingTimePlugin.mjs.map +0 -1
- package/dist/SearchIndexPlugin.mjs +0 -268
- package/dist/SearchIndexPlugin.mjs.map +0 -1
- package/dist/TableOfContentsPlugin.mjs +0 -131
- package/dist/TableOfContentsPlugin.mjs.map +0 -1
- package/dist/__tests__/BreadcrumbsPlugin.test.js +0 -160
- package/dist/__tests__/BreadcrumbsPlugin.test.js.map +0 -1
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _asyncToGenerator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _defineProperty(obj, key, value) {
|
|
31
|
-
if (key in obj) {
|
|
32
|
-
Object.defineProperty(obj, key, {
|
|
33
|
-
value: value,
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true
|
|
37
|
-
});
|
|
38
|
-
} else {
|
|
39
|
-
obj[key] = value;
|
|
40
|
-
}
|
|
41
|
-
return obj;
|
|
42
|
-
}
|
|
43
|
-
function _objectSpread(target) {
|
|
44
|
-
for(var i = 1; i < arguments.length; i++){
|
|
45
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
46
|
-
var ownKeys = Object.keys(source);
|
|
47
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
48
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
49
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
ownKeys.forEach(function(key) {
|
|
53
|
-
_defineProperty(target, key, source[key]);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return target;
|
|
57
|
-
}
|
|
58
|
-
function ownKeys(object, enumerableOnly) {
|
|
59
|
-
var keys = Object.keys(object);
|
|
60
|
-
if (Object.getOwnPropertySymbols) {
|
|
61
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
62
|
-
if (enumerableOnly) {
|
|
63
|
-
symbols = symbols.filter(function(sym) {
|
|
64
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
keys.push.apply(keys, symbols);
|
|
68
|
-
}
|
|
69
|
-
return keys;
|
|
70
|
-
}
|
|
71
|
-
function _objectSpreadProps(target, source) {
|
|
72
|
-
source = source != null ? source : {};
|
|
73
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
74
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
75
|
-
} else {
|
|
76
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
77
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return target;
|
|
81
|
-
}
|
|
82
|
-
import regeneratorRuntime from "regenerator-runtime";
|
|
83
|
-
import { unified } from "unified";
|
|
84
|
-
import markdown from "remark-parse";
|
|
85
|
-
import remarkMdx from "remark-mdx";
|
|
86
|
-
import { visit } from "unist-util-visit";
|
|
87
|
-
/**
|
|
88
|
-
* Converts raw content string into an array of sentences suitable for inclusion
|
|
89
|
-
* in the search index
|
|
90
|
-
*
|
|
91
|
-
* @param options.content the raw content string
|
|
92
|
-
* @param options.title the title of the page (used for adding context to parse errors)
|
|
93
|
-
* @param options.maxLineLength the maximum length of a sentence (set this to match the
|
|
94
|
-
* "location" option in your Fuse.js configuration). Sentences longer than this value will be
|
|
95
|
-
* truncated.
|
|
96
|
-
* @param options.maxLineCount the maximum number of lines to include in the search index for
|
|
97
|
-
* each page. Pages with more lines than this value will be truncated.
|
|
98
|
-
* @returns array of sentence strings
|
|
99
|
-
*/ var optimizeContentForSearch = function() {
|
|
100
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/ regeneratorRuntime.mark(function _callee(param) {
|
|
101
|
-
var content, title, maxLineLength, maxLineCount, processor, tree, sentences;
|
|
102
|
-
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
|
103
|
-
while(1)switch(_ctx.prev = _ctx.next){
|
|
104
|
-
case 0:
|
|
105
|
-
content = param.content, title = param.title, maxLineLength = param.maxLineLength, maxLineCount = param.maxLineCount;
|
|
106
|
-
if (!(!content || content.length < 1)) {
|
|
107
|
-
_ctx.next = 3;
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
return _ctx.abrupt("return", [
|
|
111
|
-
content
|
|
112
|
-
]);
|
|
113
|
-
case 3:
|
|
114
|
-
processor = unified().use(markdown).use(remarkMdx);
|
|
115
|
-
;
|
|
116
|
-
_ctx.prev = 5;
|
|
117
|
-
_ctx.next = 8;
|
|
118
|
-
return processor.parse(content);
|
|
119
|
-
case 8:
|
|
120
|
-
tree = _ctx.sent;
|
|
121
|
-
_ctx.next = 15;
|
|
122
|
-
break;
|
|
123
|
-
case 11:
|
|
124
|
-
_ctx.prev = 11;
|
|
125
|
-
_ctx.t0 = _ctx["catch"](5);
|
|
126
|
-
console.error("Search Index Plugin failed to parse content for ".concat(title), _ctx.t0.reason);
|
|
127
|
-
return _ctx.abrupt("return", []);
|
|
128
|
-
case 15:
|
|
129
|
-
sentences = [];
|
|
130
|
-
visit(tree, function(node) {
|
|
131
|
-
return node.type === "text" || node.type === "code";
|
|
132
|
-
}, function(node) {
|
|
133
|
-
if (maxLineLength) {
|
|
134
|
-
sentences.push(node.value.slice(0, maxLineLength));
|
|
135
|
-
} else {
|
|
136
|
-
sentences.push(node.value);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
if (!maxLineLength) {
|
|
140
|
-
_ctx.next = 19;
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
return _ctx.abrupt("return", sentences.slice(0, maxLineCount));
|
|
144
|
-
case 19:
|
|
145
|
-
return _ctx.abrupt("return", sentences);
|
|
146
|
-
case 20:
|
|
147
|
-
case "end":
|
|
148
|
-
return _ctx.stop();
|
|
149
|
-
}
|
|
150
|
-
}, _callee, null, [
|
|
151
|
-
[
|
|
152
|
-
5,
|
|
153
|
-
11
|
|
154
|
-
]
|
|
155
|
-
]);
|
|
156
|
-
}));
|
|
157
|
-
return function optimizeContentForSearch(_) {
|
|
158
|
-
return _ref.apply(this, arguments);
|
|
159
|
-
};
|
|
160
|
-
}();
|
|
161
|
-
/**
|
|
162
|
-
* Creates a search-data.json file that contains all the information from a page that is required
|
|
163
|
-
* to generate a search index
|
|
164
|
-
*/ var SearchIndexPlugin = {
|
|
165
|
-
afterUpdate: function afterUpdate(mutableFilesystem, param, param1) {
|
|
166
|
-
var sharedFilesystem = param.sharedFilesystem, serialiser = param.serialiser, ignorePages = param.ignorePages, maxLineLength = param1.maxLineLength, maxLineCount = param1.maxLineCount, keys = param1.keys;
|
|
167
|
-
return _asyncToGenerator(/*#__PURE__*/ regeneratorRuntime.mark(function _callee() {
|
|
168
|
-
var pages, searchData;
|
|
169
|
-
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
|
170
|
-
while(1)switch(_ctx.prev = _ctx.next){
|
|
171
|
-
case 0:
|
|
172
|
-
_ctx.t0 = Promise;
|
|
173
|
-
_ctx.next = 3;
|
|
174
|
-
return mutableFilesystem.promises.glob("**", {
|
|
175
|
-
onlyFiles: true,
|
|
176
|
-
ignore: ignorePages.map(function(ignore) {
|
|
177
|
-
return "**/".concat(ignore);
|
|
178
|
-
}),
|
|
179
|
-
cwd: "/"
|
|
180
|
-
});
|
|
181
|
-
case 3:
|
|
182
|
-
_ctx.t1 = _ctx.sent.map(function() {
|
|
183
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/ regeneratorRuntime.mark(function _callee(pagePath) {
|
|
184
|
-
var deserialisedPage;
|
|
185
|
-
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
|
186
|
-
while(1)switch(_ctx.prev = _ctx.next){
|
|
187
|
-
case 0:
|
|
188
|
-
_ctx.t0 = serialiser;
|
|
189
|
-
_ctx.t1 = pagePath;
|
|
190
|
-
_ctx.next = 4;
|
|
191
|
-
return mutableFilesystem.promises.readFile(pagePath);
|
|
192
|
-
case 4:
|
|
193
|
-
_ctx.t2 = _ctx.sent;
|
|
194
|
-
_ctx.next = 7;
|
|
195
|
-
return _ctx.t0.deserialise.call(_ctx.t0, _ctx.t1, _ctx.t2);
|
|
196
|
-
case 7:
|
|
197
|
-
deserialisedPage = _ctx.sent;
|
|
198
|
-
return _ctx.abrupt("return", deserialisedPage);
|
|
199
|
-
case 9:
|
|
200
|
-
case "end":
|
|
201
|
-
return _ctx.stop();
|
|
202
|
-
}
|
|
203
|
-
}, _callee);
|
|
204
|
-
}));
|
|
205
|
-
return function(pagePath) {
|
|
206
|
-
return _ref.apply(this, arguments);
|
|
207
|
-
};
|
|
208
|
-
}());
|
|
209
|
-
_ctx.next = 6;
|
|
210
|
-
return _ctx.t0.all.call(_ctx.t0, _ctx.t1);
|
|
211
|
-
case 6:
|
|
212
|
-
pages = _ctx.sent;
|
|
213
|
-
_ctx.next = 9;
|
|
214
|
-
return Promise.all(pages.map(function() {
|
|
215
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/ regeneratorRuntime.mark(function _callee(page) {
|
|
216
|
-
var content, defaultResults, extendedResults;
|
|
217
|
-
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
|
218
|
-
while(1)switch(_ctx.prev = _ctx.next){
|
|
219
|
-
case 0:
|
|
220
|
-
_ctx.next = 2;
|
|
221
|
-
return optimizeContentForSearch({
|
|
222
|
-
content: page.content || "",
|
|
223
|
-
title: page.title || "",
|
|
224
|
-
maxLineLength: maxLineLength,
|
|
225
|
-
maxLineCount: maxLineCount
|
|
226
|
-
});
|
|
227
|
-
case 2:
|
|
228
|
-
content = _ctx.sent;
|
|
229
|
-
defaultResults = {
|
|
230
|
-
title: page.title,
|
|
231
|
-
content: content,
|
|
232
|
-
route: page.route
|
|
233
|
-
};
|
|
234
|
-
if (!(keys && keys.length > 0)) {
|
|
235
|
-
_ctx.next = 7;
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
extendedResults = keys.reduce(function(acc, key) {
|
|
239
|
-
return _objectSpreadProps(_objectSpread({}, acc), _defineProperty({}, key, page[key]));
|
|
240
|
-
}, {});
|
|
241
|
-
return _ctx.abrupt("return", _objectSpread({}, defaultResults, extendedResults));
|
|
242
|
-
case 7:
|
|
243
|
-
return _ctx.abrupt("return", defaultResults);
|
|
244
|
-
case 8:
|
|
245
|
-
case "end":
|
|
246
|
-
return _ctx.stop();
|
|
247
|
-
}
|
|
248
|
-
}, _callee);
|
|
249
|
-
}));
|
|
250
|
-
return function(page) {
|
|
251
|
-
return _ref.apply(this, arguments);
|
|
252
|
-
};
|
|
253
|
-
}()));
|
|
254
|
-
case 9:
|
|
255
|
-
searchData = _ctx.sent;
|
|
256
|
-
_ctx.next = 12;
|
|
257
|
-
return sharedFilesystem.promises.writeFile("/search-data.json", JSON.stringify(searchData));
|
|
258
|
-
case 12:
|
|
259
|
-
case "end":
|
|
260
|
-
return _ctx.stop();
|
|
261
|
-
}
|
|
262
|
-
}, _callee);
|
|
263
|
-
}))();
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
export default SearchIndexPlugin;
|
|
267
|
-
|
|
268
|
-
//# sourceMappingURL=SearchIndexPlugin.mjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/SearchIndexPlugin.mjs.ts"],"sourcesContent":["import { unified } from 'unified';\nimport markdown from 'remark-parse';\nimport remarkMdx from 'remark-mdx';\nimport { visit } from 'unist-util-visit';\nimport type { Node } from 'unist';\nimport type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';\n\ntype LeafNode = Node & {\n value: string;\n};\n\ninterface SearchIndexPluginOptions {\n maxLineLength?: number;\n maxLineCount?: number;\n keys?: string[];\n}\n\ninterface Optimization {\n content: string;\n title: string;\n maxLineCount: number;\n maxLineLength: number;\n}\n\n/**\n * Converts raw content string into an array of sentences suitable for inclusion\n * in the search index\n *\n * @param options.content the raw content string\n * @param options.title the title of the page (used for adding context to parse errors)\n * @param options.maxLineLength the maximum length of a sentence (set this to match the\n * \"location\" option in your Fuse.js configuration). Sentences longer than this value will be\n * truncated.\n * @param options.maxLineCount the maximum number of lines to include in the search index for\n * each page. Pages with more lines than this value will be truncated.\n * @returns array of sentence strings\n */\nconst optimizeContentForSearch = async ({\n content,\n title,\n maxLineLength,\n maxLineCount\n}: Optimization) => {\n if (!content || content.length < 1) return [content];\n const processor = unified().use(markdown).use(remarkMdx);\n let tree;\n\n try {\n tree = await processor.parse(content);\n } catch (err) {\n console.error(`Search Index Plugin failed to parse content for ${title}`, err.reason);\n return [];\n }\n\n const sentences: string[] = [];\n\n visit(\n tree,\n node => node.type === 'text' || node.type === 'code',\n (node: LeafNode) => {\n if (maxLineLength) {\n sentences.push(node.value.slice(0, maxLineLength));\n } else {\n sentences.push(node.value);\n }\n }\n );\n\n if (maxLineLength) {\n return sentences.slice(0, maxLineCount);\n }\n return sentences;\n};\n\n/**\n * Creates a search-data.json file that contains all the information from a page that is required\n * to generate a search index\n */\nconst SearchIndexPlugin: PluginType<Page, SearchIndexPluginOptions> = {\n async afterUpdate(\n mutableFilesystem,\n { sharedFilesystem, serialiser, ignorePages },\n { maxLineLength, maxLineCount, keys }\n ) {\n const pages = await Promise.all(\n (\n (await mutableFilesystem.promises.glob('**', {\n onlyFiles: true,\n ignore: ignorePages.map(ignore => `**/${ignore}`),\n cwd: '/'\n })) as string[]\n ).map(async pagePath => {\n const deserialisedPage = await serialiser.deserialise(\n pagePath,\n await mutableFilesystem.promises.readFile(pagePath)\n );\n return deserialisedPage;\n })\n );\n\n const searchData = await Promise.all(\n pages.map(async page => {\n const content = await optimizeContentForSearch({\n content: page.content || '',\n title: page.title || '',\n maxLineLength,\n maxLineCount\n });\n const defaultResults = {\n title: page.title,\n content,\n route: page.route\n };\n\n if (keys && keys.length > 0) {\n const extendedResults = keys.reduce((acc, key) => ({ ...acc, [key]: page[key] }), {});\n return { ...defaultResults, ...extendedResults };\n }\n\n return defaultResults;\n })\n );\n\n await sharedFilesystem.promises.writeFile('/search-data.json', JSON.stringify(searchData));\n }\n};\n\nexport default SearchIndexPlugin;\n"],"names":["unified","markdown","remarkMdx","visit","optimizeContentForSearch","content","title","maxLineLength","maxLineCount","processor","tree","sentences","length","use","parse","console","error","err","reason","node","type","push","value","slice","SearchIndexPlugin","afterUpdate","mutableFilesystem","sharedFilesystem","serialiser","ignorePages","keys","pages","searchData","Promise","promises","glob","onlyFiles","ignore","map","cwd","pagePath","deserialisedPage","readFile","deserialise","all","page","defaultResults","extendedResults","route","reduce","acc","key","writeFile","JSON","stringify"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,OAAO,QAAQ,SAAS,CAAC;AAClC,OAAOC,QAAQ,MAAM,cAAc,CAAC;AACpC,OAAOC,SAAS,MAAM,YAAY,CAAC;AACnC,SAASC,KAAK,QAAQ,kBAAkB,CAAC;AAqBzC;;;;;;;;;;;;CAYC,GACD,IAAMC,wBAAwB;eAAG,wDAAA,wBAKb;YAJlBC,OAAO,EACPC,KAAK,EACLC,aAAa,EACbC,YAAY,EAGNC,SAAS,EAC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,EAAbA,aAAa;gDACbC,YAAY,EAAZA,YAAY;6CACb,CAAC;;4CALIH,OAAO,YAKX,CAAA;4CACIyC,cAAc,GAAG;gDACrBxC,KAAK,EAAEuC,IAAI,CAACvC,KAAK;gDACjBD,OAAO,EAAPA,OAAO;gDACP2C,KAAK,EAAEH,IAAI,CAACG,KAAK;6CAClB,CAAC;gDAEElB,CAAAA,CAAAA,IAAI,IAAIA,IAAI,CAAClB,MAAM,GAAG,CAAC,CAAA;;;;4CACnBmC,eAAe,GAAGjB,IAAI,CAACmB,MAAM,CAAC,SAACC,GAAG,EAAEC,GAAG;uDAAM,qCAAKD,GAAG,GAAE,oBAACC,GAAG,EAAGN,IAAI,CAACM,GAAG,CAAC,CAAA,CAAE;6CAAC,EAAE,EAAE,CAAC,CAAC;yEAC/E,kBAAKL,cAAc,EAAKC,eAAe,CAAE;;yEAG3CD,cAAc;;;;;;6BACtB,EAAA;4CAnBeD,IAAI;;;4BAmBlB,CACH;;wBArBKb,UAAU,YAqBf,CAAA;;+BAEKL,gBAAgB,CAACO,QAAQ,CAACkB,SAAS,CAAC,mBAAmB,EAAEC,IAAI,CAACC,SAAS,CAACtB,UAAU,CAAC,CAAC;;;;;;SAC3F,EAAA;KAAA;CACF,AAAC;AAEF,eAAeR,iBAAiB,CAAC"}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _asyncToGenerator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
import regeneratorRuntime from "regenerator-runtime";
|
|
31
|
-
import Slugger from "github-slugger";
|
|
32
|
-
import remarkParse from "remark-parse";
|
|
33
|
-
import { unified } from "unified";
|
|
34
|
-
import remarkStringify from "remark-stringify";
|
|
35
|
-
import remarkHeadings from "@vcarl/remark-headings";
|
|
36
|
-
/**
|
|
37
|
-
* Calculates table of contents from page headings
|
|
38
|
-
*/ var TableOfContentsPlugin = {
|
|
39
|
-
$afterSource: function $afterSource(pages, _, param) {
|
|
40
|
-
var minRank = param.minRank, maxRank = param.maxRank;
|
|
41
|
-
return _asyncToGenerator(/*#__PURE__*/ regeneratorRuntime.mark(function _callee() {
|
|
42
|
-
var processor, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, page, slugger, vfile, headings, items;
|
|
43
|
-
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
|
44
|
-
while(1)switch(_ctx.prev = _ctx.next){
|
|
45
|
-
case 0:
|
|
46
|
-
processor = unified().use(remarkParse).use(remarkStringify).use(remarkHeadings);
|
|
47
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
48
|
-
_ctx.prev = 2;
|
|
49
|
-
_iterator = pages[Symbol.iterator]();
|
|
50
|
-
case 4:
|
|
51
|
-
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
|
|
52
|
-
_ctx.next = 17;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
page = _step.value;
|
|
56
|
-
slugger = new Slugger();
|
|
57
|
-
if (!page.content) {
|
|
58
|
-
_ctx.next = 14;
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
_ctx.next = 10;
|
|
62
|
-
return processor.process(page.content);
|
|
63
|
-
case 10:
|
|
64
|
-
vfile = _ctx.sent;
|
|
65
|
-
headings = vfile.data.headings;
|
|
66
|
-
items = headings.filter(function(heading) {
|
|
67
|
-
return heading.depth >= minRank && heading.depth <= maxRank;
|
|
68
|
-
}).map(function(validHeading) {
|
|
69
|
-
var text = validHeading.value.trim();
|
|
70
|
-
return {
|
|
71
|
-
level: validHeading.depth,
|
|
72
|
-
id: slugger.slug(text),
|
|
73
|
-
text: text
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
page.tableOfContents = items;
|
|
77
|
-
case 14:
|
|
78
|
-
_iteratorNormalCompletion = true;
|
|
79
|
-
_ctx.next = 4;
|
|
80
|
-
break;
|
|
81
|
-
case 17:
|
|
82
|
-
_ctx.next = 23;
|
|
83
|
-
break;
|
|
84
|
-
case 19:
|
|
85
|
-
_ctx.prev = 19;
|
|
86
|
-
_ctx.t0 = _ctx["catch"](2);
|
|
87
|
-
_didIteratorError = true;
|
|
88
|
-
_iteratorError = _ctx.t0;
|
|
89
|
-
case 23:
|
|
90
|
-
_ctx.prev = 23;
|
|
91
|
-
_ctx.prev = 24;
|
|
92
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
93
|
-
_iterator.return();
|
|
94
|
-
}
|
|
95
|
-
case 26:
|
|
96
|
-
_ctx.prev = 26;
|
|
97
|
-
if (!_didIteratorError) {
|
|
98
|
-
_ctx.next = 29;
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
throw _iteratorError;
|
|
102
|
-
case 29:
|
|
103
|
-
return _ctx.finish(26);
|
|
104
|
-
case 30:
|
|
105
|
-
return _ctx.finish(23);
|
|
106
|
-
case 31:
|
|
107
|
-
return _ctx.abrupt("return", pages);
|
|
108
|
-
case 32:
|
|
109
|
-
case "end":
|
|
110
|
-
return _ctx.stop();
|
|
111
|
-
}
|
|
112
|
-
}, _callee, null, [
|
|
113
|
-
[
|
|
114
|
-
2,
|
|
115
|
-
19,
|
|
116
|
-
23,
|
|
117
|
-
31
|
|
118
|
-
],
|
|
119
|
-
[
|
|
120
|
-
24,
|
|
121
|
-
,
|
|
122
|
-
26,
|
|
123
|
-
30
|
|
124
|
-
]
|
|
125
|
-
]);
|
|
126
|
-
}))();
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
export default TableOfContentsPlugin;
|
|
130
|
-
|
|
131
|
-
//# sourceMappingURL=TableOfContentsPlugin.mjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/TableOfContentsPlugin.mjs.ts"],"sourcesContent":["import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';\nimport Slugger from 'github-slugger';\nimport remarkParse from 'remark-parse';\nimport { unified } from 'unified';\nimport remarkStringify from 'remark-stringify';\nimport remarkHeadings from '@vcarl/remark-headings';\nimport type { Heading as MarkdownHeading } from 'mdast';\n\ntype TOCItem = { level: number; id: string; text: string };\n\ninterface TableOfContentsPluginPage extends Page {\n tableOfContents?: TOCItem[];\n}\ntype Rank = MarkdownHeading['depth'];\ninterface TableOfContentsPluginOptions {\n minRank: Rank;\n maxRank: Rank;\n}\n\n/**\n * Calculates table of contents from page headings\n */\nconst TableOfContentsPlugin: PluginType<TableOfContentsPluginPage, TableOfContentsPluginOptions> = {\n async $afterSource(pages, _, { minRank, maxRank }) {\n const processor = unified().use(remarkParse).use(remarkStringify).use(remarkHeadings);\n for (const page of pages) {\n const slugger = new Slugger();\n if (page.content) {\n const vfile = await processor.process(page.content);\n const headings = vfile.data.headings as [{ depth: number; value: string }];\n const items: TOCItem[] = headings\n .filter(heading => heading.depth >= minRank && heading.depth <= maxRank)\n .map(validHeading => {\n const text = validHeading.value.trim();\n return {\n level: validHeading.depth,\n id: slugger.slug(text),\n text\n };\n });\n page.tableOfContents = items;\n }\n }\n\n return pages;\n }\n};\n\nexport default TableOfContentsPlugin;\n"],"names":["Slugger","remarkParse","unified","remarkStringify","remarkHeadings","TableOfContentsPlugin","$afterSource","pages","_","minRank","maxRank","processor","page","slugger","vfile","headings","items","use","content","process","data","filter","heading","depth","map","validHeading","text","value","trim","level","id","slug","tableOfContents"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAOA,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAOC,WAAW,MAAM,cAAc,CAAC;AACvC,SAASC,OAAO,QAAQ,SAAS,CAAC;AAClC,OAAOC,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAOC,cAAc,MAAM,wBAAwB,CAAC;AAcpD;;CAEC,GACD,IAAMC,qBAAqB,GAAwE;IAC3FC,YAAY,EAAlB,SAAMA,YAAY,CAACC,KAAK,EAAEC,CAAC,EAAE,KAAoB;YAAlBC,OAAO,GAAT,KAAoB,CAAlBA,OAAO,EAAEC,OAAO,GAAlB,KAAoB,CAATA,OAAO;eAAI,wDAAA,mBAAA;gBAC3CC,SAAS,EACV,yBAAU,EAAV,iBAAU,EAAV,cAAU,EAAV,SAAU,EAAV,KAAU,EAAJC,IAAI,EACPC,OAAO,EAELC,KAAK,EACLC,QAAQ,EACRC,KAAK;;;;wBANTL,SAAS,GAAGT,OAAO,EAAE,CAACe,GAAG,CAAChB,WAAW,CAAC,CAACgB,GAAG,CAACd,eAAe,CAAC,CAACc,GAAG,CAACb,cAAc,CAAC,CAAC;wBACjF,yBAAU,SAAV,iBAAU,UAAV,cAAU;;wBAAV,SAAU,GAAIG,KAAK;;4BAAnB,yBAAU,IAAV,KAAU,GAAV,SAAU;;;;wBAAJK,IAAI,GAAV,KAAU,MAAA;wBACPC,OAAO,GAAG,IAAIb,OAAO,EAAE,CAAC;4BAC1BY,CAAAA,IAAI,CAACM,OAAO;;;;;+BACMP,SAAS,CAACQ,OAAO,CAACP,IAAI,CAACM,OAAO,CAAC;;wBAA7CJ,KAAK,YAAwC,CAAA;wBAC7CC,QAAQ,GAAGD,KAAK,CAACM,IAAI,CAACL,QAAQ,AAAsC,CAAC;wBACrEC,KAAK,GAAcD,QAAQ,CAC9BM,MAAM,CAACC,SAAAA,OAAO;mCAAIA,OAAO,CAACC,KAAK,IAAId,OAAO,IAAIa,OAAO,CAACC,KAAK,IAAIb,OAAO;yBAAA,CAAC,CACvEc,GAAG,CAACC,SAAAA,YAAY,EAAI;4BACnB,IAAMC,IAAI,GAAGD,YAAY,CAACE,KAAK,CAACC,IAAI,EAAE,AAAC;4BACvC,OAAO;gCACLC,KAAK,EAAEJ,YAAY,CAACF,KAAK;gCACzBO,EAAE,EAAEjB,OAAO,CAACkB,IAAI,CAACL,IAAI,CAAC;gCACtBA,IAAI,EAAJA,IAAI;6BACL,CAAC;yBACH,CAAC,CAAC;wBACLd,IAAI,CAACoB,eAAe,GAAGhB,KAAK,CAAC;;wBAf5B,yBAAU;;;;;;;;;wBAAV,iBAAU;wBAAV,cAAU;;;;6BAAV,yBAAU,IAAV,SAAU;4BAAV,SAAU;;;;4BAAV,CAAA,iBAAU;;;;8BAAV,cAAU;;;;;;qDAmBRT,KAAK;;;;;;;;;;;;;;;;;;;SACb,EAAA;KAAA;CACF,AAAC;AAEF,eAAeF,qBAAqB,CAAC"}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _asyncToGenerator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
import regeneratorRuntime from "regenerator-runtime";
|
|
31
|
-
import BreadcrumbsPlugin from "../BreadcrumbsPlugin";
|
|
32
|
-
// jest.mock('fs');
|
|
33
|
-
var pages = [
|
|
34
|
-
{
|
|
35
|
-
fullPath: "/FolderA/index.mdx",
|
|
36
|
-
route: "route/folderA/index",
|
|
37
|
-
title: "Folder A Index"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
fullPath: "/FolderA/pageA.mdx",
|
|
41
|
-
route: "route/folderA/pageA",
|
|
42
|
-
title: "Folder A Page A"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
fullPath: "/FolderA/pageB.mdx",
|
|
46
|
-
route: "route/folderA/pageB",
|
|
47
|
-
title: "Folder A Page B"
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
fullPath: "/FolderA/SubfolderA/index.mdx",
|
|
51
|
-
route: "route/folderA/subfolderA/index",
|
|
52
|
-
title: "Subfolder A Index"
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
fullPath: "/FolderA/SubfolderA/PageA.mdx",
|
|
56
|
-
route: "route/folderA/subfolderA/pageA",
|
|
57
|
-
title: "Subfolder A Page A"
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
fullPath: "/FolderA/SubfolderA/PageB.mdx",
|
|
61
|
-
route: "route/folderA/subfolderA/pageB",
|
|
62
|
-
title: "Subfolder A Page B"
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
fullPath: "/FolderA/SubfolderA/PageB.mdx",
|
|
66
|
-
route: "route/folderA/subfolderA/pageB",
|
|
67
|
-
title: "Subfolder A Page B",
|
|
68
|
-
breadcrumbs: [
|
|
69
|
-
{
|
|
70
|
-
label: "Label A",
|
|
71
|
-
path: "path/A",
|
|
72
|
-
id: "id A"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
label: "Label B",
|
|
76
|
-
path: "path/B",
|
|
77
|
-
id: "id B"
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
}
|
|
81
|
-
];
|
|
82
|
-
describe("GIVEN the BreadcrumbsPlugin", function() {
|
|
83
|
-
var updatedPages = [];
|
|
84
|
-
beforeEach(/*#__PURE__*/ _asyncToGenerator(/*#__PURE__*/ regeneratorRuntime.mark(function _callee() {
|
|
85
|
-
var $afterSource;
|
|
86
|
-
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
|
87
|
-
while(1)switch(_ctx.prev = _ctx.next){
|
|
88
|
-
case 0:
|
|
89
|
-
$afterSource = BreadcrumbsPlugin.$afterSource;
|
|
90
|
-
_ctx.next = 3;
|
|
91
|
-
return $afterSource === null || $afterSource === void 0 ? void 0 : $afterSource(pages, {}, {
|
|
92
|
-
indexPageName: "index.mdx"
|
|
93
|
-
});
|
|
94
|
-
case 3:
|
|
95
|
-
_ctx.t0 = _ctx.sent;
|
|
96
|
-
if (_ctx.t0) {
|
|
97
|
-
_ctx.next = 6;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
_ctx.t0 = [];
|
|
101
|
-
case 6:
|
|
102
|
-
updatedPages = _ctx.t0;
|
|
103
|
-
case 7:
|
|
104
|
-
case "end":
|
|
105
|
-
return _ctx.stop();
|
|
106
|
-
}
|
|
107
|
-
}, _callee);
|
|
108
|
-
})));
|
|
109
|
-
test("THEN it should use the `$afterSource` lifecycle event", function() {
|
|
110
|
-
expect(BreadcrumbsPlugin).toHaveProperty("$afterSource");
|
|
111
|
-
});
|
|
112
|
-
describe("AND WHEN `$afterSource` is called", function() {
|
|
113
|
-
test("THEN breadcrumbs are added", /*#__PURE__*/ _asyncToGenerator(/*#__PURE__*/ regeneratorRuntime.mark(function _callee() {
|
|
114
|
-
var breadcrumbs;
|
|
115
|
-
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
|
116
|
-
while(1)switch(_ctx.prev = _ctx.next){
|
|
117
|
-
case 0:
|
|
118
|
-
breadcrumbs = updatedPages && updatedPages[4].breadcrumbs || [];
|
|
119
|
-
expect(breadcrumbs.length).toBe(3);
|
|
120
|
-
expect(breadcrumbs[0]).toEqual({
|
|
121
|
-
label: "Folder A Index",
|
|
122
|
-
path: "route/folderA/index",
|
|
123
|
-
id: "/FolderA/index.mdx"
|
|
124
|
-
});
|
|
125
|
-
expect(breadcrumbs[1]).toEqual({
|
|
126
|
-
label: "Subfolder A Index",
|
|
127
|
-
path: "route/folderA/subfolderA/index",
|
|
128
|
-
id: "/FolderA/SubfolderA/index.mdx"
|
|
129
|
-
});
|
|
130
|
-
expect(breadcrumbs[2]).toEqual({
|
|
131
|
-
label: "Subfolder A Page A",
|
|
132
|
-
path: "route/folderA/subfolderA/pageA",
|
|
133
|
-
id: "/FolderA/SubfolderA/PageA.mdx"
|
|
134
|
-
});
|
|
135
|
-
case 5:
|
|
136
|
-
case "end":
|
|
137
|
-
return _ctx.stop();
|
|
138
|
-
}
|
|
139
|
-
}, _callee);
|
|
140
|
-
})));
|
|
141
|
-
describe("AND WHEN a page already has breadcrumbs", function() {
|
|
142
|
-
test("THEN those breadcrumbs are used", function() {
|
|
143
|
-
var breadcrumbs = updatedPages && updatedPages[6].breadcrumbs || [];
|
|
144
|
-
expect(breadcrumbs.length).toBe(2);
|
|
145
|
-
expect(breadcrumbs[0]).toEqual({
|
|
146
|
-
label: "Label A",
|
|
147
|
-
path: "path/A",
|
|
148
|
-
id: "id A"
|
|
149
|
-
});
|
|
150
|
-
expect(breadcrumbs[1]).toEqual({
|
|
151
|
-
label: "Label B",
|
|
152
|
-
path: "path/B",
|
|
153
|
-
id: "id B"
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
//# sourceMappingURL=BreadcrumbsPlugin.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/__tests__/BreadcrumbsPlugin.test.ts"],"sourcesContent":["import type { Page } from '@jpmorganchase/mosaic-types';\n\nimport BreadcrumbsPlugin, { BreadcrumbsPluginPage } from '../BreadcrumbsPlugin';\n\n// jest.mock('fs');\n\nconst pages: BreadcrumbsPluginPage[] = [\n {\n fullPath: '/FolderA/index.mdx',\n route: 'route/folderA/index',\n title: 'Folder A Index'\n },\n {\n fullPath: '/FolderA/pageA.mdx',\n route: 'route/folderA/pageA',\n title: 'Folder A Page A'\n },\n {\n fullPath: '/FolderA/pageB.mdx',\n route: 'route/folderA/pageB',\n title: 'Folder A Page B'\n },\n {\n fullPath: '/FolderA/SubfolderA/index.mdx',\n route: 'route/folderA/subfolderA/index',\n title: 'Subfolder A Index'\n },\n {\n fullPath: '/FolderA/SubfolderA/PageA.mdx',\n route: 'route/folderA/subfolderA/pageA',\n title: 'Subfolder A Page A'\n },\n {\n fullPath: '/FolderA/SubfolderA/PageB.mdx',\n route: 'route/folderA/subfolderA/pageB',\n title: 'Subfolder A Page B'\n },\n {\n fullPath: '/FolderA/SubfolderA/PageB.mdx',\n route: 'route/folderA/subfolderA/pageB',\n title: 'Subfolder A Page B',\n breadcrumbs: [\n {\n label: 'Label A',\n path: 'path/A',\n id: 'id A'\n },\n {\n label: 'Label B',\n path: 'path/B',\n id: 'id B'\n }\n ]\n }\n];\n\ndescribe('GIVEN the BreadcrumbsPlugin', () => {\n let updatedPages: BreadcrumbsPluginPage[] = [];\n beforeEach(async () => {\n const $afterSource = BreadcrumbsPlugin.$afterSource;\n updatedPages = (await $afterSource?.(pages, {}, { indexPageName: 'index.mdx' })) || [];\n });\n test('THEN it should use the `$afterSource` lifecycle event', () => {\n expect(BreadcrumbsPlugin).toHaveProperty('$afterSource');\n });\n\n describe('AND WHEN `$afterSource` is called', () => {\n test('THEN breadcrumbs are added', async () => {\n const breadcrumbs = (updatedPages && updatedPages[4].breadcrumbs) || [];\n\n expect(breadcrumbs.length).toBe(3);\n expect(breadcrumbs[0]).toEqual({\n label: 'Folder A Index',\n path: 'route/folderA/index',\n id: '/FolderA/index.mdx'\n });\n expect(breadcrumbs[1]).toEqual({\n label: 'Subfolder A Index',\n path: 'route/folderA/subfolderA/index',\n id: '/FolderA/SubfolderA/index.mdx'\n });\n expect(breadcrumbs[2]).toEqual({\n label: 'Subfolder A Page A',\n path: 'route/folderA/subfolderA/pageA',\n id: '/FolderA/SubfolderA/PageA.mdx'\n });\n });\n\n describe('AND WHEN a page already has breadcrumbs', () => {\n test('THEN those breadcrumbs are used', () => {\n const breadcrumbs = (updatedPages && updatedPages[6].breadcrumbs) || [];\n expect(breadcrumbs.length).toBe(2);\n expect(breadcrumbs[0]).toEqual({\n label: 'Label A',\n path: 'path/A',\n id: 'id A'\n });\n expect(breadcrumbs[1]).toEqual({\n label: 'Label B',\n path: 'path/B',\n id: 'id B'\n });\n });\n });\n });\n});\n"],"names":["BreadcrumbsPlugin","pages","fullPath","route","title","breadcrumbs","label","path","id","describe","updatedPages","beforeEach","$afterSource","indexPageName","test","expect","toHaveProperty","length","toBe","toEqual"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAOA,iBAAiB,MAAiC,sBAAsB,CAAC;AAEhF,mBAAmB;AAEnB,IAAMC,KAAK,GAA4B;IACrC;QACEC,QAAQ,EAAE,oBAAoB;QAC9BC,KAAK,EAAE,qBAAqB;QAC5BC,KAAK,EAAE,gBAAgB;KACxB;IACD;QACEF,QAAQ,EAAE,oBAAoB;QAC9BC,KAAK,EAAE,qBAAqB;QAC5BC,KAAK,EAAE,iBAAiB;KACzB;I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