-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathbuild.js
48 lines (40 loc) · 1.31 KB
/
build.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
var cheerio = require("cheerio"),
context = require("./template/context"),
localization = require("./template/localization"),
keyword = require("./keyword");
exports.preCompile = function(src, data) {
//update keywords prior to the markdown
// data.keywords = keyword.generate(src);
data.keywords = [];
};
exports.postCompile = function(html, data) {
var $ = cheerio.load(html), title,
mdSuffix = /\.md$/i;
//update title
title = [$("h1").eq(0).text(), context.title].join(" - ");
data.title = title;
//update links
$("a").each(function(i) {
var $this = $(this);
if($this.attr("href")) {
$this.attr("href", $this.attr("href").replace(mdSuffix, ".html"));
}
});
//update breadcrumbs
var breadcrumbs = data.filepath.split("/");
breadcrumbs.shift();
// breadcrumbs.push(breadcrumbs.pop().replace(mdSuffix, ""));
breadcrumbs.pop();
data.breadcrumbs = breadcrumbs.filter(function(item) {
return item !== "index";
}).reduce(function(prev, cur) {
prev.push({
localized: localization[cur] || cur + "(Unlocalized)",
original: cur,
link: prev.length ? prev[prev.length-1] + cur + "/" : "/" + cur + "/"
});
return prev;
}, []);
data.descriptions = $.root().text().substr(0, 200).split(/[\n\t]/).join(" ");
return $.html();
};