chore: cleanup and refactor

This commit is contained in:
Cory Dransfeldt 2023-12-11 11:00:39 -08:00
parent b6fb54ab98
commit 5295a6eacc
No known key found for this signature in database
37 changed files with 285 additions and 356 deletions

View file

@ -1,7 +1,6 @@
const { DateTime } = require('luxon')
const markdownIt = require('markdown-it')
const { URL } = require('url')
const marked = require('marked')
const sanitizeHTML = require('sanitize-html')
const utmPattern = /[?&](utm_[^&=]+=[^&#]*)/gi
@ -12,16 +11,9 @@ module.exports = {
trim: (string, limit) => {
return string.length <= limit ? string : `${string.slice(0, limit)}...`
},
stripIndex: (path) => {
return path.replace('/index.html', '/')
},
mdToHtml: (content) => {
return marked.parse(content)
},
btoa: (string) => {
return btoa(string)
},
dashLower: (string) => string.replace(/\s+/g, '-').toLowerCase(),
encodeAmp: (string) => {
if (!string) return
const pattern = /&(?!(?:[a-zA-Z]+|#[0-9]+|#x[0-9a-fA-F]+);)/g
@ -54,7 +46,6 @@ module.exports = {
},
webmentionsByUrl: (webmentions, url) => {
const allowedTypes = ['mention-of', 'in-reply-to', 'like-of', 'repost-of']
const data = {
'like-of': [],
'repost-of': [],

View file

@ -0,0 +1,18 @@
const htmlmin = require('html-minifier-terser')
const isProduction = process.env.ELEVENTY_ENV === 'production'
module.exports = (eleventyConfig) => {
eleventyConfig.addTransform('html-minify', (content, path) => {
if (path && path.endsWith('.html') && isProduction) {
return htmlmin.minify(content, {
collapseBooleanAttributes: true,
collapseWhitespace: true,
decodeEntities: true,
includeAutoGeneratedTags: false,
removeComments: true,
})
}
return content
})
}