-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
executable file
·41 lines (35 loc) · 1.24 KB
/
.eleventy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const fs = require('fs').promises;
const { handleGitIgnore } = require('./src/gitignore');
const { handleNetlifyToml } = require('./src/netlify');
const { handlePackageJson } = require('./src/package');
module.exports = function(config, pluginOptions) {
pluginOptions = Object.assign({
slugToImageDataMappingFile: 'resoc-image-data.json',
openGraphBasePath: '/social-images',
templatesDir: 'resoc-templates',
patchNetlifyToml: false
}, pluginOptions);
const imgData = {};
config.on('beforeBuild', async () => {
handleGitIgnore(pluginOptions.slugToImageDataMappingFile);
});
config.addShortcode('resoc', ({ ...options } ) => {
imgData[options.slug] = {
template: options.template,
values: options.values
};
return `${pluginOptions.openGraphBasePath}/${options.slug}.jpg`;
});
config.on('afterBuild', async () => {
if (!await handleNetlifyToml(pluginOptions)) {
throw 'Please fix your Netlify configuration';
}
if (!await handlePackageJson()) {
throw 'Please install the Resoc social image Netlify build plugin';
}
await fs.writeFile(
pluginOptions.slugToImageDataMappingFile,
JSON.stringify(imgData)
);
});
}