feat: programmatically generate open graph cards

This commit is contained in:
Cory Dransfeldt 2023-12-13 14:41:46 -08:00
parent e34ad2cb0e
commit 0b47dc7747
No known key found for this signature in database
15 changed files with 144 additions and 35 deletions

29
config/events/index.js Normal file
View file

@ -0,0 +1,29 @@
const fs = require('fs')
const Image = require('@11ty/eleventy-img')
const svgToJpeg = function () {
const socialPreviewImagesDir = '_site/assets/img/social-preview/'
fs.readdir(socialPreviewImagesDir, (err, files) => {
if (!!files && files.length > 0) {
files.forEach((fileName) => {
if (fileName.endsWith('.svg')) {
let imageUrl = socialPreviewImagesDir + fileName
Image(imageUrl, {
formats: ['jpeg'],
outputDir: './' + socialPreviewImagesDir,
filenameFormat: function (id, src, width, format) {
let outputFileName = fileName.substring(0, fileName.length - 4)
return `${outputFileName}.${format}`
},
})
}
})
} else {
console.log('⚠ No social images found')
}
})
}
module.exports = {
svgToJpeg,
}