From 52eb3ca9da006373504bbb3f825fa16b42685d85 Mon Sep 17 00:00:00 2001 From: Rish Date: Fri, 15 Nov 2019 11:25:46 +0530 Subject: [PATCH] Converted all link tags in preview to open in new tab no issue --- core/server/services/mega/post-email-serializer.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/server/services/mega/post-email-serializer.js b/core/server/services/mega/post-email-serializer.js index 1e12416af0..a0bd0ccb1d 100644 --- a/core/server/services/mega/post-email-serializer.js +++ b/core/server/services/mega/post-email-serializer.js @@ -3,6 +3,7 @@ const template = require('./template'); const settingsCache = require('../../services/settings/cache'); const urlUtils = require('../../lib/url-utils'); const moment = require('moment'); +const cheerio = require('cheerio'); const getSite = () => { return Object.assign({}, settingsCache.getPublic(), { @@ -17,9 +18,14 @@ const serialize = (post) => { if (post.posts_meta) { post.email_subject = post.posts_meta.email_subject; } + let juicedHtml = juice(template({post, site: getSite()})); + // Force all links to open in new tab + let _cheerio = cheerio.load(juicedHtml); + _cheerio('a').attr('target','_blank'); + juicedHtml = _cheerio.html(); return { subject: post.email_subject || post.title, - html: juice(template({post, site: getSite()})), + html: juicedHtml, plaintext: post.plaintext }; };