From 44b991f7c1a542b0785d6b53165346f584a1da50 Mon Sep 17 00:00:00 2001 From: Peter Meier Date: Sat, 16 May 2026 15:35:32 +0200 Subject: [PATCH] Improve social media OG/Twitter meta for posts - Fix bug: post page was overriding og:image with 150x200 thumbnail - og:type = "article" for posts (was always "website") - article:published_time, article:modified_time, article:author, article:tag - og:image:alt + twitter:image:alt (post headline) - twitter:label1/data1 with reading time - Remove thumbnail fallback from socialImage (falls back to site logo instead) Co-Authored-By: Claude Sonnet 4.6 --- src/routes/+layout.svelte | 32 +++++++++++++++++++++++++- src/routes/post/[slug]/+page.server.ts | 15 +++++++++--- src/routes/post/[slug]/+page.svelte | 9 -------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index ee9cdae..dd7e573 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -52,6 +52,14 @@ seoTitle?: string; seoDescription?: string; socialImage?: string; + ogType?: string; + ogImageAlt?: string; + articlePublishedTime?: string | null; + articleModifiedTime?: string | null; + articleAuthor?: string | null; + articleTags?: string[]; + twitterLabel1?: string; + twitterData1?: string; robots?: string; keywords?: string; preview?: boolean; @@ -218,7 +226,7 @@ {/if} - + {#if seoDescription} @@ -228,9 +236,24 @@ + {#if pageData?.ogImageAlt} + + {/if} {/if} + {#if pageData?.articlePublishedTime} + + {/if} + {#if pageData?.articleModifiedTime} + + {/if} + {#if pageData?.articleAuthor} + + {/if} + {#each pageData?.articleTags ?? [] as tag} + + {/each} @@ -240,6 +263,13 @@ {/if} {#if socialImageUrl} + {#if pageData?.ogImageAlt} + + {/if} + {/if} + {#if pageData?.twitterLabel1 && pageData?.twitterData1} + + {/if} {@html jsonLdScript} diff --git a/src/routes/post/[slug]/+page.server.ts b/src/routes/post/[slug]/+page.server.ts index 8074795..5c466ea 100644 --- a/src/routes/post/[slug]/+page.server.ts +++ b/src/routes/post/[slug]/+page.server.ts @@ -303,13 +303,22 @@ export const load: PageServerLoad = async ({ params, locals, url, setHeaders }) translations, seoTitle: post.seoTitle ?? postHeadline, seoDescription: postDescription, - socialImage: postSocialImageAbs ?? postImageUrl ?? undefined, + socialImage: postSocialImageAbs ?? undefined, + ogType: 'article' as const, + ogImageAlt: postHeadline, + articlePublishedTime: postCreated, + articleModifiedTime: postUpdated, + articleAuthor: postAuthor ?? siteName, + articleTags: (() => { + const tags = (post as { postTag?: Array<{ name?: string }> }).postTag ?? []; + return tags.map((t) => (typeof t === 'string' ? t : (t?.name ?? ''))).filter(Boolean); + })(), + twitterLabel1: 'Lesezeit', + twitterData1: `${readingTimeMinutes} Min.`, robots: (post as { seoMetaRobots?: string }).seoMetaRobots ?? undefined, keywords: (() => { const explicit = ((post as { seoKeywords?: string }).seoKeywords ?? '').trim(); if (explicit) return explicit; - // Fallback: join tag names so published posts without explicit keywords - // still ship a meaningful . const tags = (post as { postTag?: Array<{ name?: string }> }).postTag ?? []; const names = tags .map((t) => (typeof t?.name === 'string' ? t.name.trim() : '')) diff --git a/src/routes/post/[slug]/+page.svelte b/src/routes/post/[slug]/+page.svelte index d15d46b..77bc5d0 100644 --- a/src/routes/post/[slug]/+page.svelte +++ b/src/routes/post/[slug]/+page.svelte @@ -14,15 +14,6 @@ let { data }: { data: PageData } = $props(); - - {data.seoTitle} - {#if data.seoDescription} - - {/if} - {#if data.postImageUrl} - - {/if} -
{#if data.rawPostImageUrl}