mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 21:40:39 +03:00
🐛 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:
parent
163092f377
commit
c434666ba2
@ -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
|
||||
|
@ -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(/'/);
|
||||
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(/'/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user