feat: programmatically generate open graph cards
This commit is contained in:
parent
e34ad2cb0e
commit
0b47dc7747
15 changed files with 144 additions and 35 deletions
29
config/events/index.js
Normal file
29
config/events/index.js
Normal 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,
|
||||
}
|
Reference in a new issue