0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Removed name from subscription details if missing

refs https://github.com/TryGhost/Team/issues/2736

If the name is not known for a member, we'll hide the name row in the subscription details in an email. This method is supported in most email clients, and requires the support of `<style>` in `<head>`.
This commit is contained in:
Simon Backx 2023-03-22 15:15:34 +01:00
parent 47e343ec18
commit 480c1a7004
6 changed files with 21478 additions and 5081 deletions

View file

@ -314,7 +314,7 @@ class EmailRenderer {
// Juice HTML (inline CSS)
const juice = require('juice');
html = juice(html, {inlinePseudoElements: true});
html = juice(html, {inlinePseudoElements: true, removeStyleTags: false});
// happens after inlining of CSS so we can change element types without worrying about styling
const cheerio = require('cheerio');
@ -503,6 +503,12 @@ class EmailRenderer {
return member.name;
}
},
{
id: 'name_class',
getValue: (member) => {
return member.name ? '' : 'hidden';
}
},
{
id: 'email',
getValue: (member) => {

View file

@ -1002,6 +1002,10 @@ a[data-flickr-embed] img {
width: 0;
}
.subscription-details p.hidden {
display: none !important;
}
/* -------------------------------------
RESPONSIVE AND MOBILE FRIENDLY STYLES
------------------------------------- */
@ -1325,7 +1329,7 @@ a[data-flickr-embed] img {
padding: 12px 0 4px;
font-size: 19px;
font-weight: 700;
}
.latest-post a {

View file

@ -185,7 +185,7 @@
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="subscription-details">
<p>Name: %%{name, "not provided"}%%</p>
<p class="%%{name_class}%%">Name: %%{name, "not provided"}%%</p>
<p>Email: <a href="mailto:%%{email}%%">%%{email}%%</a></p>
<p>Member since: %%{created_at}%%</p>
</td>

View file

@ -157,6 +157,25 @@ describe('Email renderer', function () {
assert.equal(replacements[0].getValue(member), 'Test User');
});
it('returns hidden class for missing name', function () {
member.name = '';
const html = 'Hello %%{name_class}%%,';
const replacements = emailRenderer.buildReplacementDefinitions({html, newsletterUuid: newsletter.get('uuid')});
assert.equal(replacements.length, 1);
assert.equal(replacements[0].token.toString(), '/%%\\{name_class\\}%%/g');
assert.equal(replacements[0].id, 'name_class');
assert.equal(replacements[0].getValue(member), 'hidden');
});
it('returns empty class for available name', function () {
const html = 'Hello %%{name_class}%%,';
const replacements = emailRenderer.buildReplacementDefinitions({html, newsletterUuid: newsletter.get('uuid')});
assert.equal(replacements.length, 1);
assert.equal(replacements[0].token.toString(), '/%%\\{name_class\\}%%/g');
assert.equal(replacements[0].id, 'name_class');
assert.equal(replacements[0].getValue(member), '');
});
it('returns correct email', function () {
const html = 'Hello %%{email}%%,';
const replacements = emailRenderer.buildReplacementDefinitions({html, newsletterUuid: newsletter.get('uuid')});