Skip to content

Commit 03e97bc

Browse files
authored
Merge pull request #381 from processing/homepage-images
Attempt to use Image component instead of img on homepage
2 parents 956fc12 + 8c67d74 commit 03e97bc

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/components/Image/index.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ type Props = ComponentProps<typeof Image> & {
55
/** Defaults to 'photo' aspect ratio */
66
aspectRatio?: "photo" | "square" | "none";
77
caption?: string;
8+
containerClass?: string;
89
};
910
const { props } = Astro;
1011
---
1112

12-
<div class="relative w-fit h-fit">
13+
<div class={props.containerClass || "relative w-fit h-fit"}>
1314
<!-- The props are identical but the lack of "IntrinsicAttributes" gives an errant ts error -->
1415
<!-- @ts-ignore -->
1516
<Image

src/components/PageHeader/HomePage.astro

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
import Image from "@components/Image/index.astro";
23
import type { CollectionEntry } from "astro:content";
34
import { Icon } from "../Icon";
45
@@ -32,20 +33,14 @@ const { config } = Astro.props;
3233

3334
{
3435
config.data.heroImages.map((im, i) => (
35-
<div class={`relative hero-image-container ${i > 0 ? "hidden" : ""}`}>
36-
<img
37-
class={"hero-image"}
38-
src={im.image.src}
39-
alt={im.altText}
40-
loading={i > 0 ? "lazy" : "eager"}
41-
/>
42-
<p
43-
aria-hidden
44-
class={"renderable-alt bg-bg-gray-40 line-clamp-3 absolute top-0 mt-sm mx-sm px-[7.5px] pb-[2.5px] rounded-xl text-body-caption text-ellipsis"}
45-
>
46-
{im.altText}
47-
</p>
48-
</div>
36+
<Image
37+
containerClass={`relative hero-image-container ${i > 0 ? "hidden" : ""}`}
38+
class={"hero-image"}
39+
aspectRatio="none"
40+
src={im.image}
41+
alt={im.altText}
42+
loading={i > 0 ? "lazy" : "eager"}
43+
/>
4944
))
5045
}
5146
</div>
@@ -56,7 +51,6 @@ const { config } = Astro.props;
5651
const images = document.querySelectorAll(".hero-image-container");
5752
if (images.length > 1) {
5853
const shownImageInd = Math.round(Math.random() * (images.length - 1));
59-
console.log(shownImageInd);
6054
// hide the default one
6155
images[0].classList.add("hidden");
6256
// show a random one

0 commit comments

Comments
 (0)