Skip to content

Commit

Permalink
fix(astro): URLs in meta.image
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Nov 20, 2024
1 parent 71d4c6a commit 11a6267
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ type DownloadAsZip =

Configures `<meta>` tags for Open Graph protocole and Twitter.
TutorialKit will use your logo as the default image.
Relative paths are resolved to `public` directory.
<PropertyTable inherited type="MetaTagsSchema" />

The `MetaTagsSchema` type has the following shape:
Expand All @@ -449,6 +450,13 @@ meta:
image: /cover.png
title: Title shown on social media and search engines
description: Description shown on social media and search engines
meta:
image: /cover.png # Resolves to public/cover.png
meta:
image: 'https://tutorialkit.dev/tutorialkit-opengraph.png' # URL is used as is
```

:::tip
Expand Down
9 changes: 6 additions & 3 deletions packages/astro/src/default/components/MetaTags.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ interface Props {
meta?: MetaTagsConfig;
}
const { meta = {} } = Astro.props;
let imageUrl;
if (meta.image) {
imageUrl = readPublicAsset(meta.image, true);
let imageUrl = meta.image;
if (imageUrl?.startsWith('/') || imageUrl?.startsWith('.')) {
imageUrl = readPublicAsset(imageUrl, true);
if (!imageUrl) {
console.warn(`Image ${meta.image} not found in "/public" folder`);
}
}
imageUrl ??= readLogoFile('logo', true);
---

Expand Down

0 comments on commit 11a6267

Please sign in to comment.