-
Notifications
You must be signed in to change notification settings - Fork 2
/
page.js
34 lines (29 loc) · 888 Bytes
/
page.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
let { repr } = require("faucet-pipeline-core/lib/util");
let colonParse = require("metacolon");
module.exports = class Page {
constructor(slug, sourcePath, children) {
this.slug = slug || "";
this.sourcePath = sourcePath;
this.children = children || null;
}
getChild(slug) {
return this.children.get(slug);
}
async load() {
if(this.body) { // heuristic
return Promise.resolve(this);
}
let { headers, body } = await colonParse(this.sourcePath);
// XXX: secondary fallbacks YAGNI?
this.language = headers.lang || headers.language || null;
this.title = headers.title || null;
this.description = headers.desc || headers.description || null;
this.body = body;
return this;
}
toString() {
let filepath = repr(this.sourcePath, false);
let suffix = this.body ? " resolved" : "";
return `<Page ${repr(this.slug, false)} ${filepath}${suffix}>`;
}
};