From d39bf404bc1947c48b5cb15164f20f67c0be49bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Mon, 25 Nov 2024 17:22:40 +0200 Subject: [PATCH] fix: switch default `meta.image` to `.png` (#427) --- .../astro/src/default/components/MetaTags.astro | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/astro/src/default/components/MetaTags.astro b/packages/astro/src/default/components/MetaTags.astro index eedd613e..53990699 100644 --- a/packages/astro/src/default/components/MetaTags.astro +++ b/packages/astro/src/default/components/MetaTags.astro @@ -6,21 +6,27 @@ import { readPublicAsset } from '../utils/publicAsset'; interface Props { meta?: MetaTagsConfig; } + +const DEFAULT_OG_IMAGE = 'https://tutorialkit.dev/tutorialkit-opengraph.png'; + const { meta = {} } = Astro.props; let imageUrl = meta.image; +// Resolve relative paths to /public folder if (imageUrl?.startsWith('/') || imageUrl?.startsWith('.')) { imageUrl = readPublicAsset(imageUrl, true); if (!imageUrl) { - console.warn(`Image ${meta.image} not found in "/public" folder`); + console.warn(`\nImage ${meta.image} not found in "/public" folder`); } } -imageUrl ??= readLogoFile('logo', true); +imageUrl ??= DEFAULT_OG_IMAGE; + if (imageUrl?.endsWith('.svg')) { - console.warn(`Using a SVG open graph image "${imageUrl}". This is not supported by most social platforms. - You should rather set "meta.image" to a raster image (PNG, WEBP).`); + console.warn( + `\nUsing a SVG open graph image "${imageUrl}". This is not supported by most social platforms. You should rather set "meta.image" to a raster image (PNG, WEBP).`, + ); } ---