Skip to content

Node.js based forum software built for the modern web

get all images in post

Barış Soner Uşaklıdace7d716f08
diff --git a/src/controllers/topics.js b/src/controllers/topics.js
index 491d37d1e0..053e1aa300 100644
--- a/src/controllers/topics.js
+++ b/src/controllers/topics.js
@@ -288,18 +288,19 @@ function addTags(topicData, req, res) {
},
];
- var regex = /src\s*=\s*"(.+?)"/;
-
topicData.posts.forEach(function (postData) {
+ var regex = /src\s*=\s*"(.+?)"/g;
var match = regex.exec(postData.content);
- if (match) {
+ while (match !== null) {
var image = match[1];
+
if (image.startsWith(nconf.get('url') + '/plugins')) {
return;
}
if (!image.startsWith('http')) {
image = nconf.get('url') + image;
}
+
res.locals.metaTags.push({
property: 'og:image',
content: image,
@@ -310,6 +311,7 @@ function addTags(topicData, req, res) {
content: image,
noEscape: true,
});
+ match = regex.exec(postData.content);
}
});