-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibrary.js
85 lines (53 loc) · 2.03 KB
/
library.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'use strict';
const controllers = require('./lib/controllers');
const cheerio = require('cheerio');
const plugin = {};
var debug = false;
function myDebug(msg){
if(debug){
console.log(msg);
}
}
plugin.init = function (params, callback) {
console.log("nodebb-plugin-makesmart-gallery init()");
callback();
};
plugin.convertImagesToGallery = function (data, callback) {
var postHTML = data.postData.content;
// cheerio >< null, false to not add <html> overhead
var $ = cheerio.load(postHTML, null, false);
$('p').each(function() {
var isImageGallery = containImageGallery($(this).text());
if(isImageGallery){
var galleryParagraph = $(this);
var imageSrcs = [];
var imageAlt = [];
galleryParagraph.find('img').each(function() {
imageSrcs.push($(this).attr('src'));
imageAlt.push($(this).attr('alt'));
})
if(imageSrcs.length != 0){
var index = 0;
galleryParagraph.html('<div class="swiper-container makesmart-image-gallery"><div class="swiper-wrapper" style="padding-bottom: 40px;"></div><div class="swiper-pagination"></div><div class="swiper-button-next"></div><div class="swiper-button-prev"></div></div>');
var collectionContainer = $(this).find('div.swiper-wrapper');
imageSrcs.forEach(function(src){
collectionContainer.append('<div class="swiper-slide makesmart-image-gallery-image">' + '<img src="' + src + '" alt="' + imageAlt[index] + '" class="img-responsive img-markdown" style="display: block; margin-left: auto; margin-right: auto; -webkit-box-shadow: 0px 19px 24px -15px rgba(0,0,0,0.75); -moz-box-shadow: 0px 19px 24px -15px rgba(0,0,0,0.75); box-shadow: 0px 19px 24px -15px rgba(0,0,0,0.75);">' + '</div>');
index++;
});
}
/*
imageSrcs.forEach(function(src){
galleryParagraph.append(baseUrl + src);
})
*/
}
});
myDebug("POST PARSED");
data.postData.content = $.html();
callback(null, data);
}
module.exports = plugin;
function containImageGallery(text){
var isImageGallery = text.includes("[[gallery]]");
return isImageGallery;
}