1
0
Fork 0

chore: Added newsletter scripts

This commit is contained in:
Joost De Cock 2022-06-28 12:59:31 +02:00
parent 935d380ff4
commit a48c4f8b33
8 changed files with 96 additions and 23 deletions

View file

@ -1,15 +1,21 @@
const fs = require('fs')
const axios = require('axios')
const unified = require('unified')
const markdown = require('remark-parse')
const remark2rehype = require('remark-rehype')
const format = require('rehype-format')
const html = require('rehype-stringify')
const mustache = require('mustache')
const nodemailer = require('nodemailer')
const testers = require('./testers')
import fs from 'fs'
import path from 'path'
import axios from 'axios'
import { unified } from 'unified'
import markdown from 'remark-parse'
import remark2rehype from 'remark-rehype'
import format from 'rehype-format'
import html from 'rehype-stringify'
import mustache from 'mustache'
import nodemailer from 'nodemailer'
import { testers } from '../config/newsletter-testers.mjs'
import { fileURLToPath } from 'url';
const backend = process.env.FS_BACKEND
// Current working directory
const cwd = path.dirname(fileURLToPath(import.meta.url))
const backend = "https://backend.freesewing.org/"
const asHtml = async (text) => {
let content = await unified().use(markdown).use(remark2rehype).use(format).use(html).process(text)
@ -37,8 +43,16 @@ const getSubscribers = async (test = true) => {
}
const send = async (test = true) => {
const template = fs.readFileSync(`${__dirname}/../templates/newsletter.html`, 'utf8')
const text = fs.readFileSync(`${__dirname}/../newsletter/${process.env.NL_EDITION}/en.md`, 'utf8')
const template = fs.readFileSync(`${cwd}/../config/templates/newsletter.html`, 'utf8')
let edition
try {
edition = await axios.get(`https://posts.freesewing.org/newsletters?slug_eq=${process.env.NL_EDITION}`, 'utf8')
} catch (err) {
console.log(err)
process.exit()
}
const text = edition.body
const subscribers = await getSubscribers(test)
const content = await asHtml(text)
const inject = { content }
@ -82,7 +96,7 @@ const send = async (test = true) => {
const sendTest = () => send(true)
const sendReal = () => send(false)
module.exports = {
export {
sendTest,
sendReal,
}

View file

@ -1,4 +0,0 @@
require('dotenv').config()
const lib = require('./lib')
lib.sendReal()

View file

@ -0,0 +1,4 @@
import 'dotenv/config'
import { sendReal } from './newsletter-lib.mjs'
sendReal()

View file

@ -1,4 +0,0 @@
require('dotenv').config()
const lib = require('./lib')
lib.sendTest()

View file

@ -0,0 +1,4 @@
import 'dotenv/config'
import { sendTest } from './newsletter-lib.mjs'
sendTest()