@jpmorganchase/mosaic-plugins 0.1.0-beta.3 → 0.1.0-beta.4
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/CHANGELOG.md +8 -0
- package/dist/$AliasPlugin.js +75 -0
- package/dist/$AliasPlugin.js.map +1 -0
- package/dist/$CodeModPlugin.js +42 -0
- package/dist/$CodeModPlugin.js.map +1 -0
- package/dist/$RefPlugin.js +146 -0
- package/dist/$RefPlugin.js.map +1 -0
- package/dist/$TagPlugin.js +90 -0
- package/dist/$TagPlugin.js.map +1 -0
- package/dist/BreadcrumbsPlugin.js +48 -0
- package/dist/BreadcrumbsPlugin.js.map +1 -0
- package/dist/LazyPagePlugin.js +95 -0
- package/dist/LazyPagePlugin.js.map +1 -0
- package/dist/NextPrevPagePlugin.js +59 -0
- package/dist/NextPrevPagePlugin.js.map +1 -0
- package/dist/PagesWithoutFileExtPlugin.js +47 -0
- package/dist/PagesWithoutFileExtPlugin.js.map +1 -0
- package/dist/ReadingTimePlugin.mjs +119 -0
- package/dist/ReadingTimePlugin.mjs.map +1 -0
- package/dist/SharedConfigPlugin.js +50 -0
- package/dist/SharedConfigPlugin.js.map +1 -0
- package/dist/SidebarPlugin.js +109 -0
- package/dist/SidebarPlugin.js.map +1 -0
- package/dist/SiteMapPlugin.js +44 -0
- package/dist/SiteMapPlugin.js.map +1 -0
- package/dist/TableOfContentsPlugin.mjs +140 -0
- package/dist/TableOfContentsPlugin.mjs.map +1 -0
- package/dist/utils/normaliseRefs.js +83 -0
- package/dist/utils/normaliseRefs.js.map +1 -0
- package/package.json +6 -3
- package/.turbo/turbo-build.log +0 -14
- package/src/$AliasPlugin.ts +0 -62
- package/src/$CodeModPlugin.ts +0 -34
- package/src/$RefPlugin.ts +0 -200
- package/src/$TagPlugin.ts +0 -99
- package/src/BreadcrumbsPlugin.ts +0 -43
- package/src/LazyPagePlugin.ts +0 -101
- package/src/NextPrevPagePlugin.ts +0 -80
- package/src/PagesWithoutFileExtPlugin.ts +0 -38
- package/src/ReadingTimePlugin.mjs.ts +0 -32
- package/src/SharedConfigPlugin.ts +0 -49
- package/src/SidebarPlugin.ts +0 -154
- package/src/SiteMapPlugin.ts +0 -44
- package/src/TableOfContentsPlugin.mjs.ts +0 -52
- package/src/utils/normaliseRefs.ts +0 -85
- package/tsconfig.json +0 -21
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,75 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const lodash_1 = require("lodash");
|
|
17
|
+
/**
|
|
18
|
+
* Plugin that scrapes `aliases` from page metadata and also applies all aliases stored in `config.data.aliases`
|
|
19
|
+
* Other plugins can use `setAliases` to apply new aliases, as long as they call it before this plugin has reaches `$beforeSend`
|
|
20
|
+
*/
|
|
21
|
+
const $AliasPlugin = {
|
|
22
|
+
$afterSource(pages, { config, ignorePages, pageExtensions }, options) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
25
|
+
// Group together all aliases defined in the frontmatter and store them in the alias config object
|
|
26
|
+
for (const page of pages) {
|
|
27
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (page.aliases) {
|
|
31
|
+
config.setAliases(page.fullPath, page.aliases);
|
|
32
|
+
}
|
|
33
|
+
delete page.aliases;
|
|
34
|
+
}
|
|
35
|
+
return pages;
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
$beforeSend(mutableFilesystem, { config }) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
// Prevent any more aliases being set after this lifecycle has been called - as they won't take effect
|
|
41
|
+
config.setAliases = () => {
|
|
42
|
+
throw new Error('Cannot set aliases after `$AliasPlugin` has reached `$beforeSend` lifecycle phase.');
|
|
43
|
+
};
|
|
44
|
+
if (!config.data.aliases) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
for (const fullPath in config.data.aliases) {
|
|
48
|
+
for (const alias of config.data.aliases[fullPath]) {
|
|
49
|
+
const aliasPath = path_1.default.resolve(path_1.default.dirname(fullPath), alias).toLowerCase();
|
|
50
|
+
const aliasDir = path_1.default.dirname(aliasPath);
|
|
51
|
+
if (!(yield mutableFilesystem.promises.exists(aliasDir))) {
|
|
52
|
+
yield mutableFilesystem.promises.mkdir(aliasDir, {
|
|
53
|
+
recursive: true
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (!(yield mutableFilesystem.promises.exists(aliasPath))) {
|
|
57
|
+
yield mutableFilesystem.promises.symlink(fullPath, aliasPath);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
console.warn(`Alias '${aliasPath}' already exists. Is there a duplicate alias, or a page with the same name but different file extensions?`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
exports.default = $AliasPlugin;
|
|
68
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
69
|
+
const extTest = new RegExp(`${pageExtensions.map(lodash_1.escapeRegExp).join('|')}$`);
|
|
70
|
+
const ignoreTest = new RegExp(`${ignorePages.map(lodash_1.escapeRegExp).join('|')}$`);
|
|
71
|
+
return file => {
|
|
72
|
+
return !ignoreTest.test(file) && extTest.test(file) && !path_1.default.basename(file).startsWith('.');
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=$AliasPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"$AliasPlugin.js","sourceRoot":"","sources":["../src/$AliasPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDAAwB;AAIxB,mCAAsC;AAEtC;;;GAGG;AACH,MAAM,YAAY,GAA4D;IACtE,YAAY,CAAC,KAAqC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE,OAAO;;YACxG,MAAM,eAAe,GAAG,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;YAEpE,kGAAkG;YAClG,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;oBACnC,SAAS;iBACV;gBACD,IAAI,IAAI,CAAC,OAAO,EAAE;oBAChB,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;iBAChD;gBACD,OAAO,IAAI,CAAC,OAAO,CAAC;aACrB;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;IAEK,WAAW,CAAC,iBAAiB,EAAE,EAAE,MAAM,EAAE;;YAC7C,sGAAsG;YACtG,MAAM,CAAC,UAAU,GAAG,GAAG,EAAE;gBACvB,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;YACxG,CAAC,CAAC;YAAI,IAAI,CAAC,MAAM,CAAC,IAAI,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,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC,EAAE;QACZ,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC9F,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const lodash_1 = require("lodash");
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const $CodeModPlugin = {
|
|
18
|
+
$afterSource(pages, { ignorePages, pageExtensions }) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
21
|
+
for (const page of pages) {
|
|
22
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (page.frameOverrides) {
|
|
26
|
+
page.sharedConfig = page.frameOverrides;
|
|
27
|
+
page.frameOverrides = { $ref: '#/sharedConfig' };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return pages;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.default = $CodeModPlugin;
|
|
35
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
36
|
+
const extTest = new RegExp(`${pageExtensions.map(lodash_1.escapeRegExp).join('|')}$`);
|
|
37
|
+
const ignoreTest = new RegExp(`${ignorePages.map(lodash_1.escapeRegExp).join('|')}$`);
|
|
38
|
+
return file => {
|
|
39
|
+
return !ignoreTest.test(file) && extTest.test(file) && !path_1.default.basename(file).startsWith('.');
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=$CodeModPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"$CodeModPlugin.js","sourceRoot":"","sources":["../src/$CodeModPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,mCAAsC;AACtC,gDAAwB;AAExB,MAAM,cAAc,GAGf;IACG,YAAY,CAAC,KAAa,EAAE,EAAE,WAAW,EAAE,cAAc,EAAE;;YAC/D,MAAM,eAAe,GAAG,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;YAEpE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;oBACnC,SAAS;iBACV;gBACD,IAAI,IAAI,CAAC,cAAc,EAAE;oBACvB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC;oBACxC,IAAI,CAAC,cAAc,GAAG,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC;iBAClD;aACF;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;CACF,CAAC;AAEF,kBAAe,cAAc,CAAC;AAE9B,SAAS,cAAc,CAAC,WAAW,EAAE,cAAc;IACjD,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,qBAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7E,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,qBAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC,EAAE;QACZ,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC9F,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const reduce_1 = __importDefault(require("lodash/reduce"));
|
|
17
|
+
const omit_1 = __importDefault(require("lodash/omit"));
|
|
18
|
+
const escapeRegExp_1 = __importDefault(require("lodash/escapeRegExp"));
|
|
19
|
+
const json_schema_ref_parser_1 = __importDefault(require("@apidevtools/json-schema-ref-parser"));
|
|
20
|
+
const normaliseRefs_1 = __importDefault(require("./utils/normaliseRefs"));
|
|
21
|
+
/**
|
|
22
|
+
* Plugin that scrapes `$ref` properties from page metadata and also applies all refs stored in `config.data.refs`.
|
|
23
|
+
* Other plugins can use `setRef` to apply new refs, as long as they call it before this plugin has reaches `$beforeSend`
|
|
24
|
+
*/
|
|
25
|
+
const $RefPlugin = {
|
|
26
|
+
afterUpdate(mutableFilesystem, { ignorePages, globalFilesystem, serialiser, pageExtensions, globalConfig }) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
mutableFilesystem.__internal_do_not_use_addReadFileHook((pagePath, fileData) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
if (globalConfig.data.globalRefs[pagePath]) {
|
|
30
|
+
const normalisedRef = Object.assign(Object.assign({}, (yield serialiser.deserialise(pagePath, fileData))), (yield (0, normaliseRefs_1.default)(String(pagePath), globalConfig.data.globalRefs[pagePath], globalFilesystem, pageExtensions, ignorePages)));
|
|
31
|
+
const resolve = createRefResolver({
|
|
32
|
+
[pagePath]: normalisedRef
|
|
33
|
+
}, serialiser, globalFilesystem);
|
|
34
|
+
const refParser = new json_schema_ref_parser_1.default();
|
|
35
|
+
try {
|
|
36
|
+
const resolved = yield refParser.dereference(String(pagePath), normalisedRef, {
|
|
37
|
+
resolve,
|
|
38
|
+
dereference: { circular: false }
|
|
39
|
+
});
|
|
40
|
+
return serialiser.serialise(pagePath, Object.assign(Object.assign({}, normalisedRef), resolved));
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
console.warn(`Error resolving ref(s) for page '${pagePath}'. ${e.message.replace(/\.$/, '')} in '${e.source}'`);
|
|
44
|
+
throw e;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return fileData;
|
|
48
|
+
}));
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
$beforeSend(mutableFilesystem, { config, serialiser, pageExtensions, ignorePages }, options) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
// Prevent any more refs being set after this lifecycle has been called - as they won't take effect
|
|
54
|
+
config.setRef = () => {
|
|
55
|
+
throw new Error('Cannot set refs after `RefPlugin` has reached `$beforeSend` lifecycle phase.');
|
|
56
|
+
};
|
|
57
|
+
const normalisedRefs = {};
|
|
58
|
+
if (config.data.refs) {
|
|
59
|
+
// First pass of refs, normalises any $ref entries to expand wildcards
|
|
60
|
+
for (const fullPath in config.data.refs) {
|
|
61
|
+
const page = yield serialiser.deserialise(fullPath, yield mutableFilesystem.promises.readFile(fullPath));
|
|
62
|
+
normalisedRefs[fullPath] = Object.assign(Object.assign({}, page), (yield (0, normaliseRefs_1.default)(String(fullPath), config.data.refs[fullPath], mutableFilesystem, pageExtensions, ignorePages)));
|
|
63
|
+
}
|
|
64
|
+
const resolve = createRefResolver(normalisedRefs, serialiser, mutableFilesystem);
|
|
65
|
+
const refParser = new json_schema_ref_parser_1.default();
|
|
66
|
+
// Second pass of refs, resolves the refs
|
|
67
|
+
for (const fullPath in normalisedRefs) {
|
|
68
|
+
const page = normalisedRefs[fullPath];
|
|
69
|
+
try {
|
|
70
|
+
const resolved = yield refParser.dereference(String(fullPath), page, {
|
|
71
|
+
resolve,
|
|
72
|
+
dereference: { circular: false }
|
|
73
|
+
});
|
|
74
|
+
normalisedRefs[fullPath] = Object.assign(Object.assign({}, page), resolved);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
console.warn(`Error resolving ref(s) for page '${fullPath}'. ${e.message.replace(/\.$/, '')} in '${e.source}'`);
|
|
78
|
+
throw e;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Third pass, write out the files
|
|
82
|
+
for (const fullPath in normalisedRefs) {
|
|
83
|
+
yield mutableFilesystem.promises.writeFile(fullPath, yield serialiser.serialise(fullPath, normalisedRefs[fullPath]));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
$afterSource(pages, { config, ignorePages, pageExtensions }) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
91
|
+
for (const page of pages) {
|
|
92
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const refs = findKeys(page, '$ref');
|
|
96
|
+
if (refs.length) {
|
|
97
|
+
for (const ref of refs) {
|
|
98
|
+
config.setRef(page.fullPath, ...ref);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return pages;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
exports.default = $RefPlugin;
|
|
107
|
+
function createRefResolver(normalisedRefs, serialiser, mutableFilesystem) {
|
|
108
|
+
return {
|
|
109
|
+
file: {
|
|
110
|
+
canRead: true,
|
|
111
|
+
order: 1,
|
|
112
|
+
read(file, callback) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
try {
|
|
115
|
+
const refedPage = normalisedRefs[file.url] ||
|
|
116
|
+
(yield serialiser.deserialise(file.url, yield mutableFilesystem.promises.readFile(file.url)));
|
|
117
|
+
return callback(null, (0, omit_1.default)(refedPage, 'content'));
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
return callback(e, null);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const findKeys = (obj, targetProp, pathParts = []) => {
|
|
128
|
+
return (0, reduce_1.default)(obj, (found, value, key) => {
|
|
129
|
+
if (key === targetProp) {
|
|
130
|
+
return found.concat([[pathParts.concat(String(key)), value]]);
|
|
131
|
+
}
|
|
132
|
+
if (typeof value === 'object') {
|
|
133
|
+
const foundParents = findKeys(value, targetProp, pathParts.concat(String(key)));
|
|
134
|
+
return found.concat(foundParents);
|
|
135
|
+
}
|
|
136
|
+
return found;
|
|
137
|
+
}, []);
|
|
138
|
+
};
|
|
139
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
140
|
+
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp_1.default).join('|')}$`);
|
|
141
|
+
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp_1.default).join('|')}$`);
|
|
142
|
+
return file => {
|
|
143
|
+
return !ignoreTest.test(file) && extTest.test(file) && !path_1.default.basename(file).startsWith('.');
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=$RefPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"$RefPlugin.js","sourceRoot":"","sources":["../src/$RefPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDAAwB;AAExB,2DAAmC;AACnC,uDAA+B;AAE/B,uEAA+C;AAC/C,iGAA6D;AAK7D,0EAAkD;AAElD;;;GAGG;AACH,MAAM,UAAU,GAIX;IACG,WAAW,CACf,iBAAiB,EACjB,EAAE,WAAW,EAAE,gBAAgB,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE;;YAE3E,iBAAiB,CAAC,qCAAqC,CAAC,CAAO,QAAgB,EAAE,QAAQ,EAAE,EAAE;gBAC3F,IAAI,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;oBAC1C,MAAM,aAAa,GAAG,gCACjB,CAAC,MAAM,UAAU,CAAC,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,GAClD,CAAC,MAAM,IAAA,uBAAa,EACrB,MAAM,CAAC,QAAQ,CAAC,EAChB,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EACtC,gBAAgB,EAChB,cAAc,EACd,WAAW,CACZ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,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const reduce_1 = __importDefault(require("lodash/reduce"));
|
|
17
|
+
const escapeRegExp_1 = __importDefault(require("lodash/escapeRegExp"));
|
|
18
|
+
/**
|
|
19
|
+
* Plugin that scrapes `$tag` from page metadata and also applies all aliases stored in `config.data.tags`.
|
|
20
|
+
* Tags ultimately resolve down into refs, but are different from normal refs, in that they are applied to the
|
|
21
|
+
* union filesystem (all merged filesystems), not to the individual source filesystem that they were defined on.
|
|
22
|
+
* Other plugins can use `setData()` and modify the `tags` property, to apply new global refs, as long as
|
|
23
|
+
* they do so before this plugin has reaches `$beforeSend`
|
|
24
|
+
*/
|
|
25
|
+
const $TagPlugin = {
|
|
26
|
+
// Check if the updated source has any /.tag aliases that we care about - if it does, we should re-run `afterUpdate` to
|
|
27
|
+
// make sure we pull in the latest pages
|
|
28
|
+
shouldClearCache(updatedSourceFilesystem, { config }) {
|
|
29
|
+
var _a;
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
if (!((_a = config.data) === null || _a === void 0 ? void 0 : _a.subscribedTags) ||
|
|
32
|
+
!(yield updatedSourceFilesystem.promises.exists('/.tags'))) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
// Does the updated source have tags we are interested in?
|
|
36
|
+
return (yield updatedSourceFilesystem.promises.readdir('/.tags')).some(tag => config.data.subscribedTags.includes(tag));
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
// Every source with tags will create symlinks with the tagged pages, inside /.tags
|
|
40
|
+
$afterSource(pages, { config, ignorePages, pageExtensions }) {
|
|
41
|
+
var _a;
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
44
|
+
for (const page of pages) {
|
|
45
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const meta = page;
|
|
49
|
+
// Symlink every `tag` item to '/.tags' folder
|
|
50
|
+
if ((_a = meta.tags) === null || _a === void 0 ? void 0 : _a.length) {
|
|
51
|
+
config.setTags(page.fullPath, meta.tags);
|
|
52
|
+
delete meta.tags;
|
|
53
|
+
}
|
|
54
|
+
// Find any references to $tag
|
|
55
|
+
const foundTags = findKeys(page, '$tag');
|
|
56
|
+
if (foundTags.length) {
|
|
57
|
+
const tags = new Set();
|
|
58
|
+
foundTags.forEach(ref => {
|
|
59
|
+
const [tag, fragment = ''] = ref.$$value.split('#');
|
|
60
|
+
tags.add(tag);
|
|
61
|
+
config.setGlobalRef(page.fullPath, ref.$$path, `${path_1.default.join('/.tags', tag, '**')}#${fragment}`);
|
|
62
|
+
});
|
|
63
|
+
config.setData({ subscribedTags: Array.from(tags) });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return pages;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.default = $TagPlugin;
|
|
71
|
+
const findKeys = (obj, targetProp, pathParts = []) => {
|
|
72
|
+
return (0, reduce_1.default)(obj, (found, value, key) => {
|
|
73
|
+
if (key === targetProp) {
|
|
74
|
+
return found.concat({ $$path: pathParts.concat(String(key)), $$value: value });
|
|
75
|
+
}
|
|
76
|
+
if (typeof value === 'object') {
|
|
77
|
+
const foundParents = findKeys(value, targetProp, pathParts.concat(String(key)));
|
|
78
|
+
return found.concat(...foundParents);
|
|
79
|
+
}
|
|
80
|
+
return found;
|
|
81
|
+
}, []);
|
|
82
|
+
};
|
|
83
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
84
|
+
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp_1.default).join('|')}$`);
|
|
85
|
+
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp_1.default).join('|')}$`);
|
|
86
|
+
return file => {
|
|
87
|
+
return !ignoreTest.test(file) && extTest.test(file) && !path_1.default.basename(file).startsWith('.');
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=$TagPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"$TagPlugin.js","sourceRoot":"","sources":["../src/$TagPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDAAwB;AAExB,2DAAmC;AACnC,uEAA+C;AAM/C;;;;;;GAMG;AACH,MAAM,UAAU,GAIX;IACH,uHAAuH;IACvH,wCAAwC;IAClC,gBAAgB,CAAC,uBAAuB,EAAE,EAAE,MAAM,EAAE;;;YACxD,IACE,CAAC,CAAA,MAAA,MAAM,CAAC,IAAI,0CAAE,cAAc,CAAA;gBAC5B,CAAC,CAAC,MAAM,uBAAuB,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAC1D;gBACA,OAAO,KAAK,CAAC;aACd;YACD,0DAA0D;YAC1D,OAAQ,CAAC,MAAM,uBAAuB,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAc,CAAC,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CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC9F,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
/**
|
|
17
|
+
* Calculates breadcrumbs for pages then embeds a `breadcrumbs` property to the metadata
|
|
18
|
+
*/
|
|
19
|
+
const BreadcrumbsPlugin = {
|
|
20
|
+
$afterSource(pages, {}, options) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
for (const page of pages) {
|
|
23
|
+
const breadcrumbs = [];
|
|
24
|
+
let currentPage = page;
|
|
25
|
+
let parentDir = path_1.default.posix.dirname(currentPage.fullPath);
|
|
26
|
+
while (currentPage !== undefined) {
|
|
27
|
+
if (breadcrumbs.findIndex(breadcrumb => breadcrumb.id === currentPage.fullPath) === -1) {
|
|
28
|
+
breadcrumbs.unshift({
|
|
29
|
+
label: currentPage.title,
|
|
30
|
+
path: currentPage.route,
|
|
31
|
+
id: currentPage.fullPath
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
currentPage = pages.find(page => page.fullPath === path_1.default.posix.join(parentDir, options.indexPageName));
|
|
35
|
+
if (currentPage) {
|
|
36
|
+
parentDir = path_1.default.posix.dirname(path_1.default.posix.join(String(currentPage.fullPath), '..'));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!page.breadcrumbs) {
|
|
40
|
+
page.breadcrumbs = breadcrumbs;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return pages;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.default = BreadcrumbsPlugin;
|
|
48
|
+
//# sourceMappingURL=BreadcrumbsPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BreadcrumbsPlugin.js","sourceRoot":"","sources":["../src/BreadcrumbsPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,gDAAwB;AAIxB;;GAEG;AACH,MAAM,iBAAiB,GAA8C;IAC7D,YAAY,CAAC,KAAa,EAAE,EAAE,EAAE,OAAO;;YAC3C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,MAAM,WAAW,GAAsB,EAAE,CAAC;gBAC1C,IAAI,WAAW,GAAG,IAAI,CAAC;gBACvB,IAAI,SAAS,GAAG,cAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;gBAEzD,OAAO,WAAW,KAAK,SAAS,EAAE;oBAChC,IAAI,WAAW,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE;wBACtF,WAAW,CAAC,OAAO,CAAC;4BAClB,KAAK,EAAE,WAAW,CAAC,KAAK;4BACxB,IAAI,EAAE,WAAW,CAAC,KAAK;4BACvB,EAAE,EAAE,WAAW,CAAC,QAAQ;yBACzB,CAAC,CAAC;qBACJ;oBAED,WAAW,GAAG,KAAK,CAAC,IAAI,CACtB,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,cAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,aAAa,CAAC,CAC5E,CAAC;oBACF,IAAI,WAAW,EAAE;wBACf,SAAS,GAAG,cAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;qBACrF;iBACF;gBAED,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;oBACrB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;iBAChC;aACF;YAED,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;CACF,CAAC;AAEF,kBAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
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 fs_1 = __importDefault(require("fs"));
|
|
27
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
28
|
+
const merge_1 = __importDefault(require("lodash/merge"));
|
|
29
|
+
const escapeRegExp_1 = __importDefault(require("lodash/escapeRegExp"));
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
31
|
+
const LazyPagePlugin = {
|
|
32
|
+
afterUpdate(mutableFilesystem, { ignorePages, config, pageExtensions, serialiser }) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
35
|
+
// This adds a hook that triggers everytime a non-cached page is read from the filesystem.
|
|
36
|
+
mutableFilesystem.__internal_do_not_use_addReadFileHook((pagePath, fileData) => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
// If this is a 'page' - read the original file from disk and try to inject anything that's missing.
|
|
38
|
+
if (isNonHiddenPage(pagePath)) {
|
|
39
|
+
const currentPage = yield serialiser.deserialise(pagePath, fileData);
|
|
40
|
+
if (config.data.hddPaths[pagePath]) {
|
|
41
|
+
const page = yield serialiser.deserialise(pagePath, yield fs_1.default.promises.readFile(config.data.hddPaths[pagePath]));
|
|
42
|
+
const completePage = yield serialiser.serialise(pagePath, (0, merge_1.default)(page, currentPage, { content: page.content }));
|
|
43
|
+
return completePage;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return fileData;
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
$beforeSend(mutableFilesystem, { config, serialiser, ignorePages, pageExtensions }, options) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const hddPaths = {};
|
|
53
|
+
let originalDiskSize = 0;
|
|
54
|
+
let newDiskSize = 0;
|
|
55
|
+
const allPages = yield mutableFilesystem.promises.glob(createFileGlob('**', pageExtensions), {
|
|
56
|
+
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
57
|
+
cwd: '/',
|
|
58
|
+
onlyFiles: true
|
|
59
|
+
});
|
|
60
|
+
const baseDir = path_1.default.join(process.cwd(), options.cacheDir || '.mosaic-lazy-page-plugin-cache');
|
|
61
|
+
yield fs_extra_1.default.ensureDir(baseDir);
|
|
62
|
+
for (const filePath of allPages) {
|
|
63
|
+
const rawPage = yield mutableFilesystem.promises.readFile(String(filePath));
|
|
64
|
+
const page = yield serialiser.deserialise(String(filePath), rawPage);
|
|
65
|
+
originalDiskSize += rawPage.length;
|
|
66
|
+
yield fs_1.default.promises.mkdir(path_1.default.dirname(path_1.default.join(baseDir, String(filePath))), {
|
|
67
|
+
recursive: true
|
|
68
|
+
});
|
|
69
|
+
yield fs_1.default.promises.writeFile(path_1.default.join(baseDir, String(filePath)), yield serialiser.serialise(String(filePath), page));
|
|
70
|
+
const { content } = page, pageRest = __rest(page, ["content"]);
|
|
71
|
+
hddPaths[String(filePath)] = path_1.default.join(baseDir, String(filePath));
|
|
72
|
+
const redactedPage = yield serialiser.serialise(String(filePath), pageRest);
|
|
73
|
+
newDiskSize += redactedPage.length;
|
|
74
|
+
}
|
|
75
|
+
config.setData({ hddPaths });
|
|
76
|
+
const reduction = originalDiskSize - newDiskSize;
|
|
77
|
+
console.info(`[PullDocs] LazyPagePlugin moved ${((reduction / originalDiskSize) * 100).toFixed(2)}% of virtual filesystem content to the hard disk. This reduced the virtual filesystem size from ${(originalDiskSize / 1000000).toFixed(2)}mb to ${(newDiskSize / 1000000).toFixed(2)}mb (yay!)`);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
function createFileGlob(url, pageExtensions) {
|
|
82
|
+
if (pageExtensions.length === 1) {
|
|
83
|
+
return `${url}${pageExtensions[0]}`;
|
|
84
|
+
}
|
|
85
|
+
return `${url}{${pageExtensions.join(',')}}`;
|
|
86
|
+
}
|
|
87
|
+
exports.default = LazyPagePlugin;
|
|
88
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
89
|
+
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp_1.default).join('|')}$`);
|
|
90
|
+
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp_1.default).join('|')}$`);
|
|
91
|
+
return file => {
|
|
92
|
+
return !ignoreTest.test(file) && extTest.test(file) && !path_1.default.basename(file).startsWith('.');
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=LazyPagePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LazyPagePlugin.js","sourceRoot":"","sources":["../src/LazyPagePlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,4CAAoB;AACpB,wDAA+B;AAC/B,yDAAiC;AACjC,uEAA+C;AAC/C,gDAAwB;AAGxB,MAAM,cAAc,GAGhB;IACI,WAAW,CAAC,iBAAiB,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE;;YACtF,MAAM,eAAe,GAAG,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;YAEpE,0FAA0F;YAC1F,iBAAiB,CAAC,qCAAqC,CACrD,CAAO,QAAgB,EAAE,QAAkB,EAAE,EAAE;gBAC7C,oGAAoG;gBACpG,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE;oBAC7B,M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) || 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
|
+
/**
|
|
14
|
+
* Sorts the pages in a folder alphabetically and then embeds a `navigation` property to the metadata with ordered
|
|
15
|
+
* next/prev pages
|
|
16
|
+
*/
|
|
17
|
+
const NextPrevPlugin = {
|
|
18
|
+
$beforeSend(mutableFilesystem, { config, pageExtensions, ignorePages }, { indexFirst, sortBy }) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const pageDirs = (yield mutableFilesystem.promises.glob('**', {
|
|
21
|
+
onlyDirectories: true,
|
|
22
|
+
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
23
|
+
cwd: '/'
|
|
24
|
+
}));
|
|
25
|
+
for (const dirName of pageDirs) {
|
|
26
|
+
const pages = (yield mutableFilesystem.promises.glob(createFileGlob('*', pageExtensions), { onlyFiles: true, cwd: dirName, ignore: ignorePages })).sort(createSortFn(pageExtensions, { indexFirst, sortBy }));
|
|
27
|
+
for (let i = 0; i < pages.length; i++) {
|
|
28
|
+
if (i > 0) {
|
|
29
|
+
config.setRef(pages[i], ['navigation', 'prev', 'title', '$ref'], `${pages[i - 1]}#/title`);
|
|
30
|
+
config.setRef(pages[i], ['navigation', 'prev', 'fullPath', '$ref'], `${pages[i - 1]}#/route`);
|
|
31
|
+
}
|
|
32
|
+
if (i < pages.length - 1) {
|
|
33
|
+
config.setRef(pages[i], ['navigation', 'next', 'title', '$ref'], `${pages[i + 1]}#/title`);
|
|
34
|
+
config.setRef(pages[i], ['navigation', 'next', 'fullPath', '$ref'], `${pages[i + 1]}#/route`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.default = NextPrevPlugin;
|
|
42
|
+
function createFileGlob(url, pageExtensions) {
|
|
43
|
+
if (pageExtensions.length === 1) {
|
|
44
|
+
return `${url}${pageExtensions[0]}`;
|
|
45
|
+
}
|
|
46
|
+
return `${url}{${pageExtensions.join(',')}}`;
|
|
47
|
+
}
|
|
48
|
+
function createSortFn(pageExtensions, { sortBy: _sortBy, indexFirst }) {
|
|
49
|
+
const indexRegExp = indexFirst && new RegExp(`index${pageExtensions.map(lodash_1.escapeRegExp).join('|')}$`);
|
|
50
|
+
// TODO: Switch out the algorithm here, based on `sortBy`
|
|
51
|
+
return function sortFn(fullPathA, fullPathB) {
|
|
52
|
+
// Always pin /index to the front
|
|
53
|
+
if (indexFirst && indexRegExp.test(fullPathA)) {
|
|
54
|
+
return -1;
|
|
55
|
+
}
|
|
56
|
+
return fullPathA.localeCompare(fullPathB);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=NextPrevPagePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextPrevPagePlugin.js","sourceRoot":"","sources":["../src/NextPrevPagePlugin.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,mCAAsC;AAEtC;;;GAGG;AACH,MAAM,cAAc,GAMhB;IACI,WAAW,CACf,iBAAiB,EACjB,EAAE,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,EACvC,EAAE,UAAU,EAAE,MAAM,EAAE;;YAEtB,MAAM,QAAQ,GAAG,CAAC,MAAM,iBAAiB,CAAC,QAAQ,CAAC,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