refactor: ♻️ move data up in the data cascade

In order for og-image generation to not generate broken previews the flow of data needs to be handled differently. This also makes metadata generation more predictable.
This commit is contained in:
Sebin Nyshkim 2025-05-18 17:12:11 +02:00
parent ddbad1d1a2
commit d2a9ec7936
6 changed files with 26 additions and 40 deletions

View file

@ -29,8 +29,7 @@ const urlFormat = ({ src, width, format }) => {
const imgUuid = src.match(/\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/);
const imgFormat = format === 'jpeg' ? 'jpg' : format;
if (src.startsWith(baseUrl))
return `${baseUrl}/${imgUuid[1]}.${imgFormat}?width=${width}`;
if (src.startsWith(baseUrl)) return `${baseUrl}/${imgUuid[1]}.${imgFormat}?width=${width}`;
return src;
};
@ -56,6 +55,17 @@ export default async function (eleventyConfig) {
: collection.getFilteredByGlob('./src/{posts,drafts}/*.md')
);
eleventyConfig.addGlobalData('site_name', "Sebin's Blog");
eleventyConfig.addGlobalData('type', 'article');
eleventyConfig.addGlobalData('image', { width: 1200, height: 630, src: '', alt: '' });
eleventyConfig.addGlobalData('author', {
name: 'Sebin Nyshkim',
href: 'https://blog.sebin-nyshkim.net',
image: 'https://img.sebin-nyshkim.net/i/b6629b72-ab77-4a6c-bf97-b1a615cc2454'
});
eleventyConfig.addGlobalData('twitter', { cardType: 'summary_large_image' });
eleventyConfig.addGlobalData('mastodon', { fediverseCreator: '@SebinNyshkim@meow.social' });
eleventyConfig.setFrontMatterParsingOptions({
excerpt: (file) => {
if (!file.data.tags) return; // immediately return if not a blog post with tags
@ -158,6 +168,7 @@ export const config = {
input: 'src',
output: 'public',
layouts: 'layouts',
includes: 'includes'
includes: 'includes',
data: 'data'
}
};