This commit is contained in:
Andris Reinman 2016-05-04 19:11:41 +03:00
parent ab988837fe
commit 84869dafa7
7 changed files with 81 additions and 34 deletions

View file

@ -1,5 +1,9 @@
# Changelog
## 1.4.1 2016-05-04
* Added support for RSS templates
## 1.4.0 2016-05-04
* Added support for RSS campaigns

View file

@ -10,6 +10,7 @@ let shortid = require('shortid');
let isUrl = require('is-url');
let feed = require('../feed');
let log = require('npmlog');
let mailer = require('../mailer');
let allowedKeys = ['description', 'from', 'address', 'subject', 'template', 'source_url', 'list', 'segment', 'html', 'text'];
@ -323,6 +324,13 @@ module.exports.create = (campaign, opts, callback) => {
return callback(err);
}
mailer.getTemplate('emails/rss-html.hbs', (err, rendererHtml) => {
if (err) {
return callback(err);
}
campaign.html = rendererHtml();
create((err, campaignId) => {
if (err) {
return callback(err);
@ -357,6 +365,7 @@ module.exports.create = (campaign, opts, callback) => {
});
});
});
});
return;
} else if (campaign.template) {
templates.get(campaign.template, (err, template) => {

View file

@ -1,7 +1,7 @@
{
"name": "mailtrain",
"private": true,
"version": "1.4.0",
"version": "1.4.1",
"description": "Self hosted email newsletter app",
"main": "index.js",
"scripts": {

View file

@ -15,7 +15,7 @@ function feedLoop() {
return setTimeout(feedLoop, 15 * 1000);
}
let query = 'SELECT `id`, `source_url`, `from`, `address`, `subject`, `list`, `segment` FROM `campaigns` WHERE `type`=2 AND `status`=6 AND (`last_check` IS NULL OR `last_check`< NOW() - INTERVAL 10 MINUTE) LIMIT 1';
let query = 'SELECT `id`, `source_url`, `from`, `address`, `subject`, `list`, `segment`, `html` FROM `campaigns` WHERE `type`=2 AND `status`=6 AND (`last_check` IS NULL OR `last_check`< NOW() - INTERVAL 10 MINUTE) LIMIT 1';
connection.query(query, (err, rows) => {
connection.release();
@ -125,6 +125,13 @@ function checkEntries(parent, entries, callback) {
}
let entryId = result.insertId;
let html = (parent.html || '').toString().trim();
if (/\[RSS_ENTRY\]/i.test(html)) {
html = html.replace(/\[RSS_ENTRY\]/, entry.content);
} else {
html = entry.content + html;
}
let campaign = {
type: 'entry',
@ -134,7 +141,7 @@ function checkEntries(parent, entries, callback) {
subject: entry.title || parent.subject,
list: parent.list,
segment: parent.segment,
html: entry.content
html
};
campaigns.create(campaign, {

View file

@ -73,18 +73,13 @@
<input type="text" class="form-control" name="from" id="from" value="{{from}}" placeholder="This is the name your emails will come from" required>
</div>
</div>
<div class="form-group">
<label for="address" class="col-sm-2 control-label">Email "from" address</label>
<div class="col-sm-10">
<input type="email" class="form-control" name="address" id="address" value="{{address}}" placeholder="This is the address people will send replies to" required>
</div>
</div>
<div class="form-group">
<label for="subject" class="col-sm-2 control-label">Email "subject line"</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="subject" id="subject" value="{{subject}}" placeholder="Keep it relevant and non-spammy" required>
</div>
</div>
<hr />

View file

@ -76,6 +76,20 @@
</div>
</div>
<div class="form-group">
<label for="template-html" class="col-sm-2 control-label">Template content (HTML)</label>
<div class="col-sm-10">
{{#if disableWysiwyg}}
<div class="code-editor" id="template-html">{{html}}</div>
<input type="hidden" name="html">
{{else}}
<textarea class="form-control summernote" id="template-html" name="html" rows="8">{{html}}</textarea>
{{/if}}
<span class="help-block">Use special merge tag <code>[RSS_ENTRY]</code> to mark the position for the RSS post content. Additionally you can use any valid merge tag as well.</span>
</div>
</div>
<hr />
<div class="form-group">
@ -90,12 +104,6 @@
<input type="email" class="form-control" name="address" id="address" value="{{address}}" placeholder="This is the address people will send replies to" required>
</div>
</div>
<div class="form-group">
<label for="subject" class="col-sm-2 control-label">Email "subject line"</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="subject" id="subject" value="{{subject}}" placeholder="Keep it relevant and non-spammy" required>
</div>
</div>
</fieldset>
<hr />

24
views/emails/rss-html.hbs Normal file
View file

@ -0,0 +1,24 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div>
[RSS_ENTRY]
</div>
<p>
<a href="[LINK_PREFERENCES]" style="color: #666666; text-decoration: none;">Preferences</a>
<span style="color: #444444;">&nbsp;&nbsp;|&nbsp;&nbsp;</span>
<a href="[LINK_UNSUBSCRIBE]" style="color: #666666; text-decoration: none;">Unsubscribe</a>
<span style="color: #444444;">&nbsp;&nbsp;|&nbsp;&nbsp;</span>
<a href="[LINK_BROWSER]" style="color: #666666; text-decoration: none;">View this email in your browser</a>
</p>
</body>
</html>