Fixed plaintext for mentions email report (#16517)

closes https://github.com/TryGhost/Team/issues/2754

Updates plaintext version for mentions email report to include all unique mentions in a nice list format.
This commit is contained in:
Rishabh Garg 2023-03-29 00:36:05 +05:30 committed by GitHub
parent 3236891b80
commit 61afa94a4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 2 deletions

View File

@ -81,8 +81,13 @@ module.exports = {
* @returns {Promise<string>} * @returns {Promise<string>}
*/ */
async renderText(report, recipient) { async renderText(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.renderText('mention-report', { return staffService.api.emails.renderText('mention-report', {
report: report, mentions: uniqueMentions,
recipient: recipient recipient: recipient
}); });
} }

View File

@ -1,7 +1,15 @@
module.exports = function (data) { module.exports = function (data) {
const {mentions} = data;
// Create a list of new mentions with a link to the source
const mentionsList = mentions.map((mention) => {
return `- ${mention.sourceSiteTitle} (${mention.sourceUrl})`;
}).join('\n');
// Be careful when you indent the email, because whitespaces are visible in emails! // Be careful when you indent the email, because whitespaces are visible in emails!
return ` return `
You have been mentioned by ${data.sourceUrl}. You have been mentioned recently. Here's where:
${mentionsList}
--- ---

View File

@ -908,5 +908,28 @@ describe('StaffService', function () {
mailStub.called.should.be.false(); mailStub.called.should.be.false();
}); });
}); });
describe('renderText for webmentions', function () {
it('renders plaintext report for mentions', async function () {
const textTemplate = await service.emails.renderText('mention-report', {
toEmail: 'jamie@example.com',
siteDomain: 'ghost.org',
staffUrl: 'https://admin.example.com/blog/ghost/#/settings/staff/jane.',
mentions: [
{
sourceSiteTitle: 'Webmentions',
sourceUrl: 'https://webmention.io/'
},
{
sourceSiteTitle: 'Ghost Demo',
sourceUrl: 'https://demo.ghost.io/'
}
]
});
textTemplate.should.match(/- Webmentions \(https:\/\/webmention.io\/\)/);
textTemplate.should.match(/Ghost Demo \(https:\/\/demo.ghost.io\/\)/);
textTemplate.should.match(/Sent to jamie@example.com from ghost.org/);
});
});
}); });
}); });