-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
48 lines (43 loc) · 1.53 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const BroccoliMergeTrees = require('broccoli-merge-trees');
const BroccoliFunnel = require('broccoli-funnel');
const { mv } = require('broccoli-stew');
const { existsSync } = require('fs');
const Plugin = require('broccoli-plugin');
const TableOfContents = require('./lib/table-of-contents');
const CollateJsonApiBlobs = require('./lib/collate-and-paginate');
const MarkdownToJsonApi = require('./lib/markdown-to-jsonapi');
class EmptyNode extends Plugin {
constructor() {
super([]);
}
// eslint-disable-next-line class-methods-use-this
build() {}
}
module.exports = function StaticSiteJson(folder, options = {}) {
if (typeof folder === 'string' && !existsSync(folder)) {
return new EmptyNode();
}
const cleanMarkdownFunnel = new BroccoliFunnel(folder, {
include: ['**/*.md', '**/*.markdown'],
});
const tocFunnel = new BroccoliFunnel(folder, {
include: [
'**/pages.yml',
'**/pages.yaml',
'**/pages.json',
'**/toc.yml',
'**/toc.yaml',
'**/toc.json',
],
});
const pagesTree = new TableOfContents(tocFunnel, options);
const jsonApiTree = new MarkdownToJsonApi(cleanMarkdownFunnel, options);
// the default content folder is "content" and this tree needs to know
// about contentFolder for pagination links
const collationTree = new CollateJsonApiBlobs(jsonApiTree, {
contentFolder: 'content',
...options,
});
const compiledTrees = new BroccoliMergeTrees([jsonApiTree, pagesTree, collationTree]);
return mv(compiledTrees, (options.contentFolder || 'content'));
};