@jpmorganchase/mosaic-plugins 0.1.0-beta.8 → 0.1.0-beta.81
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
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
interface TagPluginPage extends Page {
|
|
3
|
+
tags?: string[];
|
|
4
|
+
}
|
|
5
|
+
interface TagPluginConfigData {
|
|
6
|
+
tagRefs: {
|
|
7
|
+
[key: string]: {
|
|
8
|
+
$$path: string[];
|
|
9
|
+
$$value: string[];
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
globalRefs: {
|
|
13
|
+
[key: string]: {
|
|
14
|
+
$$path: string[];
|
|
15
|
+
$$value: string[];
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
subscribedTags: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Plugin that scrapes `$tag` from page metadata and also applies all aliases stored in `config.data.tags`.
|
|
22
|
+
* Tags ultimately resolve down into refs, but are different from normal refs, in that they are applied to the
|
|
23
|
+
* union filesystem (all merged filesystems), not to the individual source filesystem that they were defined on.
|
|
24
|
+
* Other plugins can use `setData()` and modify the `tags` property, to apply new global refs, as long as
|
|
25
|
+
* they do so before this plugin has reaches `$beforeSend`
|
|
26
|
+
*/
|
|
27
|
+
declare const $TagPlugin: PluginType<TagPluginPage, unknown, TagPluginConfigData>;
|
|
28
|
+
export default $TagPlugin;
|
package/dist/$TagPlugin.js
CHANGED
|
@@ -1,249 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
function _arrayWithoutHoles(arr) {
|
|
10
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
11
|
-
}
|
|
12
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
13
|
-
try {
|
|
14
|
-
var info = gen[key](arg);
|
|
15
|
-
var value = info.value;
|
|
16
|
-
} catch (error) {
|
|
17
|
-
reject(error);
|
|
18
|
-
return;
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { reduce } from 'lodash-es';
|
|
3
|
+
import PluginError from './utils/PluginError.js';
|
|
4
|
+
import { createPageTest } from './utils/createPageTest.js';
|
|
5
|
+
const findKeys = (obj, targetProp, pathParts = []) => reduce(obj, (found, value, key) => {
|
|
6
|
+
if (key === targetProp) {
|
|
7
|
+
return found.concat({ $$path: pathParts.concat(String(key)), $$value: value });
|
|
19
8
|
}
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Promise.resolve(value).then(_next, _throw);
|
|
9
|
+
if (typeof value === 'object') {
|
|
10
|
+
const foundParents = findKeys(value, targetProp, pathParts.concat(String(key)));
|
|
11
|
+
return found.concat(...foundParents);
|
|
24
12
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return function() {
|
|
28
|
-
var self = this, args = arguments;
|
|
29
|
-
return new Promise(function(resolve, reject) {
|
|
30
|
-
var gen = fn.apply(self, args);
|
|
31
|
-
function _next(value) {
|
|
32
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
33
|
-
}
|
|
34
|
-
function _throw(err) {
|
|
35
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
36
|
-
}
|
|
37
|
-
_next(undefined);
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function _iterableToArray(iter) {
|
|
42
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
43
|
-
}
|
|
44
|
-
function _iterableToArrayLimit(arr, i) {
|
|
45
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
46
|
-
if (_i == null) return;
|
|
47
|
-
var _arr = [];
|
|
48
|
-
var _n = true;
|
|
49
|
-
var _d = false;
|
|
50
|
-
var _s, _e;
|
|
51
|
-
try {
|
|
52
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
53
|
-
_arr.push(_s.value);
|
|
54
|
-
if (i && _arr.length === i) break;
|
|
55
|
-
}
|
|
56
|
-
} catch (err) {
|
|
57
|
-
_d = true;
|
|
58
|
-
_e = err;
|
|
59
|
-
} finally{
|
|
60
|
-
try {
|
|
61
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
62
|
-
} finally{
|
|
63
|
-
if (_d) throw _e;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return _arr;
|
|
67
|
-
}
|
|
68
|
-
function _nonIterableRest() {
|
|
69
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
70
|
-
}
|
|
71
|
-
function _nonIterableSpread() {
|
|
72
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
73
|
-
}
|
|
74
|
-
function _slicedToArray(arr, i) {
|
|
75
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
76
|
-
}
|
|
77
|
-
function _toConsumableArray(arr) {
|
|
78
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
79
|
-
}
|
|
80
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
81
|
-
if (!o) return;
|
|
82
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
83
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
84
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
85
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
86
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
87
|
-
}
|
|
88
|
-
import regeneratorRuntime from "regenerator-runtime";
|
|
89
|
-
import path from "path";
|
|
90
|
-
import escapeRegExp from "lodash/escapeRegExp";
|
|
91
|
-
import reduce from "lodash/reduce";
|
|
92
|
-
function createPageTest(ignorePages, pageExtensions) {
|
|
93
|
-
var extTest = new RegExp("".concat(pageExtensions.map(escapeRegExp).join("|"), "$"));
|
|
94
|
-
var ignoreTest = new RegExp("".concat(ignorePages.map(escapeRegExp).join("|"), "$"));
|
|
95
|
-
return function(file) {
|
|
96
|
-
return !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith(".");
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
var findKeys = function(obj, targetProp) {
|
|
100
|
-
var pathParts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
|
|
101
|
-
return reduce(obj, function(found, value, key) {
|
|
102
|
-
if (key === targetProp) {
|
|
103
|
-
return found.concat({
|
|
104
|
-
$$path: pathParts.concat(String(key)),
|
|
105
|
-
$$value: value
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
if (typeof value === "object") {
|
|
109
|
-
var _found;
|
|
110
|
-
var foundParents = findKeys(value, targetProp, pathParts.concat(String(key)));
|
|
111
|
-
return (_found = found).concat.apply(_found, _toConsumableArray(foundParents));
|
|
112
|
-
}
|
|
113
|
-
return found;
|
|
114
|
-
}, []);
|
|
115
|
-
};
|
|
13
|
+
return found;
|
|
14
|
+
}, []);
|
|
116
15
|
/**
|
|
117
16
|
* Plugin that scrapes `$tag` from page metadata and also applies all aliases stored in `config.data.tags`.
|
|
118
17
|
* Tags ultimately resolve down into refs, but are different from normal refs, in that they are applied to the
|
|
119
18
|
* union filesystem (all merged filesystems), not to the individual source filesystem that they were defined on.
|
|
120
19
|
* Other plugins can use `setData()` and modify the `tags` property, to apply new global refs, as long as
|
|
121
20
|
* they do so before this plugin has reaches `$beforeSend`
|
|
122
|
-
*/
|
|
123
|
-
|
|
21
|
+
*/
|
|
22
|
+
const $TagPlugin = {
|
|
23
|
+
// Check if the updated source has any /.tag aliases that we care about - if it does, we should re-run `afterUpdate` to
|
|
124
24
|
// make sure we pull in the latest pages
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
;
|
|
133
|
-
_ctx.t0 = !((ref = config.data) === null || ref === void 0 ? void 0 : ref.subscribedTags);
|
|
134
|
-
if (_ctx.t0) {
|
|
135
|
-
_ctx.next = 6;
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
_ctx.next = 5;
|
|
139
|
-
return updatedSourceFilesystem.promises.exists("/.tags");
|
|
140
|
-
case 5:
|
|
141
|
-
_ctx.t0 = !_ctx.sent;
|
|
142
|
-
case 6:
|
|
143
|
-
if (!_ctx.t0) {
|
|
144
|
-
_ctx.next = 8;
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
return _ctx.abrupt("return", false);
|
|
148
|
-
case 8:
|
|
149
|
-
_ctx.next = 10;
|
|
150
|
-
return updatedSourceFilesystem.promises.readdir("/.tags");
|
|
151
|
-
case 10:
|
|
152
|
-
return _ctx.abrupt("return", _ctx.sent.some(function(tag) {
|
|
153
|
-
return config.data.subscribedTags.includes(tag);
|
|
154
|
-
}));
|
|
155
|
-
case 11:
|
|
156
|
-
case "end":
|
|
157
|
-
return _ctx.stop();
|
|
158
|
-
}
|
|
159
|
-
}, _callee);
|
|
160
|
-
}))();
|
|
25
|
+
async shouldClearCache(updatedSourceFilesystem, { config }) {
|
|
26
|
+
if (!config.data?.subscribedTags ||
|
|
27
|
+
!(await updatedSourceFilesystem.promises.exists('/.tags'))) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
// Does the updated source have tags we are interested in?
|
|
31
|
+
return (await updatedSourceFilesystem.promises.readdir('/.tags')).some(tag => config.data.subscribedTags.includes(tag));
|
|
161
32
|
},
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
// Find any references to $tag
|
|
186
|
-
var foundTags = findKeys(page, "$tag");
|
|
187
|
-
if (foundTags.length) {
|
|
188
|
-
var tags = new Set();
|
|
189
|
-
foundTags.forEach(function(ref) {
|
|
190
|
-
var _$ref = _slicedToArray(ref.$$value.split("#"), 2), tag = _$ref[0], tmp = _$ref[1], fragment = tmp === void 0 ? "" : tmp;
|
|
191
|
-
tags.add(tag);
|
|
192
|
-
config.setGlobalRef(page.fullPath, ref.$$path, "".concat(path.join("/.tags", tag, "**"), "#").concat(fragment));
|
|
193
|
-
});
|
|
194
|
-
config.setData({
|
|
195
|
-
subscribedTags: Array.from(tags)
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
for(_iterator = pages[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
200
|
-
_ctx.next = 11;
|
|
201
|
-
break;
|
|
202
|
-
case 7:
|
|
203
|
-
_ctx.prev = 7;
|
|
204
|
-
_ctx.t0 = _ctx["catch"](2);
|
|
205
|
-
_didIteratorError = true;
|
|
206
|
-
_iteratorError = _ctx.t0;
|
|
207
|
-
case 11:
|
|
208
|
-
_ctx.prev = 11;
|
|
209
|
-
_ctx.prev = 12;
|
|
210
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
211
|
-
_iterator.return();
|
|
212
|
-
}
|
|
213
|
-
case 14:
|
|
214
|
-
_ctx.prev = 14;
|
|
215
|
-
if (!_didIteratorError) {
|
|
216
|
-
_ctx.next = 17;
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
throw _iteratorError;
|
|
220
|
-
case 17:
|
|
221
|
-
return _ctx.finish(14);
|
|
222
|
-
case 18:
|
|
223
|
-
return _ctx.finish(11);
|
|
224
|
-
case 19:
|
|
225
|
-
return _ctx.abrupt("return", pages);
|
|
226
|
-
case 20:
|
|
227
|
-
case "end":
|
|
228
|
-
return _ctx.stop();
|
|
33
|
+
// Every source with tags will create symlinks with the tagged pages, inside /.tags
|
|
34
|
+
async $afterSource(pages, { config, ignorePages, pageExtensions }) {
|
|
35
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
36
|
+
for (const page of pages) {
|
|
37
|
+
try {
|
|
38
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const meta = page;
|
|
42
|
+
// Symlink every `tag` item to '/.tags' folder
|
|
43
|
+
if (meta.tags?.length) {
|
|
44
|
+
config.setTags(page.fullPath, meta.tags);
|
|
45
|
+
}
|
|
46
|
+
// Find any references to $tag
|
|
47
|
+
const foundTags = findKeys(page, '$tag');
|
|
48
|
+
if (foundTags.length) {
|
|
49
|
+
const tags = new Set();
|
|
50
|
+
foundTags.forEach(ref => {
|
|
51
|
+
const [tag, fragment = ''] = ref.$$value.split('#');
|
|
52
|
+
tags.add(tag);
|
|
53
|
+
config.setGlobalRef(page.fullPath, ref.$$path, `${path.posix.join('/.tags', tag, '**', '*')}#${fragment}`);
|
|
54
|
+
});
|
|
55
|
+
config.setData({ subscribedTags: Array.from(tags) });
|
|
229
56
|
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
],
|
|
237
|
-
[
|
|
238
|
-
12,
|
|
239
|
-
,
|
|
240
|
-
14,
|
|
241
|
-
18
|
|
242
|
-
]
|
|
243
|
-
]);
|
|
244
|
-
}))();
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
throw new PluginError(e.message, page.fullPath);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return pages;
|
|
245
63
|
}
|
|
246
64
|
};
|
|
247
65
|
export default $TagPlugin;
|
|
248
|
-
|
|
249
66
|
//# sourceMappingURL=$TagPlugin.js.map
|
package/dist/$TagPlugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"$TagPlugin.js","sourceRoot":"","sources":["../src/$TagPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,WAAW,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,YAAsB,EAAE,EAAE,EAAE,CAC7D,MAAM,CACJ,GAAG,EACH,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;IACpB,IAAI,GAAG,KAAK,UAAU,EAAE;QACtB,OAAO,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;KAChF;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChF,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC;KACtC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,EACD,EAAE,CACH,CAAC;AAW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G,CAAC,EAAE;wBACtB,MAAM,CAAC,GAAG,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;wBAEpD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;wBAEd,MAAM,CAAC,YAAY,CACjB,IAAI,CAAC,QAAQ,EACb,GAAG,CAAC,MAAM,EACV,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,QAAQ,EAAE,CAC3D,CAAC;oBACJ,CAAC,CAAC,CAAC;oBACH,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;iBACtD;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;aACjD;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Plugin as PluginType } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
import { SidebarPluginPage } from './SidebarPlugin.js';
|
|
3
|
+
export declare type Breadcrumb = {
|
|
4
|
+
label: string;
|
|
5
|
+
path: string;
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
export interface BreadcrumbsPluginPage extends SidebarPluginPage {
|
|
9
|
+
breadcrumbs?: Array<Breadcrumb>;
|
|
10
|
+
layout?: string;
|
|
11
|
+
}
|
|
12
|
+
interface BreadcrumbsPluginOptions {
|
|
13
|
+
indexPageName: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Calculates breadcrumbs for pages then embeds a `breadcrumbs` property to the metadata
|
|
17
|
+
*/
|
|
18
|
+
declare const BreadcrumbsPlugin: PluginType<BreadcrumbsPluginPage, BreadcrumbsPluginOptions>;
|
|
19
|
+
export default BreadcrumbsPlugin;
|
|
@@ -1,120 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 path from "path";
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import PluginError from './utils/PluginError.js';
|
|
3
|
+
import { createPageTest } from './utils/createPageTest.js';
|
|
32
4
|
/**
|
|
33
5
|
* Calculates breadcrumbs for pages then embeds a `breadcrumbs` property to the metadata
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
6
|
+
*/
|
|
7
|
+
const BreadcrumbsPlugin = {
|
|
8
|
+
async $afterSource(pages, { ignorePages, pageExtensions }, options) {
|
|
9
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
10
|
+
for (const page of pages) {
|
|
11
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const pathParts = page.fullPath.replace(/^[/]/, '').split('/');
|
|
16
|
+
const topAndTailedPath = pathParts.slice(1, -1);
|
|
17
|
+
const breadcrumbs = topAndTailedPath.reduce((result, _pathPart, partIndex) => {
|
|
18
|
+
const breadcrumbRoot = `/${pathParts[0]}`;
|
|
19
|
+
const breadcrumbPath = path.join(breadcrumbRoot, ...topAndTailedPath.slice(0, topAndTailedPath.length - partIndex), options.indexPageName);
|
|
20
|
+
const breadcrumbPage = pages.find(
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
22
|
+
item => item.fullPath === breadcrumbPath);
|
|
23
|
+
if (breadcrumbPage) {
|
|
24
|
+
result.unshift({
|
|
25
|
+
label: breadcrumbPage.sidebar?.groupLabel ||
|
|
26
|
+
breadcrumbPage.sidebar?.label ||
|
|
27
|
+
breadcrumbPage.title,
|
|
28
|
+
path: breadcrumbPage.route,
|
|
29
|
+
id: breadcrumbPage.fullPath
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}, []);
|
|
34
|
+
if (!page.breadcrumbs) {
|
|
35
|
+
page.breadcrumbs = breadcrumbs;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
throw new PluginError(e.message, page.fullPath);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return pages;
|
|
43
|
+
},
|
|
44
|
+
async afterNamespaceSourceUpdate(mutableFilesystem, { serialiser, globalFilesystem, ignorePages }, options) {
|
|
45
|
+
const pages = (await mutableFilesystem.promises.glob('**', {
|
|
46
|
+
onlyFiles: true,
|
|
47
|
+
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
48
|
+
cwd: '/'
|
|
49
|
+
}));
|
|
50
|
+
if (pages.length > 0) {
|
|
51
|
+
let updatedBreadcrumbs = [];
|
|
52
|
+
const { breadcrumbs } = await serialiser.deserialise(pages[0], await mutableFilesystem.promises.readFile(pages[0]));
|
|
53
|
+
// the root breadcrumb is the first breadcrumb for all pages in a source. It is essentially the "first" page in a source
|
|
54
|
+
const rootBreadcrumb = breadcrumbs?.[0] || undefined;
|
|
55
|
+
if (rootBreadcrumb) {
|
|
56
|
+
let parentDir = path.posix.join(path.posix.dirname(rootBreadcrumb.id), '../');
|
|
57
|
+
while (parentDir !== '/') {
|
|
58
|
+
const parentDirIndex = path.posix.join(parentDir, options.indexPageName);
|
|
59
|
+
// check for this file in the global fs so we have a holistic view of all site pages
|
|
60
|
+
if (await globalFilesystem.promises.exists(parentDirIndex)) {
|
|
61
|
+
const { breadcrumbs: parentDirBreadcrumbs } = await serialiser.deserialise(rootBreadcrumb.id, await globalFilesystem.promises.readFile(parentDirIndex));
|
|
62
|
+
updatedBreadcrumbs = parentDirBreadcrumbs;
|
|
72
63
|
break;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
_ctx.t0 = _ctx["catch"](1);
|
|
76
|
-
_didIteratorError = true;
|
|
77
|
-
_iteratorError = _ctx.t0;
|
|
78
|
-
case 9:
|
|
79
|
-
_ctx.prev = 9;
|
|
80
|
-
_ctx.prev = 10;
|
|
81
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
82
|
-
_iterator.return();
|
|
83
|
-
}
|
|
84
|
-
case 12:
|
|
85
|
-
_ctx.prev = 12;
|
|
86
|
-
if (!_didIteratorError) {
|
|
87
|
-
_ctx.next = 15;
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
throw _iteratorError;
|
|
91
|
-
case 15:
|
|
92
|
-
return _ctx.finish(12);
|
|
93
|
-
case 16:
|
|
94
|
-
return _ctx.finish(9);
|
|
95
|
-
case 17:
|
|
96
|
-
return _ctx.abrupt("return", pages);
|
|
97
|
-
case 18:
|
|
98
|
-
case "end":
|
|
99
|
-
return _ctx.stop();
|
|
64
|
+
}
|
|
65
|
+
parentDir = path.posix.join(path.posix.dirname(parentDirIndex), '../');
|
|
100
66
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
67
|
+
if (updatedBreadcrumbs.length > 0) {
|
|
68
|
+
for (const pagePath of pages) {
|
|
69
|
+
const page = await serialiser.deserialise(pagePath, await mutableFilesystem.promises.readFile(pagePath));
|
|
70
|
+
// append the parent breadcrumbs **before** the current breadcrumbs
|
|
71
|
+
page.breadcrumbs = [...updatedBreadcrumbs, ...page.breadcrumbs];
|
|
72
|
+
await mutableFilesystem.promises.writeFile(pagePath, await serialiser.serialise(pagePath, page));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
async shouldUpdateNamespaceSources(updatedSourceFilesystem, { ignorePages, namespace }) {
|
|
79
|
+
/**
|
|
80
|
+
* Only trigger an update when the updated source happens to be the "root" namespace source
|
|
81
|
+
* This is determined this by checking if the filesystem has files inside the "namespace" directory
|
|
82
|
+
*
|
|
83
|
+
* "child" sources will have the namespace directory but they wont have files until further down the directory hierarchy
|
|
84
|
+
*/
|
|
85
|
+
const namespaceDirFiles = (await updatedSourceFilesystem.promises.glob(`${namespace}/*`, {
|
|
86
|
+
onlyFiles: true,
|
|
87
|
+
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
88
|
+
cwd: '/'
|
|
89
|
+
}));
|
|
90
|
+
// the root namespace has updated
|
|
91
|
+
return namespaceDirFiles.length > 0;
|
|
116
92
|
}
|
|
117
93
|
};
|
|
118
94
|
export default BreadcrumbsPlugin;
|
|
119
|
-
|
|
120
95
|
//# sourceMappingURL=BreadcrumbsPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/BreadcrumbsPlugin.ts"],"
|
|
1
|
+
{"version":3,"file":"BreadcrumbsPlugin.js","sourceRoot":"","sources":["../src/BreadcrumbsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,WAAW,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAc3D;;GAEG;AACH,MAAM,iBAAiB,GAAgE;IACrF,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE,OAAO;QAChE,MAAM,eAAe,GAAG,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QACpE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;gBACnC,SAAS;aACV;YACD,IAAI;gBACF,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC/D,MAAM,gBAAgB,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBAChD,MAAM,WAAW,GAAG,gBAAgB,CAAC,MAAM,CACzC,CAAC,MAAM,EAA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