@jpmorganchase/mosaic-plugins 0.1.0-beta.3 → 0.1.0-beta.30
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 +55 -0
- package/dist/$AliasPlugin.js.map +1 -0
- package/dist/$CodeModPlugin.d.ts +7 -0
- package/dist/$CodeModPlugin.js +24 -0
- package/dist/$CodeModPlugin.js.map +1 -0
- package/dist/$RefPlugin.d.ts +31 -0
- package/dist/$RefPlugin.js +119 -0
- package/dist/$RefPlugin.js.map +1 -0
- package/dist/$TagPlugin.d.ts +28 -0
- package/dist/$TagPlugin.js +65 -0
- package/dist/$TagPlugin.js.map +1 -0
- package/dist/BreadcrumbsPlugin.d.ts +18 -0
- package/dist/BreadcrumbsPlugin.js +38 -0
- package/dist/BreadcrumbsPlugin.js.map +1 -0
- package/dist/BrokenLinksPlugin.d.ts +10 -0
- package/dist/BrokenLinksPlugin.js +80 -0
- package/dist/BrokenLinksPlugin.js.map +1 -0
- package/dist/LazyPagePlugin.d.ts +14 -0
- package/dist/LazyPagePlugin.js +63 -0
- package/dist/LazyPagePlugin.js.map +1 -0
- package/dist/LocalFolderSavePlugin.d.ts +6 -0
- package/dist/LocalFolderSavePlugin.js +21 -0
- package/dist/LocalFolderSavePlugin.js.map +1 -0
- package/dist/PagesWithoutFileExtPlugin.d.ts +9 -0
- package/dist/PagesWithoutFileExtPlugin.js +29 -0
- package/dist/PagesWithoutFileExtPlugin.js.map +1 -0
- package/dist/PublicAssetsPlugin.d.ts +18 -0
- package/dist/PublicAssetsPlugin.js +28 -0
- package/dist/PublicAssetsPlugin.js.map +1 -0
- package/dist/ReadingTimePlugin.d.ts +10 -0
- package/dist/ReadingTimePlugin.js +23 -0
- package/dist/ReadingTimePlugin.js.map +1 -0
- package/dist/SearchIndexPlugin.d.ts +56 -0
- package/dist/SearchIndexPlugin.js +152 -0
- package/dist/SearchIndexPlugin.js.map +1 -0
- package/dist/SharedConfigPlugin.d.ts +13 -0
- package/dist/SharedConfigPlugin.js +34 -0
- package/dist/SharedConfigPlugin.js.map +1 -0
- package/dist/SidebarPlugin.d.ts +38 -0
- package/dist/SidebarPlugin.js +207 -0
- package/dist/SidebarPlugin.js.map +1 -0
- package/dist/SiteMapPlugin.d.ts +6 -0
- package/dist/SiteMapPlugin.js +27 -0
- package/dist/SiteMapPlugin.js.map +1 -0
- package/dist/TableOfContentsPlugin.d.ts +20 -0
- package/dist/TableOfContentsPlugin.js +43 -0
- package/dist/TableOfContentsPlugin.js.map +1 -0
- package/dist/utils/normaliseRefs.d.ts +1 -0
- package/dist/utils/normaliseRefs.js +66 -0
- package/dist/utils/normaliseRefs.js.map +1 -0
- package/package.json +41 -15
- package/.turbo/turbo-build.log +0 -14
- package/CHANGELOG.md +0 -34
- 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/src/SidebarPlugin.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import type PluginType from '@jpmorganchase/mosaic-types/dist/Plugin';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Sorts the pages in a folder by priority and then exports a JSON file (name: `options.filename`) with the
|
|
6
|
-
* sidebar tree from that directory downwards and adds sidebar data into frontmatter for each page.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const SidebarPlugin: PluginType<
|
|
10
|
-
{
|
|
11
|
-
dirs: string[];
|
|
12
|
-
refs: { [key: string]: { $$path: (number | string)[]; $$value: string }[] };
|
|
13
|
-
},
|
|
14
|
-
{ filename: string }
|
|
15
|
-
> = {
|
|
16
|
-
async $beforeSend(
|
|
17
|
-
mutableFilesystem,
|
|
18
|
-
{ config, serialiser, ignorePages, pageExtensions },
|
|
19
|
-
options
|
|
20
|
-
) {
|
|
21
|
-
const dirs = await mutableFilesystem.promises.glob('**', {
|
|
22
|
-
onlyDirectories: true,
|
|
23
|
-
cwd: '/'
|
|
24
|
-
});
|
|
25
|
-
for (const dirName of dirs) {
|
|
26
|
-
const sidebarFilePath = path.posix.join(String(dirName), options.filename);
|
|
27
|
-
const pages = (
|
|
28
|
-
await Promise.all(
|
|
29
|
-
((await mutableFilesystem.promises.glob(
|
|
30
|
-
createFileGlob(['*', '*/index'], pageExtensions),
|
|
31
|
-
{
|
|
32
|
-
onlyFiles: true,
|
|
33
|
-
cwd: String(dirName),
|
|
34
|
-
ignore: ignorePages.map(ignore => `**/${ignore}`)
|
|
35
|
-
}
|
|
36
|
-
)) as string[]).map(async pagePath => {
|
|
37
|
-
return await serialiser.deserialise(
|
|
38
|
-
pagePath,
|
|
39
|
-
await mutableFilesystem.promises.readFile(pagePath)
|
|
40
|
-
);
|
|
41
|
-
})
|
|
42
|
-
)
|
|
43
|
-
)
|
|
44
|
-
.filter(page => filterFn(page))
|
|
45
|
-
.sort((pageA, pageB) => sortFn(pageA, pageB, dirName));
|
|
46
|
-
|
|
47
|
-
for (let i = 0; i < pages.length; i++) {
|
|
48
|
-
setPageRefs(sidebarFilePath, pages[i], i);
|
|
49
|
-
setChildPageRefs(pages[i], dirName, i, sidebarFilePath);
|
|
50
|
-
addSidebarDataToFrontmatter(pages[i], dirName);
|
|
51
|
-
}
|
|
52
|
-
await mutableFilesystem.promises.writeFile(sidebarFilePath, '[]');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function setPageRefs(sidebarFilePath, page, i) {
|
|
56
|
-
config.setRef(sidebarFilePath, ['pages', `${i}`, 'id', '$ref'], `${page.fullPath}#/route`);
|
|
57
|
-
page.sidebar && page.sidebar.label
|
|
58
|
-
? config.setRef(
|
|
59
|
-
sidebarFilePath,
|
|
60
|
-
['pages', `${i}`, 'name', '$ref'],
|
|
61
|
-
`${page.fullPath}#/sidebar/label`
|
|
62
|
-
)
|
|
63
|
-
: config.setRef(
|
|
64
|
-
sidebarFilePath,
|
|
65
|
-
['pages', `${i}`, 'name', '$ref'],
|
|
66
|
-
`${page.fullPath}#/title`
|
|
67
|
-
);
|
|
68
|
-
config.setRef(
|
|
69
|
-
sidebarFilePath,
|
|
70
|
-
['pages', `${i}`, 'data', 'link', '$ref'],
|
|
71
|
-
`${page.fullPath}#/route`
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async function setChildPageRefs(page, dirName, i, sidebarFilePath) {
|
|
76
|
-
if (isSubfolderIndex(page, dirName)) {
|
|
77
|
-
const childDirName = path.posix.dirname(page.fullPath);
|
|
78
|
-
const childNodeSidebarPath = path.posix.join(childDirName, options.filename);
|
|
79
|
-
const childPages = (
|
|
80
|
-
await Promise.all(
|
|
81
|
-
((await mutableFilesystem.promises.glob(
|
|
82
|
-
createFileGlob(['*', '*/index'], pageExtensions),
|
|
83
|
-
{
|
|
84
|
-
onlyFiles: true,
|
|
85
|
-
cwd: String(childDirName),
|
|
86
|
-
ignore: ignorePages.map(ignore => `**/${ignore}`)
|
|
87
|
-
}
|
|
88
|
-
)) as string[]).map(async pagePath => {
|
|
89
|
-
return await serialiser.deserialise(
|
|
90
|
-
pagePath,
|
|
91
|
-
await mutableFilesystem.promises.readFile(pagePath)
|
|
92
|
-
);
|
|
93
|
-
})
|
|
94
|
-
)
|
|
95
|
-
).filter(page => filterFn(page));
|
|
96
|
-
if (childPages.length > 1) {
|
|
97
|
-
for (let j = 1; j < childPages.length; j++) {
|
|
98
|
-
config.setRef(
|
|
99
|
-
sidebarFilePath,
|
|
100
|
-
['pages', `${i}`, 'childNodes', `${j - 1}`, '$ref'],
|
|
101
|
-
`${childNodeSidebarPath}#/pages/${j}`
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function addSidebarDataToFrontmatter(page, dirName) {
|
|
109
|
-
const dirNameLevels = String(dirName)
|
|
110
|
-
.split('/')
|
|
111
|
-
.filter(level => level);
|
|
112
|
-
const sidebarRootDir =
|
|
113
|
-
`/` + dirNameLevels.slice(0, dirNameLevels.length < 3 ? dirNameLevels.length : 3).join(`/`);
|
|
114
|
-
config.setRef(
|
|
115
|
-
String(page.fullPath),
|
|
116
|
-
['sidebarData', '$ref'],
|
|
117
|
-
path.posix.join(String(sidebarRootDir), options.filename, '#', 'pages')
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
export default SidebarPlugin;
|
|
123
|
-
|
|
124
|
-
function createFileGlob(patterns, pageExtensions) {
|
|
125
|
-
if (Array.isArray(patterns)) {
|
|
126
|
-
return patterns.map(pattern => createFileGlob(pattern, pageExtensions));
|
|
127
|
-
}
|
|
128
|
-
if (pageExtensions.length === 1) {
|
|
129
|
-
return `${patterns}${pageExtensions[0]}`;
|
|
130
|
-
}
|
|
131
|
-
return `${patterns}{${pageExtensions.join(',')}}`;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function isSubfolderIndex(page, dirName) {
|
|
135
|
-
return page.fullPath.split('/').length == String(dirName).split('/').length + 2;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function sortFn(pageA, pageB, dirName) {
|
|
139
|
-
// Always pin /index to the front
|
|
140
|
-
if (pageA.route === dirName + '/index') {
|
|
141
|
-
return -1;
|
|
142
|
-
}
|
|
143
|
-
if (pageB.route === dirName + '/index') {
|
|
144
|
-
return 1;
|
|
145
|
-
}
|
|
146
|
-
return (
|
|
147
|
-
(pageB.sidebar && pageB.sidebar.priority ? pageB.sidebar.priority : -1) -
|
|
148
|
-
(pageA.sidebar && pageA.sidebar.priority ? pageA.sidebar.priority : -1)
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function filterFn(page) {
|
|
153
|
-
return !(page.sidebar && page.sidebar.exclude);
|
|
154
|
-
}
|
package/src/SiteMapPlugin.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type PluginType from '@jpmorganchase/mosaic-types/dist/Plugin';
|
|
2
|
-
|
|
3
|
-
const SiteMapPlugin: PluginType<
|
|
4
|
-
{ sitemaps: string[][] },
|
|
5
|
-
{}
|
|
6
|
-
> = {
|
|
7
|
-
// Merge together all of the individual sitemaps from each source
|
|
8
|
-
async afterUpdate(mutableFilesystem, { sharedFilesystem, globalConfig }) {
|
|
9
|
-
if (!Array.isArray(globalConfig.data.sitemaps)) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
await sharedFilesystem.promises.writeFile(
|
|
13
|
-
'/sitemap.xml',
|
|
14
|
-
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' +
|
|
15
|
-
globalConfig.data.sitemaps
|
|
16
|
-
.map(items =>
|
|
17
|
-
items
|
|
18
|
-
.map(
|
|
19
|
-
item =>
|
|
20
|
-
`\t<url>\n\t\t<loc>${String(
|
|
21
|
-
item
|
|
22
|
-
)}</loc>\n\t\t<changefreq>weekly</changefreq>\n\t\t<priority>0.5</priority>\n\t</url>`
|
|
23
|
-
)
|
|
24
|
-
.join('\n')
|
|
25
|
-
)
|
|
26
|
-
.join('') +
|
|
27
|
-
'\n</urlset>'
|
|
28
|
-
);
|
|
29
|
-
},
|
|
30
|
-
// Store a sitemap for just this source
|
|
31
|
-
async $beforeSend(mutableFilesystem, { config, ignorePages }, options) {
|
|
32
|
-
config.setData({
|
|
33
|
-
sitemaps: [
|
|
34
|
-
(await mutableFilesystem.promises.glob('**', {
|
|
35
|
-
onlyFiles: true,
|
|
36
|
-
ignore: ignorePages.map(ignore => `**/${ignore}`),
|
|
37
|
-
cwd: '/'
|
|
38
|
-
})) as string[]
|
|
39
|
-
]
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export default SiteMapPlugin;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type PluginType from '@jpmorganchase/mosaic-types/dist/Plugin';
|
|
2
|
-
import type Page from '@jpmorganchase/mosaic-types/dist/Page';
|
|
3
|
-
import { visit } from 'unist-util-visit';
|
|
4
|
-
import markdown from 'remark-parse';
|
|
5
|
-
import { unified } from 'unified';
|
|
6
|
-
import Slugger from 'github-slugger';
|
|
7
|
-
import { toString } from 'hast-util-to-string';
|
|
8
|
-
|
|
9
|
-
type TOCItem = { level: number; id: string; text: string };
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Calculates table of contents from page headings
|
|
13
|
-
*/
|
|
14
|
-
const TableOfContentsPlugin: PluginType<{}, { minRank: 2; maxRank: 4 }> = {
|
|
15
|
-
async $afterSource(pages: Page[], {}, { minRank, maxRank }) {
|
|
16
|
-
const processor = unified().use(markdown);
|
|
17
|
-
const slugger = new Slugger();
|
|
18
|
-
for (const page of pages) {
|
|
19
|
-
const tree = await processor.parse(page.content);
|
|
20
|
-
const items: TOCItem[] = [];
|
|
21
|
-
visit(
|
|
22
|
-
tree,
|
|
23
|
-
node => test(node),
|
|
24
|
-
node => {
|
|
25
|
-
const text = toString(node).trim();
|
|
26
|
-
items.push({
|
|
27
|
-
level: node.depth,
|
|
28
|
-
id: slugger.slug(text),
|
|
29
|
-
text: text
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
page.tableOfContents = items;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return pages;
|
|
37
|
-
|
|
38
|
-
function test(node) {
|
|
39
|
-
return node.type === 'heading' && isHeadingInRange(node);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function isHeadingInRange(node) {
|
|
43
|
-
const depth = node.depth;
|
|
44
|
-
if (depth < minRank || depth > maxRank) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export default TableOfContentsPlugin;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
|
|
3
|
-
import glob from 'fast-glob';
|
|
4
|
-
import set from 'lodash/set';
|
|
5
|
-
|
|
6
|
-
function createFileGlob(url, pageExtensions) {
|
|
7
|
-
if (pageExtensions.length === 1) {
|
|
8
|
-
return `${url}${pageExtensions[0]}`;
|
|
9
|
-
}
|
|
10
|
-
return `${url}{${pageExtensions.join(',')}}`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default async function normaliseRefs(filepath, refs, filesystem, pageExtensions, ignorePages) {
|
|
14
|
-
const configWithoutGlobs = {};
|
|
15
|
-
|
|
16
|
-
for (let i = 0; i < refs.length; i++) {
|
|
17
|
-
const ref = refs[i];
|
|
18
|
-
const [url, fragment = ''] = ref.$$value.split('#');
|
|
19
|
-
|
|
20
|
-
if (!url) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const fullUrl = path.resolve(path.dirname(filepath), url);
|
|
25
|
-
|
|
26
|
-
if (!glob.isDynamicPattern(url)) {
|
|
27
|
-
if (!(await filesystem.promises.exists(fullUrl))) {
|
|
28
|
-
throw new Error(
|
|
29
|
-
`A \`$ref\` for '${filepath}' pointed to page '${fullUrl}' - which could not be found.`
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
const refRealPath = await filesystem.promises.realpath(
|
|
33
|
-
fullUrl
|
|
34
|
-
//path.resolve(path.dirname(filepath), url)
|
|
35
|
-
);
|
|
36
|
-
const stat = await filesystem.promises.stat(refRealPath);
|
|
37
|
-
// Turn directory refs into full index paths
|
|
38
|
-
// TODO: But DO we want to do this?
|
|
39
|
-
if (stat.isDirectory()) {
|
|
40
|
-
// && !/\/index(\.\w{1,4})?$/.test(url)) {
|
|
41
|
-
set(configWithoutGlobs, ref.$$path.slice(0, -1), {
|
|
42
|
-
$ref: `${await filesystem.promises.realpath(path.join(refRealPath, 'index'))}#${fragment}`
|
|
43
|
-
});
|
|
44
|
-
} else {
|
|
45
|
-
set(configWithoutGlobs, ref.$$path.slice(0, -1), {
|
|
46
|
-
$ref: `${refRealPath}#${fragment}`
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
let globResolvedRefs =
|
|
54
|
-
// If the pattern doesn't have an explicit file extension - then we'll make it just return pages
|
|
55
|
-
await filesystem.promises.glob(
|
|
56
|
-
!/\/[^/]+\.\w{2,4}$/.test(url) ? createFileGlob(url, pageExtensions) : url,
|
|
57
|
-
{
|
|
58
|
-
ignore: [filepath, ...ignorePages.map(ignore => `**/${ignore}`)],
|
|
59
|
-
cwd: path.dirname(filepath),
|
|
60
|
-
absolute: true
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
// Use a set so we de-dupe any symlinks that point to the same page
|
|
65
|
-
const resolvedRefs = new Set();
|
|
66
|
-
|
|
67
|
-
for (const value of globResolvedRefs) {
|
|
68
|
-
const refRealPath = await filesystem.promises.realpath(path.resolve(filepath, value));
|
|
69
|
-
if (refRealPath !== (await filesystem.promises.realpath(filepath))) {
|
|
70
|
-
resolvedRefs.add(`${refRealPath}#${fragment}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
set(
|
|
75
|
-
configWithoutGlobs,
|
|
76
|
-
ref.$$path.slice(0, -1),
|
|
77
|
-
Array.from(resolvedRefs).map($ref => ({ $ref }))
|
|
78
|
-
);
|
|
79
|
-
} catch (e) {
|
|
80
|
-
throw e;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return configWithoutGlobs;
|
|
85
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"allowJs": true,
|
|
5
|
-
"target": "es2015",
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"moduleResolution": "NodeNext",
|
|
8
|
-
"outDir": "dist",
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"sourceMap": true,
|
|
11
|
-
"rootDir": "./src"
|
|
12
|
-
},
|
|
13
|
-
"include": ["src/**/*"],
|
|
14
|
-
"exclude": [
|
|
15
|
-
"node_modules",
|
|
16
|
-
"src/**/__tests__/**/*",
|
|
17
|
-
"src/__tests__/**/*",
|
|
18
|
-
"src/**/*.mjs.*",
|
|
19
|
-
"**/dist/**/*"
|
|
20
|
-
]
|
|
21
|
-
}
|