-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0926be
commit ffccca6
Showing
40 changed files
with
2,673 additions
and
2,075 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const socialImages = require('./events/socialImages'); | ||
|
||
const afterBuildEvents = [socialImages]; | ||
|
||
module.exports = { | ||
after: afterBuildEvents, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const Image = require('@11ty/eleventy-img'); | ||
const siteConfig = require('../../content/_data/siteConfig'); | ||
|
||
const SOCIAL_PREVIEW_IMAGES_DIR = path.join('_site', 'images', 'share'); | ||
const OUTPUT_IMAGE_EXTENSION = 'jpg'; | ||
|
||
module.exports = () => { | ||
const files = fs.readdirSync(SOCIAL_PREVIEW_IMAGES_DIR); | ||
|
||
if (siteConfig.opengraph.enableImageGeneration) { | ||
if (files && files.length > 0) { | ||
files.forEach(async (filename) => { | ||
if (filename.endsWith('.svg')) { | ||
const imageUrl = path.join(SOCIAL_PREVIEW_IMAGES_DIR, filename); | ||
|
||
await Image(imageUrl, { | ||
formats: ['jpeg'], | ||
outputDir: path.join('.', SOCIAL_PREVIEW_IMAGES_DIR), | ||
filenameFormat: () => { | ||
const outputFilename = filename.substring(0, filename.length - 4); | ||
|
||
return `${outputFilename}.${OUTPUT_IMAGE_EXTENSION}`; | ||
}, | ||
}); | ||
|
||
// we no longer need SVG files after converting to JPG so we remove them | ||
|
||
// fs.unlinkSync(imageUrl); | ||
} | ||
}); | ||
} | ||
} else { | ||
// If OG image generation is off, SVG files are not needed, | ||
// so we remove them from the build | ||
fs.rmSync(SOCIAL_PREVIEW_IMAGES_DIR, { recursive: true, force: true }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const moduleName = require('../helpers/moduleName'); | ||
|
||
const CHARACTERS_PER_LINE = 14; | ||
|
||
const body = (input) => { | ||
const parts = input.split(' '); | ||
|
||
const lines = parts.reduce((prev, current) => { | ||
if (!prev.length) { | ||
return [current]; | ||
} | ||
|
||
const lastOne = prev[prev.length - 1]; | ||
|
||
if (lastOne.length + current.length > CHARACTERS_PER_LINE) { | ||
return [...prev, current]; | ||
} | ||
|
||
prev[prev.length - 1] = lastOne + ' ' + current; | ||
|
||
return prev; | ||
}, []); | ||
|
||
return lines; | ||
}; | ||
|
||
module.exports = { | ||
name: moduleName(__filename), | ||
body, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,15 @@ | ||
const moduleName = require('../helpers/moduleName'); | ||
const { minify } = require('terser'); | ||
const { IS_PRODUCTION } = require('../constants'); | ||
|
||
const JS_MINIFIER_OPTIONS = { | ||
mangle: true, | ||
}; | ||
|
||
const body = async (content, outputPath) => { | ||
module.exports = async (content, outputPath) => { | ||
if (IS_PRODUCTION && outputPath && outputPath.endsWith('.js')) { | ||
const minified = await minify(content, JS_MINIFIER_OPTIONS); | ||
return minified.code; | ||
} else { | ||
return content; | ||
} | ||
}; | ||
|
||
module.exports = { | ||
name: moduleName(__filename), | ||
body, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
const jsonminify = require('jsonminify'); | ||
const { IS_PRODUCTION } = require('../constants'); | ||
const moduleName = require('../helpers/moduleName'); | ||
|
||
const body = (content, outputPath) => { | ||
module.exports = (content, outputPath) => { | ||
if (IS_PRODUCTION && outputPath && outputPath.endsWith('.json')) { | ||
return jsonminify(content); | ||
} | ||
return content; | ||
}; | ||
|
||
module.exports = { | ||
name: moduleName(__filename), | ||
body, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
const moduleName = require('../helpers/moduleName'); | ||
const minifyXML = require('minify-xml').minify; | ||
const minifyXML = import('minify-xml'); | ||
const { IS_PRODUCTION } = require('../constants'); | ||
|
||
const XML_MINIFIER_OPTIONS = { | ||
trimWhitespaceFromTexts: true, | ||
collapseWhitespaceInTexts: true, | ||
}; | ||
|
||
const body = (content, outputPath) => { | ||
module.exports = async (content, outputPath) => { | ||
if (IS_PRODUCTION && outputPath && outputPath.endsWith('.xml')) { | ||
return minifyXML(content, XML_MINIFIER_OPTIONS); | ||
const minifier = await minifyXML; | ||
const { minify } = minifier; | ||
return minify(content, XML_MINIFIER_OPTIONS); | ||
} | ||
return content; | ||
}; | ||
|
||
module.exports = { | ||
name: moduleName(__filename), | ||
body, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.