43 lines
2.7 KiB
JavaScript
Executable File
43 lines
2.7 KiB
JavaScript
Executable File
const fs = require("fs")
|
|
const { exec } = require("child_process");
|
|
const serverPath = require("./serverPath.js")
|
|
const members = require("/etc/newsletter_members.js")
|
|
const blogs = require(serverPath+"/blog/blogs.js")
|
|
let finalBlogIndex = blogs.length-1
|
|
const final_blog = blogs[finalBlogIndex]
|
|
const lastBlogIndex = require(serverPath+"/node/previousBlog.js")
|
|
|
|
if (finalBlogIndex > lastBlogIndex || process.argv[2] == "--test") {
|
|
final_blog[1] = final_blog[1].replace(/(?:\r\n|\r|\n)/g, '<br>')
|
|
final_blog[1] = final_blog[1].replace(/(?:\t)/g, ' ')
|
|
let imageAttachments = final_blog[3] ? `${final_blog[3].map(image => `-a ${serverPath}/images/${image}`).join('')}` : '';
|
|
console.log(imageAttachments);
|
|
//console.log(final_blog[1])
|
|
if (process.argv[2] == "--test") {
|
|
console.log("test")
|
|
let command = `echo '<h1>----TEST POST----</h1><br/><h3>Date created: ${final_blog[2]}</h3><br/>${final_blog[1]}<br/><br/><a href='https://deadvey.com/blog/blogs/${finalBlogIndex}.html'>Original Post</a>' | mutt -e "set content_type=text/html" -s "DeaDvey's Blog (TEST): ${final_blog[0]}" test@deadvey.com ${imageAttachments}`
|
|
console.log(`--------------\nFULL COMMAND TO RUN: ${command}\n---------------`)
|
|
exec(command)
|
|
}
|
|
else if (process.argv[2] == "--production-test") {
|
|
console.log("production test")
|
|
for (let current_member = 0; current_member < members.length; current_member++) {
|
|
let command = `echo '<h1>----HELLO, NEWSLETTER SUBSCRIBERS, THIS IS A TEST POST, PLEASE LET ME KNOW IF IT ARRIVES!----</h1><br/>${process.argv[3]}' | mutt -e "set content_type=text/html" -s "DeaDvey's Blog (TEST): ${final_blog[0]}" ${members[current_member]}`
|
|
exec(command)
|
|
console.log(`sent to ${members[current_member]}`)
|
|
}
|
|
}
|
|
else if (finalBlogIndex > lastBlogIndex) {
|
|
console.log("full distribution!!!")
|
|
for (let current_member = 0; current_member < members.length; current_member++) {
|
|
let command = `echo '<h3>Date created: ${final_blog[2]}</h3><br/>${final_blog[1]}<br/><br/><a href="https://deadvey.com/blog/blogs/${finalBlogIndex}.html">Original Post</a><br/><a href="mailto:newsletter@deadvey.com?subject=Requesting%20unsubscription%20from%20mailing%20list&body=Please%20unsubscribe%20me%20from%20the%20mailing%20list.">Unsubscribe</a>' | mutt -e "set content_type=text/html" -s "DeaDvey's Blog: ${final_blog[0]}" ${members[current_member]} ${imageAttachments}`
|
|
exec(command)
|
|
console.log(`sent to ${members[current_member]}`)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
finalBlogIndex = blogs.length-1
|
|
fs.writeFileSync(serverPath+"/node/previousBlog.js", `let lastBlog=${finalBlogIndex.toString()}; if (typeof module !== 'undefined' && module.exports) { module.exports = lastBlog; }`);
|