-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
30 lines (26 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
(function(module) {
var Carousel = {};
Carousel.parse = function(data, callback) {
if (!data || !data.postData || !data.postData.content) {
return callback(null, data);
}
var re = /\[carousel(.*)]/mg;
var postContent = data.postData.content;
var originContent = data.postData.content;
var arr = postContent.match(re);
if(arr && arr.length){
var config = arr[0].replace(re, '$1');
re = /(<br>|)(<img )src(=".*?>)(<br>|)/mg;
postContent = postContent.replace(re, '<div class="item">$2class="lazyOwl" style="box-shadow:1px 1px 3px rgba(0,0,0,0.2)" data-src$3</div>');
re = /<div class="item">.*?\/div>/mg;
arr = postContent.match(re);
if(arr && arr.length){
postContent = postContent.replace(re, '');
postContent = postContent.replace(/\[carousel(.*)]/mg, '<div class="carousel" config="' + config + '">'+arr.join('')+'</div>');
data.postData.content = postContent;
}
}
callback(null, data);
};
module.exports = Carousel;
}(module));