-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathletterBuilder.js
77 lines (68 loc) · 1.49 KB
/
letterBuilder.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const dotenv = require('dotenv')
const cheerio = require('cheerio')
dotenv.config()
const MONTHS = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
const DAYS = [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
]
const DATE = new Date()
var extension = "th"
switch (DATE.getDate()){
case(1):
extension = "st"
break;
case (2):
extension = "nd"
break
}
const TITLE = process.env.NEWSLETTER_TITLE
const CONTENTS = `
<h1>This is my newsletter</h1>
<p>Good morning! Today is ${DAYS[DATE.getDay()-1]}, the ${DATE.getDate()}${extension} of ${MONTHS[DATE.getMonth()]}, ${DATE.getFullYear()}. Here are five things you need to know...</p>
<ul>
<li>Always smile</li>
<li>Don't forget to brush your teeth</li>
<li>Keep in touch with your family</li>
</ul>
`
const $ = cheerio.load(CONTENTS)
const TEXT_ONLY = $.text()
function buildNewsletter(){
return {
"title": TITLE,
"html": CONTENTS,
"raw": TEXT_ONLY
}
}
function buildTestNewsletter(){
var epoch = Math.floor(+ new Date()/1000)
var testString = "Timestamp: " + epoch + " - This is a test email that can be ignored"
return {
"title": "*** TEST EMAIL ***",
"html": `<p>${testString}</p>`,
"raw": testString
}
}
module.exports = {
buildNewsletter,
buildTestNewsletter
}