Skip to content

Commit

Permalink
fix: image glob
Browse files Browse the repository at this point in the history
  • Loading branch information
CoodingPenguin committed Jan 14, 2025
1 parent d6d9a6a commit 13839ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/components/HeroImage.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { Image } from "astro:assets";
const { image } = Astro.props;
const images = import.meta.glob<{ default: ImageMetadata }>(
"/src/assets/*.{jpeg,jpg,png,gif}"
"/src/assets/**/*.{jpeg,jpg,png,gif}"
);
// replace ../.. with src in image
let replacedImage = image.replace("../..", "/src");
if (!images[replacedImage])
throw new Error(
`"${replacedImage}" does not exist in glob: "src/assets/*.{jpeg,jpg,png,gif}"`
`"${replacedImage}" does not exist in glob: "src/assets/**/*.{jpeg,jpg,png,gif}"`
);
---

Expand Down
4 changes: 2 additions & 2 deletions src/pages/posts/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ const post = Astro.props;
const { Content } = await post.render();
const images = import.meta.glob<{ default: ImageMetadata }>(
"/src/assets/*.{jpeg,jpg,png,gif}"
"/src/assets/**/*.{jpeg,jpg,png,gif}"
);
const replacedHero = post.data.heroImage?.replace("../..", "/src");
if (replacedHero && !images[replacedHero])
throw new Error(
`"${post.data.heroImage}" does not exist in glob: "src/assets/*.{jpeg,jpg,png,gif}"`
`"${post.data.heroImage}" does not exist in glob: "src/assets/**/*.{jpeg,jpg,png,gif}"`
);
---

Expand Down

0 comments on commit 13839ab

Please sign in to comment.