From dace7d716f087717df463b81bc4a74ed23dac551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 8 Dec 2017 11:46:05 -0500 Subject: [PATCH] get all images in post --- src/controllers/topics.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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); } });