forked from ly-tools/gitbook-plugin-fancybox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
47 lines (42 loc) · 1.05 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
'use strict';
var cheerio = require('cheerio');
var _ = require('underscore');
var multiline = require('multiline');
var template = _.template(multiline(function() {
/*
<a href="<%= url %>" rel="grouped" title="<%= title %>" target="_self" class="fancybox">
<img src="<%= url %>" alt="<%= title %>"></img>
</a>
*/
}));
module.exports = {
book: {
assets: './assets',
js: [
'jquery.min.js',
'jquery.mousewheel.pack.js',
'jquery.fancybox.pack.js',
'jquery.fancybox-buttons.js',
'plugin.js'
],
css: [
'jquery.fancybox.css',
'jquery.fancybox-buttons.css'
]
},
hooks: {
page: function(page) {
var $ = cheerio.load(page.content);
$('img').each(function(index, img) {
var $img = $(img);
if (Array.from($img).some(img => img.attribs.class === "plain")) return img;
$img.replaceWith(template({
url: $img.attr('src'),
title: $img.attr('alt')
}));
});
page.content = $.html();
return page;
}
}
};