-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
54 lines (35 loc) · 1.02 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
var cheerio = require( "cheerio" )
var wrapImageTags = function(page){
var $ = cheerio.load(page.content);
// Loop through each image found in the page content
$('img').each(function(){
// Build the wrapper
var imageWrapper = $('<div>').addClass('image-wrapper');
// Get the image object
var img = $(this);
// Rebuild the image
var $image = $('<img>')
.attr('src', img.attr('src'))
.attr('alt', img.attr('alt'));
// Append the original image
imageWrapper.append($image);
// Add the image with its wrapper
$(this).before(imageWrapper);
// Remove the image
$(this).remove();
});
page.content = $.html();
return page;
}
module.exports = {
// Map of hooks
hooks: {
'page': function(page){
return wrapImageTags(page);
}
},
// Map of new blocks
blocks: {},
// Map of new filters
filters: {}
};