-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.js
27 lines (22 loc) · 937 Bytes
/
index.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
const { join } = require("path");
const { config } = require("./src/config");
exports.createOpenGraphImage = (createPage, options) => {
config.init(options)
const { defaultSize, componentGenerationDir, defaultWaitCondition } = config.getConfig();
const { path, component, context } = options;
const size = { ...defaultSize, ...(options.size || {}) };
const waitCondition = options.waitCondition ? options.waitCondition : defaultWaitCondition;
const componentPath = join(componentGenerationDir, encodeURIComponent(path.split("/").join("")));
const imgPath = join("public", path);
const generationContext = { componentPath, imgPath, size, waitCondition };
const ogImageMetaData = { path, size, __ogImageGenerationContext: generationContext };
createPage({
path: componentPath,
component: component,
context: {
...context,
ogImage: ogImageMetaData,
},
});
return ogImageMetaData;
};