@jpmorganchase/mosaic-plugins 0.1.0-beta.7 → 0.1.0-beta.71
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 +34 -46
- package/dist/$AliasPlugin.js.map +1 -1
- package/dist/$CodeModPlugin.d.ts +7 -0
- package/dist/$CodeModPlugin.js +12 -28
- package/dist/$CodeModPlugin.js.map +1 -1
- package/dist/$RefPlugin.d.ts +31 -0
- package/dist/$RefPlugin.js +109 -108
- package/dist/$RefPlugin.js.map +1 -1
- package/dist/$TagPlugin.d.ts +28 -0
- package/dist/$TagPlugin.js +24 -44
- package/dist/$TagPlugin.js.map +1 -1
- package/dist/BreadcrumbsPlugin.d.ts +19 -0
- package/dist/BreadcrumbsPlugin.js +78 -34
- 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 +46 -79
- package/dist/LazyPagePlugin.js.map +1 -1
- package/dist/PagesWithoutFileExtPlugin.d.ts +9 -0
- package/dist/PagesWithoutFileExtPlugin.js +14 -29
- 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 +124 -32
- package/dist/SharedConfigPlugin.js.map +1 -1
- package/dist/SidebarPlugin.d.ts +44 -0
- package/dist/SidebarPlugin.js +235 -88
- package/dist/SidebarPlugin.js.map +1 -1
- package/dist/SiteMapPlugin.d.ts +9 -0
- package/dist/SiteMapPlugin.js +20 -34
- 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 +52 -69
- package/dist/utils/normaliseRefs.js.map +1 -1
- package/dist/utils/sortSidebarData.d.ts +19 -0
- package/dist/utils/sortSidebarData.js +35 -0
- package/dist/utils/sortSidebarData.js.map +1 -0
- package/package.json +42 -19
- package/CHANGELOG.md +0 -79
- package/dist/LocalFolderSavePlugin.js +0 -48
- package/dist/LocalFolderSavePlugin.js.map +0 -1
- package/dist/NextPrevPagePlugin.js +0 -63
- package/dist/NextPrevPagePlugin.js.map +0 -1
- package/dist/ReadingTimePlugin.mjs +0 -119
- package/dist/ReadingTimePlugin.mjs.map +0 -1
- package/dist/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/CHANGELOG.md
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# @jpmorganchase/mosaic-plugins
|
|
2
|
-
|
|
3
|
-
## 0.1.0-beta.7
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- 46adaec: Initial release of theme and client side search
|
|
8
|
-
|
|
9
|
-
We are iterating towards deploying our site code.
|
|
10
|
-
|
|
11
|
-
This release includes
|
|
12
|
-
|
|
13
|
-
- initial work for client-side search support
|
|
14
|
-
- Mosaic theme.
|
|
15
|
-
|
|
16
|
-
### Patch Changes
|
|
17
|
-
|
|
18
|
-
- Updated dependencies [46adaec]
|
|
19
|
-
- @jpmorganchase/mosaic-serialisers@0.1.0-beta.7
|
|
20
|
-
- @jpmorganchase/mosaic-source-git-repo@0.1.0-beta.7
|
|
21
|
-
- @jpmorganchase/mosaic-source-local-folder@0.1.0-beta.7
|
|
22
|
-
- @jpmorganchase/mosaic-types@0.1.0-beta.7
|
|
23
|
-
|
|
24
|
-
## 0.1.0-beta.6
|
|
25
|
-
|
|
26
|
-
### Patch Changes
|
|
27
|
-
|
|
28
|
-
- c103b24: Release fixes for snapshot serve
|
|
29
|
-
- Updated dependencies [c103b24]
|
|
30
|
-
- @jpmorganchase/mosaic-types@0.1.0-beta.6
|
|
31
|
-
|
|
32
|
-
## 0.1.0-beta.5
|
|
33
|
-
|
|
34
|
-
### Patch Changes
|
|
35
|
-
|
|
36
|
-
- 61a246c: This releases add support for generate / build and serve snapshots
|
|
37
|
-
- Updated dependencies [61a246c]
|
|
38
|
-
- @jpmorganchase/mosaic-types@0.1.0-beta.5
|
|
39
|
-
|
|
40
|
-
## 0.1.0-beta.4
|
|
41
|
-
|
|
42
|
-
### Patch Changes
|
|
43
|
-
|
|
44
|
-
- bd285df: added dist to package.json
|
|
45
|
-
- Updated dependencies [bd285df]
|
|
46
|
-
- @jpmorganchase/mosaic-types@0.1.0-beta.4
|
|
47
|
-
|
|
48
|
-
## 0.1.0-beta.3
|
|
49
|
-
|
|
50
|
-
### Patch Changes
|
|
51
|
-
|
|
52
|
-
- 457df5e: switch to public package
|
|
53
|
-
- Updated dependencies [457df5e]
|
|
54
|
-
- @jpmorganchase/mosaic-types@0.1.0-beta.3
|
|
55
|
-
|
|
56
|
-
## 0.1.0-beta.2
|
|
57
|
-
|
|
58
|
-
### Patch Changes
|
|
59
|
-
|
|
60
|
-
- e1bbbe7: Initial release of Mosaic Core file-system.
|
|
61
|
-
|
|
62
|
-
Mosaic is a content aggregating service which pulls content from heterogeneous data sources.
|
|
63
|
-
|
|
64
|
-
- 4b2bc51: pipped to 0.1.0-beta.1 for publishing to NPM
|
|
65
|
-
- Updated dependencies [e1bbbe7]
|
|
66
|
-
- Updated dependencies [4b2bc51]
|
|
67
|
-
- @jpmorganchase/mosaic-types@0.1.0-beta.2
|
|
68
|
-
|
|
69
|
-
## 0.1.0
|
|
70
|
-
|
|
71
|
-
### Patch Changes
|
|
72
|
-
|
|
73
|
-
- e1bbbe7: Initial release of Mosaic Core file-system.
|
|
74
|
-
|
|
75
|
-
Mosaic is a content aggregating service which pulls content from heterogeneous data sources.
|
|
76
|
-
|
|
77
|
-
- Updated dependencies [e1bbbe7]
|
|
78
|
-
- Updated dependencies [bbc853c]
|
|
79
|
-
- @jpmorganchase/mosaic-types@0.1.0
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const path_1 = __importDefault(require("path"));
|
|
27
|
-
const fs_1 = __importDefault(require("fs"));
|
|
28
|
-
const mdx_1 = __importDefault(require("@jpmorganchase/mosaic-serialisers/dist/mdx"));
|
|
29
|
-
const LocalFolderSavePlugin = {
|
|
30
|
-
saveContent(filePath, data, sourceOptions, { namespace }) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const { markdown } = data;
|
|
33
|
-
const { rootDir, prefixDir } = sourceOptions;
|
|
34
|
-
if (namespace !== 'local') {
|
|
35
|
-
// indicate to the Plugin Runner that no save happened
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
const pathOnDisk = path_1.default.posix.join(rootDir, filePath.replace(new RegExp(`${prefixDir}/`), ''));
|
|
39
|
-
const rawPage = yield fs_1.default.promises.readFile(pathOnDisk);
|
|
40
|
-
const _a = yield mdx_1.default.deserialise(pathOnDisk, rawPage), { content } = _a, metadata = __rest(_a, ["content"]);
|
|
41
|
-
const updatedPage = Object.assign(Object.assign({}, metadata), { content: markdown });
|
|
42
|
-
yield fs_1.default.promises.writeFile(pathOnDisk, yield mdx_1.default.serialise(pathOnDisk, updatedPage));
|
|
43
|
-
return true;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
exports.default = LocalFolderSavePlugin;
|
|
48
|
-
//# sourceMappingURL=LocalFolderSavePlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalFolderSavePlugin.js","sourceRoot":"","sources":["../src/LocalFolderSavePlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,4CAAoB;AAGpB,qFAAuF;AAMvF,MAAM,qBAAqB,GAAe;IAClC,WAAW,CACf,QAAQ,EACR,IAA+B,EAC/B,aAAuC,EACvC,EAAE,SAAS,EAAE;;YAEb,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;YAC1B,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,aAAa,CAAC;YAE7C,IAAI,SAAS,KAAK,OAAO,EAAE;gBACzB,sDAAsD;gBACtD,OAAO,KAAK,CAAC;aACd;YAED,MAAM,UAAU,GAAG,cAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YAC/F,MAAM,OAAO,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YACvD,MAAM,KAA2B,MAAM,aAAc,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,EAAhF,EAAE,OAAO,OAAuE,EAAlE,QAAQ,cAAtB,WAAwB,CAAwD,CAAC;YACvF,MAAM,WAAW,mCAAQ,QAAQ,KAAE,OAAO,EAAE,QAAQ,GAAE,CAAC;YAEvD,MAAM,YAAE,CAAC,QAAQ,CAAC,SAAS,CACzB,UAAU,EACV,MAAM,aAAc,CAAC,SAAS,CAAC,UAAU,EAAE,WAAW,CAAC,CACxD,CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;CACF,CAAC;AAEF,kBAAe,qBAAqB,CAAC"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const lodash_1 = require("lodash");
|
|
13
|
-
function createFileGlob(url, pageExtensions) {
|
|
14
|
-
if (pageExtensions.length === 1) {
|
|
15
|
-
return `${url}${pageExtensions[0]}`;
|
|
16
|
-
}
|
|
17
|
-
return `${url}{${pageExtensions.join(',')}}`;
|
|
18
|
-
}
|
|
19
|
-
function createSortFn(pageExtensions, { sortBy: _sortBy, indexFirst }) {
|
|
20
|
-
const indexRegExp = indexFirst && new RegExp(`index${pageExtensions.map(lodash_1.escapeRegExp).join('|')}$`);
|
|
21
|
-
// TODO: Switch out the algorithm here, based on `sortBy`
|
|
22
|
-
return function sortFn(fullPathA, fullPathB) {
|
|
23
|
-
// Always pin /index to the front
|
|
24
|
-
if (indexFirst && indexRegExp.test(fullPathA)) {
|
|
25
|
-
return -1;
|
|
26
|
-
}
|
|
27
|
-
return fullPathA.localeCompare(fullPathB);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Sorts the pages in a folder alphabetically and then embeds a `navigation` property to the metadata with ordered
|
|
32
|
-
* next/prev pages
|
|
33
|
-
*/
|
|
34
|
-
const NextPrevPlugin = {
|
|
35
|
-
$beforeSend(mutableFilesystem, { config, pageExtensions, ignorePages }, { indexFirst, sortBy }) {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const pageDirs = (yield mutableFilesystem.promises.glob('**', {
|
|
38
|
-
onlyDirectories: true,
|
|
39
|
-
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
40
|
-
cwd: '/'
|
|
41
|
-
}));
|
|
42
|
-
for (const dirName of pageDirs) {
|
|
43
|
-
const pages = (yield mutableFilesystem.promises.glob(createFileGlob('*', pageExtensions), {
|
|
44
|
-
onlyFiles: true,
|
|
45
|
-
cwd: dirName,
|
|
46
|
-
ignore: ignorePages
|
|
47
|
-
})).sort(createSortFn(pageExtensions, { indexFirst, sortBy }));
|
|
48
|
-
for (let i = 0; i < pages.length; i++) {
|
|
49
|
-
if (i > 0) {
|
|
50
|
-
config.setRef(pages[i], ['navigation', 'prev', 'title', '$ref'], `${pages[i - 1]}#/title`);
|
|
51
|
-
config.setRef(pages[i], ['navigation', 'prev', 'fullPath', '$ref'], `${pages[i - 1]}#/route`);
|
|
52
|
-
}
|
|
53
|
-
if (i < pages.length - 1) {
|
|
54
|
-
config.setRef(pages[i], ['navigation', 'next', 'title', '$ref'], `${pages[i + 1]}#/title`);
|
|
55
|
-
config.setRef(pages[i], ['navigation', 'next', 'fullPath', '$ref'], `${pages[i + 1]}#/route`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
exports.default = NextPrevPlugin;
|
|
63
|
-
//# sourceMappingURL=NextPrevPagePlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{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KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,CACzB,CAAC;qBACH;iBACF;aACF;QACH,CAAC;KAAA;CACF,CAAC;AAEF,kBAAe,cAAc,CAAC"}
|
|
@@ -1,119 +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 getReadingTime from "reading-time";
|
|
32
|
-
import markdown from "remark-parse";
|
|
33
|
-
import { unified } from "unified";
|
|
34
|
-
import { visit } from "unist-util-visit";
|
|
35
|
-
/**
|
|
36
|
-
* Calculates reading time for pages and adds to frontmatter
|
|
37
|
-
*/ var ReadingTimePlugin = {
|
|
38
|
-
$afterSource: function $afterSource(pages) {
|
|
39
|
-
return _asyncToGenerator(/*#__PURE__*/ regeneratorRuntime.mark(function _callee() {
|
|
40
|
-
var processor, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, page, tree, textContent;
|
|
41
|
-
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
|
42
|
-
while(1)switch(_ctx.prev = _ctx.next){
|
|
43
|
-
case 0:
|
|
44
|
-
processor = unified().use(markdown);
|
|
45
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
46
|
-
_ctx.prev = 2;
|
|
47
|
-
_iterator = pages[Symbol.iterator]();
|
|
48
|
-
case 4:
|
|
49
|
-
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
|
|
50
|
-
_ctx.next = 15;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
page = _step.value;
|
|
54
|
-
_ctx.next = 8;
|
|
55
|
-
return processor.parse(page.content);
|
|
56
|
-
case 8:
|
|
57
|
-
tree = _ctx.sent;
|
|
58
|
-
textContent = "";
|
|
59
|
-
visit(tree, function(node) {
|
|
60
|
-
return node.type === "text" || node.type === "code";
|
|
61
|
-
}, function(node) {
|
|
62
|
-
textContent += node.value;
|
|
63
|
-
});
|
|
64
|
-
page.readingTime = getReadingTime(textContent);
|
|
65
|
-
case 12:
|
|
66
|
-
_iteratorNormalCompletion = true;
|
|
67
|
-
_ctx.next = 4;
|
|
68
|
-
break;
|
|
69
|
-
case 15:
|
|
70
|
-
_ctx.next = 21;
|
|
71
|
-
break;
|
|
72
|
-
case 17:
|
|
73
|
-
_ctx.prev = 17;
|
|
74
|
-
_ctx.t0 = _ctx["catch"](2);
|
|
75
|
-
_didIteratorError = true;
|
|
76
|
-
_iteratorError = _ctx.t0;
|
|
77
|
-
case 21:
|
|
78
|
-
_ctx.prev = 21;
|
|
79
|
-
_ctx.prev = 22;
|
|
80
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
81
|
-
_iterator.return();
|
|
82
|
-
}
|
|
83
|
-
case 24:
|
|
84
|
-
_ctx.prev = 24;
|
|
85
|
-
if (!_didIteratorError) {
|
|
86
|
-
_ctx.next = 27;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
throw _iteratorError;
|
|
90
|
-
case 27:
|
|
91
|
-
return _ctx.finish(24);
|
|
92
|
-
case 28:
|
|
93
|
-
return _ctx.finish(21);
|
|
94
|
-
case 29:
|
|
95
|
-
return _ctx.abrupt("return", pages);
|
|
96
|
-
case 30:
|
|
97
|
-
case "end":
|
|
98
|
-
return _ctx.stop();
|
|
99
|
-
}
|
|
100
|
-
}, _callee, null, [
|
|
101
|
-
[
|
|
102
|
-
2,
|
|
103
|
-
17,
|
|
104
|
-
21,
|
|
105
|
-
29
|
|
106
|
-
],
|
|
107
|
-
[
|
|
108
|
-
22,
|
|
109
|
-
,
|
|
110
|
-
24,
|
|
111
|
-
28
|
|
112
|
-
]
|
|
113
|
-
]);
|
|
114
|
-
}))();
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
export default ReadingTimePlugin;
|
|
118
|
-
|
|
119
|
-
//# sourceMappingURL=ReadingTimePlugin.mjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ReadingTimePlugin.mjs.ts"],"sourcesContent":["import type { Page, Plugin as PluginType } from '@jpmorganchase/mosaic-types';\nimport getReadingTime from 'reading-time';\nimport markdown from 'remark-parse';\nimport { unified } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { Node } from 'unist';\n\ntype LeafNode = Node & {\n value?: string;\n};\n\ninterface ReadingTimePluginPage extends Page {\n readingTime?: ReturnType<typeof getReadingTime>;\n}\n\n/**\n * Calculates reading time for pages and adds to frontmatter\n */\nconst ReadingTimePlugin: PluginType<ReadingTimePluginPage> = {\n async $afterSource(pages) {\n const processor = unified().use(markdown);\n for (const page of pages) {\n const tree = await processor.parse(page.content);\n let textContent = '';\n\n visit(\n tree,\n node => node.type === 'text' || node.type === 'code',\n (node: LeafNode) => {\n textContent += node.value;\n }\n );\n page.readingTime = getReadingTime(textContent);\n }\n\n return pages;\n }\n};\n\nexport default ReadingTimePlugin;\n"],"names":["getReadingTime","markdown","unified","visit","ReadingTimePlugin","$afterSource","pages","processor","page","tree","textContent","use","parse","content","node","type","value","readingTime"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAOA,cAAc,MAAM,cAAc,CAAC;AAC1C,OAAOC,QAAQ,MAAM,cAAc,CAAC;AACpC,SAASC,OAAO,QAAQ,SAAS,CAAC;AAClC,SAASC,KAAK,QAAQ,kBAAkB,CAAC;AAWzC;;CAEC,GACD,IAAMC,iBAAiB,GAAsC;IACrDC,YAAY,EAAlB,SAAMA,YAAY,CAACC,KAAK;eAAE,wDAAA,mBAAA;gBAClBC,SAAS,EACV,yBAAU,EAAV,iBAAU,EAAV,cAAU,EAAV,SAAU,EAAV,KAAU,EAAJC,IAAI,EACPC,IAAI,EACNC,WAAW;;;;wBAHXH,SAAS,GAAGL,OAAO,EAAE,CAACS,GAAG,CAACV,QAAQ,CAAC,CAAC;wBACrC,yBAAU,SAAV,iBAAU,UAAV,cAAU;;wBAAV,SAAU,GAAIK,KAAK;;4BAAnB,yBAAU,IAAV,KAAU,GAAV,SAAU;;;;wBAAJE,IAAI,GAAV,KAAU,MAAA;;+BACMD,SAAS,CAACK,KAAK,CAACJ,IAAI,CAACK,OAAO,CAAC;;wBAA1CJ,IAAI,YAAsC,CAAA;wBAC5CC,WAAW,GAAG,EAAE,CAAC;wBAErBP,KAAK,CACHM,IAAI,EACJK,SAAAA,IAAI;mCAAIA,IAAI,CAACC,IAAI,KAAK,MAAM,IAAID,IAAI,CAACC,IAAI,KAAK,MAAM;yBAAA,EACpD,SAACD,IAAc,EAAK;4BAClBJ,WAAW,IAAII,IAAI,CAACE,KAAK,CAAC;yBAC3B,CACF,CAAC;wBACFR,IAAI,CAACS,WAAW,GAAGjB,cAAc,CAACU,WAAW,CAAC,CAAC;;wBAX5C,yBAAU;;;;;;;;;wBAAV,iBAAU;wBAAV,cAAU;;;;6BAAV,yBAAU,IAAV,SAAU;4BAAV,SAAU;;;;4BAAV,CAAA,iBAAU;;;;8BAAV,cAAU;;;;;;qDAcRJ,KAAK;;;;;;;;;;;;;;;;;;;SACb,EAAA;KAAA;CACF,AAAC;AAEF,eAAeF,iBAAiB,CAAC"}
|
|
@@ -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,EAC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