-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtext.js
More file actions
141 lines (128 loc) · 4.39 KB
/
text.js
File metadata and controls
141 lines (128 loc) · 4.39 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* eslint-disable no-unused-vars */
// Take a string argument 'description' and format it by replacing various HTML tags and whitespace characters
function formatDescription (description) {
return description
.replace(/<br>+/g, '<br>')
.replace(/<p>\s+/g, '<p>')
.replace(/<br><p>/g, '<p>')
.replace(/<br><\/p>/g, '</p>')
.replace(/^<p>\s/g, '<p>')
.replace(/\s<\/p>/g, '</p>')
.replace(/<p>\s*<\/p>/g, '')
.replace(/\s+/g, ' ')
}
// Take an event object as an argument and generate a formatted description string for the event
function calDescription (event) {
const info = `<strong>More Info and RSVP:</strong><br><a href="${event.browser_url}">${event.browser_url}</a><br><br>`
const description = `<strong>Description:</strong><br>${formatDescription(event.description)}<br>`
const footer = (typeof customEventDescriptionFooter === 'function') // if customEventDescriptionFooter is defined, append it. otherwise nothing.
? customEventDescriptionFooter(event.description)
: ''
return info + description + footer
}
// This function takes a location object as an argument and generates a string with the venue, address, locality, region, and postal code
const formatLocation = (location) => {
if (location.postal_code === '') {
return ''
}
const { venue, address_lines: addressLines, locality, region, postal_code: zipCode } = location
return `${venue}, ${addressLines.join()}, ${locality}, ${region} ${zipCode}`
}
// This function takes an event object as an argument and returns a formatted string for use in a newsletter
function formatEvent (event) {
const startDate = getStartTime(event)
const endDate = getEndTime(event)
const templateTitle = `<h2>${event.title.trim()}</h2>`
const eventDate = startDate.toLocaleDateString('en-US', {
weekday: 'long',
month: 'long',
day: '2-digit'
})
const startTime = startDate.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit'
})
const endTime = endDate.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit'
})
const templateTimeAndLink = `<h3><time datetime=${startDate.toISOString()}>${eventDate}</time> | ${startTime} - ${endTime}</h3>`
const imageURL = event.featured_image_url
? `
<a href="${encodeURI(event.browser_url)}" target="_blank">
<img src="${encodeURI(event.featured_image_url)}" alt="Event Promo Image">
</a>
`
: ''
const buttonRSVP = `
<a href="${encodeURI(event.browser_url)}" target="_blank">
<button type="button">Sign Me Up</button>
</a>
`
return `
<article class="event_article">
${templateTitle}
${templateTimeAndLink}
${imageURL}
${buttonRSVP}
${formatDescription(event.description)}
</article>
`
}
function getUpcomingEventLimitFilter (nextdays) {
const futureDate = new Date()
futureDate.setDate(futureDate.getDate() + nextdays)
const queryFutureDate = `start_date lt '${Utilities.formatDate(futureDate, 'UTC', 'yyyy-MM-dd')}'`
return [queryFutureDate]
}
function getHTMLTopAnnouncement () {
return `
<br />
<hr class="rounded">
<h1 id="announcement">Priority Announcement</h1>
<br />
<p>Description of priority announcement.</p>
`
}
function getEventDescBody (event) {
return event.status !== 'cancelled' ? formatEvent(event) : ''
}
function getHTMLEvents (events) {
let doc = `
<br />
<hr class="rounded">
<h1 id="upcoming">Upcoming Events</h1>
`
if (typeof customNewsletterEventHeaderText === 'function') {
doc += customNewsletterEventHeaderText(events)
}
const eventBodies = events.map((event) => getEventDescBody(event))
doc += `
<section>
${eventBodies.join('')}
</section>
`
return doc
}
function getHTMLAnnouncements () {
let doc = ''
if (typeof customAnnouncements === 'function') {
doc += customAnnouncements()
}
return doc
}
// Compile an HTML message of upcoming events and return it as a string
function compileHTMLEmail (events) {
return getHTMLTopAnnouncement() + getHTMLEvents(events) + getHTMLAnnouncements()
}
// Consolidate event title and start time into a multi-line formatted string
function formatEventAnnouncementMessage (event) {
const startstring = getStartTime(event).toLocaleDateString('en-US', {
weekday: 'long',
month: 'long',
day: '2-digit',
hour: 'numeric',
minute: '2-digit'
})
return `*${event.title.trim()}*\n${startstring}`
}