Add CSS Inlining to minify.utils

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-05-02 22:49:51 +01:00
parent c06c7a29ce
commit f40cb103f8
3 changed files with 14 additions and 14 deletions

View File

@ -75,7 +75,7 @@ async function delRegReq(uuid) {
module.exports = {
query,
increment, // Probqbly doesn't need exporting?
//increment, // Probqbly doesn't need exporting?
addUser,
userAtime,
addRegReq,

View File

@ -2,7 +2,7 @@ const log = require('../utils/log.utils')
const crypto = require('crypto')
const db = require('../services/dbAccess.services')
const fs = require('fs/promises')
const minify = require('html-minifier').minify
const minify = require('../utils/minify.utils')
// Checks users registration key against issued keys
async function isAuthed(uuid) { // Needs testing
@ -33,18 +33,15 @@ async function generateKey() { // Needs testing & moving to 'register.utils'
async function generateConfirmationEmail(eml, uuid) {
try {
let htmlTpl = await fs.readFile('mail-templates/register.html', 'utf-8')
let mini = minify(((htmlTpl).replace(/>>ACCESSCODE<</g, uuid)), { // Add collapse whitespace here
removeComments: true,
collapseWhitespace: true,
minifyCSS: true
})
let txtTpl = fs.readFile('mail-templates/register.txt', 'utf-8')
return { // CSS Needs to be inlined. See css-inline, or css-inliner
const htmlTpl = await fs.readFile('mail-templates/register.html', 'utf-8')
const htmlStr = htmlTpl.replace(/>>ACCESSCODE<</g, uuid)
const htmlMin = await minify(htmlStr)
const txtTpl = fs.readFile('mail-templates/register.txt', 'utf-8')
return {
to: eml,
subject: 'OwlBoard Registration',
text: (await txtTpl).replace(/>>ACCESSCODE<</g, uuid),
html: mini
html: htmlMin
}
} catch(err) {
log.out('mailServices.generateConfirmationEmail: Error reading templates, $(err)', 'err')

View File

@ -1,7 +1,10 @@
const htmlShrink = require('html-minifier').minify
const juice = require('juice')
module.exports = async function minifyMail(input) {
// Minify HTML input, including inline styles.
//let inline = cssInliner(input) ??
return htmlShrink(input)
const inlined = juice(input)
return htmlShrink(inlined, {
removeComments: true,
collapseWhitespace: true
})
}