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

Changed {subscriber_firstname} replacement to {first_name}

no issue

- easier to remember and type
- removes need to remove the `subscriber_` prefix when accessing member properties
This commit is contained in:
Kevin Ansfield 2020-04-20 14:25:58 +01:00
parent 944ffa8668
commit 9981ea336c
3 changed files with 5 additions and 5 deletions

View file

@ -26,9 +26,9 @@ const getEmailData = async (postModel, members = []) => {
members.forEach((member) => { members.forEach((member) => {
emails.push(member.email); emails.push(member.email);
// firstname is a computed property only used here for now // first_name is a computed property only used here for now
// TODO: move into model computed property or output serializer? // TODO: move into model computed property or output serializer?
member.firstname = (member.name || '').split(' ')[0]; member.first_name = (member.name || '').split(' ')[0];
// add static data to mailgun template variables // add static data to mailgun template variables
const data = { const data = {

View file

@ -60,7 +60,7 @@ const _parseReplacements = (emailTmpl) => {
const EMAIL_REPLACEMENT_REGEX = /%%(\{.*?\})%%/g; const EMAIL_REPLACEMENT_REGEX = /%%(\{.*?\})%%/g;
// the " is necessary here because `juice` will convert "->" for email compatibility // the " is necessary here because `juice` will convert "->" for email compatibility
const REPLACEMENT_STRING_REGEX = /\{(?<memberProp>\w*?)(?:,? *(?:"|&quot;)(?<fallback>.*?)(?:"|&quot;))?\}/; const REPLACEMENT_STRING_REGEX = /\{(?<memberProp>\w*?)(?:,? *(?:"|&quot;)(?<fallback>.*?)(?:"|&quot;))?\}/;
const ALLOWED_REPLACEMENTS = ['subscriber_firstname']; const ALLOWED_REPLACEMENTS = ['first_name'];
const replacements = []; const replacements = [];
['html', 'plaintext'].forEach((format) => { ['html', 'plaintext'].forEach((format) => {
@ -77,7 +77,7 @@ const _parseReplacements = (emailTmpl) => {
format, format,
id, id,
match: replacementMatch, match: replacementMatch,
memberProp: memberProp.replace('subscriber_', ''), memberProp,
fallback fallback
}); });

View file

@ -75,7 +75,7 @@ describe('Email Preview API', function () {
id: ObjectId.generate(), id: ObjectId.generate(),
title: 'Post with email-only card', title: 'Post with email-only card',
slug: 'email-only-card', slug: 'email-only-card',
mobiledoc: '{"version":"0.3.1","atoms":[],"cards":[["email",{"html":"<p>Hey {subscriber_firstname \\"there\\"} {unknown}</p><p><strong>Welcome to your first Ghost email!</strong></p>"}],["email",{"html":"<p>Another email card with a similar replacement, {subscriber_firstname, \\"see?\\"}</p>"}]],"markups":[],"sections":[[10,0],[1,"p",[[0,[],0,"This is the actual post content..."]]],[10,1],[1,"p",[]]]}', mobiledoc: '{"version":"0.3.1","atoms":[],"cards":[["email",{"html":"<p>Hey {first_name \\"there\\"} {unknown}</p><p><strong>Welcome to your first Ghost email!</strong></p>"}],["email",{"html":"<p>Another email card with a similar replacement, {first_name, \\"see?\\"}</p>"}]],"markups":[],"sections":[[10,0],[1,"p",[[0,[],0,"This is the actual post content..."]]],[10,1],[1,"p",[]]]}',
html: '<p>This is the actual post content...</p>', html: '<p>This is the actual post content...</p>',
plaintext: 'This is the actual post content...', plaintext: 'This is the actual post content...',
status: 'draft', status: 'draft',