summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Swithinbank2023-06-09 19:18:16 +0200
committerGitHub2023-06-09 19:18:16 +0200
commit4844915c25c9cdfb852e41584d93abfd85b82d08 (patch)
treeefc054f74d7c07717e235b7e63f51536893cdc50
parent89e0a04c26639246f550957acda2285e50417729 (diff)
downloadIT.starlight-4844915c25c9cdfb852e41584d93abfd85b82d08.tar.gz
IT.starlight-4844915c25c9cdfb852e41584d93abfd85b82d08.tar.bz2
IT.starlight-4844915c25c9cdfb852e41584d93abfd85b82d08.zip
Support setting an SVG as a hero image (#185)
-rw-r--r--.changeset/silent-feet-think.md5
-rw-r--r--packages/starlight/components/Hero.astro20
2 files changed, 18 insertions, 7 deletions
diff --git a/.changeset/silent-feet-think.md b/.changeset/silent-feet-think.md
new file mode 100644
index 00000000..c521c90e
--- /dev/null
+++ b/.changeset/silent-feet-think.md
@@ -0,0 +1,5 @@
+---
+"@astrojs/starlight": patch
+---
+
+Support setting an SVG as the hero image file
diff --git a/packages/starlight/components/Hero.astro b/packages/starlight/components/Hero.astro
index d16a60e2..a4768622 100644
--- a/packages/starlight/components/Hero.astro
+++ b/packages/starlight/components/Hero.astro
@@ -14,18 +14,24 @@ const {
image,
actions,
} = Astro.props.hero;
+
+const imageAttrs = {
+ loading: 'eager' as const,
+ decoding: 'async' as const,
+ width: 400,
+ height: 400,
+ alt: image?.alt,
+};
---
<div class="hero">
{
image?.file ? (
- <Image
- src={image.file}
- loading="eager"
- width={400}
- height={400}
- alt={image.alt}
- />
+ image.file.format === 'svg' ? (
+ <img src={image.file.src} {...imageAttrs} />
+ ) : (
+ <Image src={image.file} {...imageAttrs} />
+ )
) : (
image?.html && <div class="hero-html flex" set:html={image.html} />
)