diff --git a/core/server/services/mega/post-email-serializer.js b/core/server/services/mega/post-email-serializer.js index 25513b4de0..cf250e7705 100644 --- a/core/server/services/mega/post-email-serializer.js +++ b/core/server/services/mega/post-email-serializer.js @@ -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 diff --git a/test/api-acceptance/admin/email_preview_spec.js b/test/api-acceptance/admin/email_preview_spec.js index 510007c4fc..25cff30e0a 100644 --- a/test/api-acceptance/admin/email_preview_spec.js +++ b/test/api-acceptance/admin/email_preview_spec.js @@ -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: '

This is the actual post content...

', 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(/'/); - jsonResponse.email_previews[0].html.should.not.match(/'/); + const [preview] = jsonResponse.email_previews; + + preview.html.should.containEql('Testing links in email excerpt'); + + preview.html.should.match(/'/); + preview.html.should.not.match(/'/); }); }); });