-
Notifications
You must be signed in to change notification settings - Fork 3
/
mergeOptions.js
39 lines (32 loc) · 1.19 KB
/
mergeOptions.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
import path from 'node:path';
/**
* Merges the plugin options with defaults
*
* @param {DirectoriesConfig} [directoriesConfig]
* @param {EleventyPluginOgImageOptions} [pluginOptions]
* @returns {EleventyPluginOgImageMergedOptions}
*/
export function mergeOptions({ directoriesConfig, pluginOptions }) {
const { outputDir, previewDir, urlPath, OgImage, satoriOptions, ...options } = pluginOptions || {};
const eleventyOutput = directoriesConfig ? directoriesConfig.output : '';
const joinedOutputDir = path.join(eleventyOutput, outputDir || 'og-images');
return {
inputFileGlob: '**/*.og.*',
hashLength: 8,
outputFileExtension: 'png',
outputDir: joinedOutputDir,
previewDir: path.join(...(previewDir ? [eleventyOutput, previewDir] : [joinedOutputDir, 'preview'])),
urlPath: urlPath || outputDir || 'og-images',
/** @param {OgImage} ogImage */
outputFileSlug: (ogImage) => ogImage.hash(),
/** @param {OgImage} ogImage */
shortcodeOutput: async (ogImage) => `<meta property="og:image" content="${await ogImage.outputUrl()}" />`,
...options,
satoriOptions: {
width: 1200,
height: 630,
fonts: [],
...satoriOptions,
},
};
}