-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (29 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs');
const path = require('path');
const Handlebars = require('handlebars');
require('./helpers');
const validTemplates = ['changelog'];
const aliases = {
blog: 'changelog',
};
const generate = (templateName, data) => {
const name = aliases[templateName] || templateName;
if (!validTemplates.includes(name)) {
throw new Error('invalid name of template. must be one of: ' + validTemplates.join(', '));
}
const fn = path.join(__dirname, 'src', name, 'email.html');
if (!fs.existsSync(fn)) {
throw new Error(`couldn't find template at ${fn}`);
}
const template = fs.readFileSync(fn).toString();
const tmpl = Handlebars.compile(template);
const _data = { ...data };
_data.__filename = fn;
_data.__dirname = path.dirname(fn);
_data.manageSubscriptionLink = '__MANAGE_SUBSCRIPTION_LINK__';
_data.unsubscribeLink = '__UNSUBSCRIBE_LINK__';
_data.poweredByImage = 'https://cdn.pinpoint.com/images/email/powered_by_30.png';
_data.poweredByLink = '__POWEREDBY_LINK__';
return tmpl(_data);
};
module.exports = { generate };