-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathindex.js
33 lines (31 loc) · 871 Bytes
/
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
var cheerio = require('cheerio');
var slug = require('github-slugid');
// insert anchor link into section
function insertAnchors(content) {
var $ = cheerio.load(content);
$(':header').each(function(i, elem) {
var header = $(elem);
var id = header.attr("id");
if (!id) {
id = slug(header.text());
header.attr("id", id);
}
header.prepend('<a name="' + id + '" class="plugin-anchor" '
+ 'href="#' + id + '">'
+ '<i class="fa fa-link" aria-hidden="true"></i>'
+ '</a>');
});
return $.html();
}
module.exports = {
book: {
assets: "./assets",
css: [ "plugin.css" ]
},
hooks: {
"page": function(page) {
page.content = insertAnchors(page.content);
return page;
}
}
};