🐛 Removed [http://url/] output in member email preview text

no issue

- we output the post excerpt in a hidden div in the email template so that email clients pick it up as the "preview" text when listing emails
- when no custom excerpt is provided the preview text is grabbed from post.excerpt which is the first 500 chars of the post.plaintext value
- post.plaintext formats links as "Link [http://url/]" which is unwanted in html email previews

- add a basic replacement to the post email serializer to remove any `[http://url/]` occurrences from the post excerpt before rendering the email content
This commit is contained in:
Kevin Ansfield 2020-08-12 20:14:06 +01:00
parent 163092f377
commit c434666ba2
2 changed files with 15 additions and 3 deletions

View File

@ -105,6 +105,14 @@ const serialize = async (postModel, options = {isBrowserPreview: false}) => {
if (post.posts_meta) {
post.email_subject = post.posts_meta.email_subject;
}
// we use post.excerpt as a hidden piece of text that is picked up by some email
// clients as a "preview" when listing emails. Our current plaintext/excerpt
// generation outputs links as "Link [https://url/]" which isn't desired in the preview
if (!post.custom_excerpt) {
post.excerpt = post.excerpt.replace(/\s\[http(.*?)\]/g, '');
}
post.html = mobiledocLib.mobiledocHtmlRenderer.render(JSON.parse(post.mobiledoc), {target: 'email'});
// same options as used in Post model for generating plaintext but without `wordwrap: 80`
// to avoid replacement strings being split across lines and for mail clients to handle

View File

@ -114,7 +114,7 @@ describe('Email Preview API', function () {
id: ObjectId.generate(),
title: 'Post with email-only card',
slug: 'email-only-card',
mobiledoc: '{"version":"0.3.1","atoms":[],"cards":[],"markups":[],"sections":[[1,"p",[[0,[],0,"This is the actual post content... With an apostrophy: \'"]]],[1,"p",[]]]}',
mobiledoc: '{"version":"0.3.1","atoms":[],"cards":[],"markups":[["a",["href","https://ghost.org"]]],"sections":[[1,"p",[[0,[],0,"Testing "],[0,[0],1,"links"],[0,[],0," in email excerpt and apostrophes \'"]]]]}',
html: '<p>This is the actual post content...</p>',
plaintext: 'This is the actual post content...',
status: 'draft',
@ -135,8 +135,12 @@ describe('Email Preview API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.email_previews);
jsonResponse.email_previews[0].html.should.match(/&#39;/);
jsonResponse.email_previews[0].html.should.not.match(/&apos;/);
const [preview] = jsonResponse.email_previews;
preview.html.should.containEql('Testing links in email excerpt');
preview.html.should.match(/&#39;/);
preview.html.should.not.match(/&apos;/);
});
});
});