fix: external author image

feat/open-graph
Arik Chakma 9 months ago
parent 72d697f6d7
commit 1e044405a4
  1. 19
      scripts/generate-og-images.mjs

@ -219,17 +219,22 @@ async function generateGuideOpenGraph() {
for (const guide of allGuides) { for (const guide of allGuides) {
const author = allAuthors.find((author) => author.id === guide.authorId); const author = allAuthors.find((author) => author.id === guide.authorId);
const authorAvatar = await fs.readFile( const image =
path.join(ALL_AUTHOR_IMAGE_DIR, author.imageUrl), author?.imageUrl || 'https://roadmap.sh/images/default-avatar.png';
); const isExternalImage = image?.startsWith('http');
const avatarExt = author.imageUrl.split('.').pop(); let authorImageExtention = '';
let authorAvatar;
if (!isExternalImage) {
authorAvatar = await fs.readFile(path.join(ALL_AUTHOR_IMAGE_DIR, image));
authorImageExtention = image?.split('.')[1];
}
const template = getGuideTemplate({ const template = getGuideTemplate({
...guide, ...guide,
authorName: author.name, authorName: author.name,
authorAvatar: `data:image/${avatarExt};base64,${authorAvatar.toString( authorAvatar: isExternalImage
'base64', ? image
)}`, : `data:image/${authorImageExtention};base64,${authorAvatar.toString('base64')}`,
}); });
await generateOpenGraph(template, 'guides', guide.id + '.png'); await generateOpenGraph(template, 'guides', guide.id + '.png');
} }

Loading…
Cancel
Save