From 24c86b49d13c67bb93a98c5236ee61f7d8324729 Mon Sep 17 00:00:00 2001 From: Aileen Nowak Date: Sat, 9 Jul 2016 06:40:32 +0300 Subject: [PATCH] HTML newsletter template for subscribers (#7045) refs #7023 The template can be used for all cases (different newsletter interval, different amount of blog posts, with or without blog picture). The template can be filled with the following data structure: - `blog.logo` is the blog logo from settings - `blog.title` is the title of the current blog - `blog.url` is the URL of the blog - `blog.twitterURL` is the twitter profile URL of the blog from settings - `blog.facebookURL` is the facebook page URL of the blog from settings - `blog.unsubscribe` is the link for the reader to unsubscribe from the blog - `newsletter.interval` is the interval in words like 'weekly', 'daily', 'monthly' - `newsletter.date` is the date of the newsletter issue in a format like 'June 9th, 2016' - `blog.post` is expected to be an array: - `blog.post[i].picture` is the picture of the blog post. There are also conditionals, which change the inline CSS to either show a border-top if there's no picture (in that case the HTML code, that shows the picture is not active) - `blog.post[i].title` is the title of the current blog post - `blog.post[i].text` is the text of the current blog post, which needs to be cut down to 278 letters, plus ending with `…` - `blog.post[i].url` is the URL of the current blog post - `blog.post[i].tag` is the tag of the current blog post - `blog.post[i].author` is the author of the current blog post Important is, that only HEX HTML entities will work, especially in Outlook. So instead of `—` we need to use `—` and `’` instead of `'` or `'` and so on. Added unit test for newsletter template in `test/unit/mail/utils_spec.js`. --- core/server/mail/templates/newsletter.html | 876 +++++++++++++++++++++ core/test/unit/mail/utils_spec.js | 75 +- 2 files changed, 949 insertions(+), 2 deletions(-) create mode 100644 core/server/mail/templates/newsletter.html diff --git a/core/server/mail/templates/newsletter.html b/core/server/mail/templates/newsletter.html new file mode 100644 index 0000000000..9ff90bdd1d --- /dev/null +++ b/core/server/mail/templates/newsletter.html @@ -0,0 +1,876 @@ + + + + + + + + {{blog.title}} + + + + + + + + + +
+
+ + + + + + +
+ + + + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ + + <% if (blog.logo) { %> + + + + + + +
+ + + + +
+
+ + +
+
+
+ <% } %> + + + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ + + + + + +
+ + + + +
+ +

+ {{blog.title}} +

+
+
+ + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ + + + + + +
+ + + + +
+ +

+ {{newsletter.interval}} digest — + {{newsletter.date}}

+ +
+
+ + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ + + + + + <% if (blog.post[0].picture) { %> + + + + + + +
+ + + + +
+
+ + Feature Image
+
+
+ <% } %> + + + + + + + + +
+ + + + +
+ + + + + <% if (blog.post[0].picture) { %> + + <% } else { %> +
+ <% } %> + + + + + + + + + +
+ + + + +
 
+
+ + + + +
+ + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ + + + + + +
+ + + + +
+ + +

+ + {{blog.post[0].title}} + +

+
+
+ + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ + + + + + +
+ + + + +
+ + +

+ {{blog.post[0].text}} +

+
+
+ + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ + + + + + +
+ + + + +
+ + + + + + +
+ + + + +
+
+ + Read More + +
+
+
+
+
+ + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+
+
+ + + + +
 
+
+ +
+
+ + + + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ + + + <% if (blog.post.length > 1) { %> + + + + + + + + +
+ + + + +
 
+
+ + + + +
+ +

+ {{blog.post[1].tag}} / {{blog.post[1].author}} +

+ + + + + + +
 
+ +

+ + {{blog.post[1].title}} + +

+ + + + + + +
 
+ +

+ {{blog.post[1].text}} +

+
+
+ + + + +
 
+
+ + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ + <% if (blog.post.length > 2) { %> + + + + + + + + +
+ + + + +
 
+
+ + + + +
+ +

+ {{blog.post[2].tag}} / {{blog.post[2].author}} +

+ + + + + + +
 
+ +

+ + {{blog.post[2].title}} + +

+ + + + + + +
 
+ +

+ {{blog.post[2].text}} +

+
+
+ + + + +
 
+
+ + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ + + <% if (blog.post.length > 3) { %> + + <% for (var i = 3; i < blog.post.length; i++) { %> + + + + + + + + +
+ + + + +
 
+
+ + + + +
+ +

+ {{blog.post[i]['tag']}} / {{blog.post[i]['author']}} +

+ + + + + + +
 
+ +

+ + {{blog.post[i]['title']}} + +

+ + + + + + +
 
+ +

+ {{blog.post[i]['text']}} +

+
+
+ + + + +
 
+
+ + + <% if (i < blog.post.length-1) { %> + + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ <% } %> + + <% } %> + + + + + + + + + +
+ + + + +
+ + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ + + + + + + + +
+ + + + +
 
+
+ + + + +
+ + + + + + +
+ + + + +
+
+ + Find more on {{blog.title}} +
+
+
+
+
+ + + + +
 
+
+ + + + + + +
+ + + + +
+ + + + + + +
 
+ + +
+
+ + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+
+
+ <% } %> + + <% } %> + + <% } %> + + + + + + + + +
+ + + + +
+ +

+ You’re receiving this email because you subscribed to {{newsletter.interval}} emails from {{blog.title}}
If you’d prefer not to receive these, you can + + unsubscribe instantly + . +

+
+
+ + + + + + +
+ + + + +
+ + + + + + +
 
+
+
+ + +
+
+
+ +
                                                           
+ + diff --git a/core/test/unit/mail/utils_spec.js b/core/test/unit/mail/utils_spec.js index f433a2a6d8..468d57fec1 100644 --- a/core/test/unit/mail/utils_spec.js +++ b/core/test/unit/mail/utils_spec.js @@ -5,7 +5,7 @@ var sinon = require('sinon'), describe('Mail: Utils', function () { var scope = {ghostMailer: null}; - before(function () { + beforeEach(function () { scope.ghostMailer = new mail.GhostMailer(); sandbox.stub(scope.ghostMailer.transport, 'sendMail', function (message, sendMailDone) { @@ -21,7 +21,7 @@ describe('Mail: Utils', function () { }); }); - after(function () { + afterEach(function () { sandbox.restore(); }); @@ -42,4 +42,75 @@ describe('Mail: Utils', function () { done(); }).catch(done); }); + + it('generates newsletter template', function (done) { + mail.utils.generateContent({ + template: 'newsletter', + data: { + blog: { + logo: 'http://myblog.com/content/images/blog-logo.jpg', + title: 'The Ghost Blog', + url: 'http://myblog.com', + twitterUrl: 'http://twitter.com/tryghost', + facebookUrl: 'https://www.facebook.com/ghost', + unsubscribe: 'http://myblog.com/unsubscribe', + post: [ + { + picture: 'http://myblog.com/content/images/post-1-image.jpg', + title: 'Featured blog post', + text: 'This is a featured blog post. It’s awesome…', + url: 'http://myblog.com/featured-blog-post', + tag: 'featured', + author: 'harry potter' + }, + { + picture: 'http://myblog.com/content/images/post-2-image.jpg', + title: 'Second blog post', + text: 'This is the second blog post. It’s also awesome…', + url: 'http://myblog.com/second-blog-post', + tag: 'second', + author: 'lord voldemord' + }, + { + picture: 'http://myblog.com/content/images/post-3-image.jpg', + title: 'Third blog post', + text: 'This is the third blog post. It’s also awesome…', + url: 'http://myblog.com/third-blog-post', + tag: 'third', + author: 'marry poppins' + }, + { + picture: 'http://myblog.com/content/images/post-4-image.jpg', + title: 'Fourth blog post', + text: 'This is the fourth blog post. It’s also awesome…', + url: 'http://myblog.com/fourth-blog-post', + tag: 'fourth', + author: 'donald duck' + }, + { + picture: 'http://myblog.com/content/images/post-5-image.jpg', + title: 'Fifth blog post', + text: 'This is the fifth blog post. It’s also awesome…', + url: 'http://myblog.com/fifth-blog-post', + tag: 'fifth', + author: 'casper the ghost' + } + ] + }, + newsletter: { + interval: 'monthly', + date: 'june, 9th 2016' + } + } + }).then(function (result) { + return scope.ghostMailer.send({ + to: 'aileen@ghost.org', + subject: 'The Newsletter Blog', + html: result.html, + text: result.text + }); + }).then(function () { + done(); + }).catch(done); + }); });