-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (52 loc) · 1.59 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
49
50
51
52
53
54
55
56
57
58
59
const get = require('lodash/get');
const trim = require('lodash/trim');
const toStyleString = require('to-style').string
function minifyHtml(content) {
return content
.replace(/\r?\n|\r/g, '')
.replace(/[\t ]+\</g, "<")
.replace(/\>[\t ]+\</g, "><")
.replace(/\>[\t ]+$/g, ">");
}
module.exports = {
// Extend ebook resources and html
website: {
assets: './book',
css: [
'plugin.css'
],
},
book: {
assets: './book',
css: [
'plugin.css'
],
},
ebook: {
assets: './book',
css: [
'plugin.css'
],
},
// Extend templating blocks
blocks: {
httpverb: {
process: function (block) {
const ctx = this;
const opts = ctx.book.config.get('pluginsConfig.http-verb');
const verb = trim(get(block, 'kwargs.verb', '') || get(block, 'args[0]', '') || 'get');
const style = toStyleString(get(opts, `styles.${verb}`));
return this.renderBlock('markdown', trim(block.body || '')).then((str) => {
return minifyHtml(`
<div class="gbhv-verbpath">
<span class="gbhv-verb gbhv-${verb.toLowerCase()}"${style ? ` style="${style}"` : ''}>
${verb.toUpperCase()}
</span>
<span class="gbhv-path">${str}</span>
</div>
`);
})
}
}
},
};