mirror of
https://github.com/SkyfallWasTaken/skyfalldev.git
synced 2025-02-22 21:12:05 +00:00
Fix images on blog index
This commit is contained in:
parent
1bf9af4349
commit
7a553d6457
1 changed files with 20 additions and 2 deletions
|
@ -34,16 +34,34 @@ let imagesLoadedEagerly = 0;
|
||||||
imagesLoadedEagerly += 1;
|
imagesLoadedEagerly += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let heroImage = post.data.heroImage;
|
||||||
|
|
||||||
|
let heroImagePromise;
|
||||||
|
if (heroImage) {
|
||||||
|
/** @type {Record<string, () => Promise<{default: import('astro').ImageMetadata}>>} */
|
||||||
|
const images: any = import.meta.glob(
|
||||||
|
"/src/assets/*.{jpeg,jpg,png,gif}",
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!images[heroImage]) {
|
||||||
|
throw new Error(
|
||||||
|
`"${heroImage}" does not exist in glob: "src/assets/*.{jpeg,jpg,png,gif}"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
heroImagePromise = images[heroImage];
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
<a href={`/blog/${post.slug}/`}>
|
<a href={`/blog/${post.slug}/`}>
|
||||||
{() => {
|
{() => {
|
||||||
if (post.data.heroImage) {
|
if (heroImagePromise) {
|
||||||
return (
|
return (
|
||||||
<Image
|
<Image
|
||||||
width={720}
|
width={720}
|
||||||
height={360}
|
height={360}
|
||||||
src={post.data.heroImage}
|
src={heroImagePromise()}
|
||||||
loading={shouldLoadEagerly ? "eager" : "lazy"}
|
loading={shouldLoadEagerly ? "eager" : "lazy"}
|
||||||
class="rounded-md mb-3"
|
class="rounded-md mb-3"
|
||||||
alt=""
|
alt=""
|
||||||
|
|
Loading…
Add table
Reference in a new issue