chore: Added newsletter scripts
This commit is contained in:
parent
935d380ff4
commit
a48c4f8b33
8 changed files with 96 additions and 23 deletions
|
@ -1,4 +1,4 @@
|
|||
module.exports = [
|
||||
export const testers = [
|
||||
{
|
||||
email: 'joost@joost.at',
|
||||
ehash: 'asefsdfsdfsdlfsllehash',
|
|
@ -142,6 +142,7 @@
|
|||
"handlebars": "^4.7.7",
|
||||
"jsonfile": "^6.1.0",
|
||||
"postcss": "^8.4.5",
|
||||
"rehype-format": "^4.0.1",
|
||||
"remark-cli": "^10.0.1",
|
||||
"remark-frontmatter": "^4.0.1",
|
||||
"remark-lint-emphasis-marker": "^3.1.1",
|
||||
|
|
|
@ -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,
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
require('dotenv').config()
|
||||
const lib = require('./lib')
|
||||
|
||||
lib.sendReal()
|
4
scripts/send-real-newsletter.mjs
Normal file
4
scripts/send-real-newsletter.mjs
Normal file
|
@ -0,0 +1,4 @@
|
|||
import 'dotenv/config'
|
||||
import { sendReal } from './newsletter-lib.mjs'
|
||||
|
||||
sendReal()
|
|
@ -1,4 +0,0 @@
|
|||
require('dotenv').config()
|
||||
const lib = require('./lib')
|
||||
|
||||
lib.sendTest()
|
4
scripts/send-test-newsletter.mjs
Normal file
4
scripts/send-test-newsletter.mjs
Normal file
|
@ -0,0 +1,4 @@
|
|||
import 'dotenv/config'
|
||||
import { sendTest } from './newsletter-lib.mjs'
|
||||
|
||||
sendTest()
|
58
yarn.lock
58
yarn.lock
|
@ -13902,6 +13902,13 @@ hast-util-embedded@^1.0.0:
|
|||
dependencies:
|
||||
hast-util-is-element "^1.1.0"
|
||||
|
||||
hast-util-embedded@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/hast-util-embedded/-/hast-util-embedded-2.0.0.tgz#877f4261044854743fc2621f728930ca61c8376f"
|
||||
integrity sha512-vEr54rDu2CheBM4nLkWbW8Rycf8HhkA/KsrDnlyKnvBTyhyO+vAG6twHnfUbiRGo56YeUBNCI4HFfHg3Wu+tig==
|
||||
dependencies:
|
||||
hast-util-is-element "^2.0.0"
|
||||
|
||||
hast-util-has-property@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/hast-util-has-property/-/hast-util-has-property-2.0.0.tgz#c15cd6180f3e535540739fcc9787bcffb5708cae"
|
||||
|
@ -13914,6 +13921,15 @@ hast-util-heading-rank@^2.0.0:
|
|||
dependencies:
|
||||
"@types/hast" "^2.0.0"
|
||||
|
||||
hast-util-is-body-ok-link@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/hast-util-is-body-ok-link/-/hast-util-is-body-ok-link-2.0.0.tgz#e0df6947b2676d2acac55c611755d359f264958e"
|
||||
integrity sha512-S58hCexyKdD31vMsErvgLfflW6vYWo/ixRLPJTtkOvLld24vyI8vmYmkgLA5LG3la2ME7nm7dLGdm48gfLRBfw==
|
||||
dependencies:
|
||||
"@types/hast" "^2.0.0"
|
||||
hast-util-has-property "^2.0.0"
|
||||
hast-util-is-element "^2.0.0"
|
||||
|
||||
hast-util-is-element@^1.0.0, hast-util-is-element@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/hast-util-is-element/-/hast-util-is-element-1.1.0.tgz#3b3ed5159a2707c6137b48637fbfe068e175a425"
|
||||
|
@ -13927,6 +13943,16 @@ hast-util-is-element@^2.0.0:
|
|||
"@types/hast" "^2.0.0"
|
||||
"@types/unist" "^2.0.0"
|
||||
|
||||
hast-util-phrasing@^2.0.0:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/hast-util-phrasing/-/hast-util-phrasing-2.0.1.tgz#48a63391688d242500f1b435665f29b9d81cc6b2"
|
||||
integrity sha512-Lw+gVihgE0Ye1TsToZqui0puQnHbZ0dFQe0c/Z2QJWGYRIc72DpH3UHLV8zU48sjIPord88MTSeYEbLQMp5A9g==
|
||||
dependencies:
|
||||
hast-util-embedded "^2.0.0"
|
||||
hast-util-has-property "^2.0.0"
|
||||
hast-util-is-body-ok-link "^2.0.0"
|
||||
hast-util-is-element "^2.0.0"
|
||||
|
||||
hast-util-sanitize@^3.0.0:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/hast-util-sanitize/-/hast-util-sanitize-3.0.2.tgz#b0b783220af528ba8fe6999f092d138908678520"
|
||||
|
@ -14251,6 +14277,11 @@ html-webpack-plugin@^5.5.0:
|
|||
pretty-error "^4.0.0"
|
||||
tapable "^2.0.0"
|
||||
|
||||
html-whitespace-sensitive-tag-names@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/html-whitespace-sensitive-tag-names/-/html-whitespace-sensitive-tag-names-2.0.0.tgz#80c7512c969de90c94279641068fafb5fa6da468"
|
||||
integrity sha512-SQdIvTTtnHAx72xGUIUudvVOCjeWvV1U7rvSFnNGxTGRw3ZC7RES4Gw6dm1nMYD60TXvm6zjk/bWqgNc5pjQaw==
|
||||
|
||||
htmlparser2@^6.0.0, htmlparser2@^6.1.0:
|
||||
version "6.1.0"
|
||||
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-6.1.0.tgz#c4d762b6c3371a05dbe65e94ae43a9f845fb8fb7"
|
||||
|
@ -23919,6 +23950,21 @@ rehype-autolink-headings@^6.1.1:
|
|||
unified "^10.0.0"
|
||||
unist-util-visit "^4.0.0"
|
||||
|
||||
rehype-format@^4.0.1:
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/rehype-format/-/rehype-format-4.0.1.tgz#0d4ad47733699dd8e3fcd9f73d04f210246b39e1"
|
||||
integrity sha512-HA92WeqFri00yiClrz54IIpM9no2DH9Mgy5aFmInNODoAYn+hN42a6oqJTIie2nj0HwFyV7JvOYx5YHBphN8mw==
|
||||
dependencies:
|
||||
"@types/hast" "^2.0.0"
|
||||
hast-util-embedded "^2.0.0"
|
||||
hast-util-is-element "^2.0.0"
|
||||
hast-util-phrasing "^2.0.0"
|
||||
hast-util-whitespace "^2.0.0"
|
||||
html-whitespace-sensitive-tag-names "^2.0.0"
|
||||
rehype-minify-whitespace "^5.0.0"
|
||||
unified "^10.0.0"
|
||||
unist-util-visit-parents "^5.0.0"
|
||||
|
||||
rehype-highlight@^5.0.1:
|
||||
version "5.0.2"
|
||||
resolved "https://registry.yarnpkg.com/rehype-highlight/-/rehype-highlight-5.0.2.tgz#de952123cd4d9672f21a4a38d3b119b88a08eafa"
|
||||
|
@ -23940,6 +23986,18 @@ rehype-minify-whitespace@^4.0.0:
|
|||
hast-util-whitespace "^1.0.4"
|
||||
unist-util-is "^4.0.0"
|
||||
|
||||
rehype-minify-whitespace@^5.0.0:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/rehype-minify-whitespace/-/rehype-minify-whitespace-5.0.1.tgz#79729a0146aa97a9d43e1eb4b5884974e2f37e77"
|
||||
integrity sha512-PPp4lWJiBPlePI/dv1BeYktbwkfgXkrK59MUa+tYbMPgleod+4DvFK2PLU0O0O60/xuhHfiR9GUIUlXTU8sRIQ==
|
||||
dependencies:
|
||||
"@types/hast" "^2.0.0"
|
||||
hast-util-embedded "^2.0.0"
|
||||
hast-util-is-element "^2.0.0"
|
||||
hast-util-whitespace "^2.0.0"
|
||||
unified "^10.0.0"
|
||||
unist-util-is "^5.0.0"
|
||||
|
||||
rehype-sanitize@^5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/rehype-sanitize/-/rehype-sanitize-5.0.1.tgz#dac01a7417bdd329260c74c74449697b4be5eb56"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue