From ef353db39a2d43e6eade0c4b3dcc7ef6bf86afb4 Mon Sep 17 00:00:00 2001 From: Rishabh Garg Date: Thu, 23 Mar 2023 18:18:03 +0530 Subject: [PATCH] Grouped mentions from same source in email report (#16470) refs https://github.com/TryGhost/Team/issues/2754 Mentions from same source are already grouped together in Admin UI, with number of links for each source shown in the grouped mention. Similarly, this change updates the grouping of mentions from same source for email reports, removing any duplicate mention source from the report. --- .../core/server/services/mentions-email-report/service.js | 7 ++++++- .../staff-service/lib/email-templates/mention-report.hbs | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ghost/core/core/server/services/mentions-email-report/service.js b/ghost/core/core/server/services/mentions-email-report/service.js index d03f16a2b6..698cc944a7 100644 --- a/ghost/core/core/server/services/mentions-email-report/service.js +++ b/ghost/core/core/server/services/mentions-email-report/service.js @@ -63,8 +63,13 @@ module.exports = { * @returns {Promise} */ async renderHTML(report, recipient) { + // Filter out mentions with duplicate source url from the report + const uniqueMentions = report.mentions.filter((mention, index, self) => { + return self.findIndex(m => m.sourceUrl.href === mention.sourceUrl.href) === index; + }); + return staffService.api.emails.renderHTML('mention-report', { - report: report, + mentions: uniqueMentions, recipient: recipient, hasMoreMentions: report.mentions.length > 5 }); diff --git a/ghost/staff-service/lib/email-templates/mention-report.hbs b/ghost/staff-service/lib/email-templates/mention-report.hbs index 98bd233a70..83d62a832a 100644 --- a/ghost/staff-service/lib/email-templates/mention-report.hbs +++ b/ghost/staff-service/lib/email-templates/mention-report.hbs @@ -3,7 +3,7 @@ - 💌 New mention{{#eq report.mentions.length 1}}{{else}}{{report.mentions.length}}s{{/eq}} + 💌 New mention{{#eq mentions.length 1}}{{else}}{{mentions.length}}s{{/eq}} {{> styles}} @@ -24,9 +24,9 @@

Hey there,

-

{{siteTitle}} was mentioned{{#eq report.mentions.length 1}} in:{{else}} {{report.mentions.length}} times recently. Here's where:{{/eq}}

+

{{siteTitle}} was mentioned{{#eq mentions.length 1}} in:{{else}} {{mentions.length}} times recently. Here's where:{{/eq}}

- {{#each (limit report.mentions 5) as |mention|}} + {{#each (limit mentions 5) as |mention|}}
@@ -91,7 +91,7 @@ - +
View all {{#if hasMoreMentions}}{{report.mentions.length}}{{/if}} mentions View all {{#if hasMoreMentions}}{{mentions.length}}{{/if}} mentions