Skip to content

Commit 7372af4

Browse files
committed
perf(hero): override component and set fetchpriority to high
1 parent 711f9fb commit 7372af4

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed

astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export default defineConfig({
108108
components: {
109109
Head: "./src/starlight-overrides/Head.astro",
110110
Header: "./src/starlight-overrides/Header.astro",
111+
Hero: "./src/starlight-overrides/Hero.astro",
111112
LanguageSelect: "./src/starlight-overrides/LanguageSelect.astro",
112113
MobileMenuToggle: "./src/starlight-overrides/MobileMenuToggle.astro",
113114
PageFrame: "./src/starlight-overrides/PageFrame.astro",

src/starlight-overrides/Hero.astro

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
import { Image } from "astro:assets";
3+
import type { ImageMetadata } from "astro";
4+
import { LinkButton } from "@astrojs/starlight/components";
5+
6+
const { data } = Astro.locals.starlightRoute.entry;
7+
const { title = data.title, tagline, image, actions = [] } = data.hero || {};
8+
9+
const imageAttrs = {
10+
loading: "eager" as const,
11+
decoding: "async" as const,
12+
width: 400,
13+
height: 400,
14+
alt: image?.alt || "",
15+
fetchpriority: "high" as const,
16+
};
17+
18+
let darkImage: ImageMetadata | undefined;
19+
let lightImage: ImageMetadata | undefined;
20+
let rawHtml: string | undefined;
21+
if (image) {
22+
if ("file" in image) {
23+
darkImage = image.file;
24+
} else if ("dark" in image) {
25+
darkImage = image.dark;
26+
lightImage = image.light;
27+
} else {
28+
rawHtml = image.html;
29+
}
30+
}
31+
---
32+
33+
<div class="hero">
34+
{
35+
darkImage && (
36+
<Image src={darkImage} {...imageAttrs} class={lightImage ? "light:sl-hidden" : undefined} />
37+
)
38+
}
39+
{lightImage && <Image src={lightImage} {...imageAttrs} class="dark:sl-hidden" />}
40+
{rawHtml && <div class="hero-html sl-flex" set:html={rawHtml} />}
41+
<div class="sl-flex stack">
42+
<div class="sl-flex copy">
43+
<h1 id="_top" data-page-title set:html={title} />
44+
{tagline && <div class="tagline" set:html={tagline} />}
45+
</div>
46+
{
47+
actions.length > 0 && (
48+
<div class="sl-flex actions">
49+
{actions.map(
50+
({ attrs: { class: className, ...attrs } = {}, icon, link: href, text, variant }) => (
51+
<LinkButton {href} {variant} icon={icon?.name} class:list={[className]} {...attrs}>
52+
{text}
53+
{icon?.html && <Fragment set:html={icon.html} />}
54+
</LinkButton>
55+
),
56+
)}
57+
</div>
58+
)
59+
}
60+
</div>
61+
</div>
62+
63+
<style>
64+
@layer starlight.core {
65+
.hero {
66+
display: grid;
67+
align-items: center;
68+
gap: 1rem;
69+
padding-bottom: 1rem;
70+
}
71+
72+
.hero > img,
73+
.hero > .hero-html {
74+
object-fit: contain;
75+
width: min(70%, 20rem);
76+
height: auto;
77+
margin-inline: auto;
78+
}
79+
80+
.stack {
81+
flex-direction: column;
82+
gap: clamp(1.5rem, calc(1.5rem + 1vw), 2rem);
83+
text-align: center;
84+
}
85+
86+
.copy {
87+
flex-direction: column;
88+
gap: 1rem;
89+
align-items: center;
90+
}
91+
92+
.copy > * {
93+
max-width: 50ch;
94+
}
95+
96+
h1 {
97+
font-size: clamp(var(--sl-text-3xl), calc(0.25rem + 5vw), var(--sl-text-6xl));
98+
line-height: var(--sl-line-height-headings);
99+
font-weight: 600;
100+
color: var(--sl-color-white);
101+
}
102+
103+
.tagline {
104+
font-size: clamp(var(--sl-text-base), calc(0.0625rem + 2vw), var(--sl-text-xl));
105+
color: var(--sl-color-gray-2);
106+
}
107+
108+
.actions {
109+
gap: 1rem 2rem;
110+
flex-wrap: wrap;
111+
justify-content: center;
112+
}
113+
114+
@media (min-width: 50rem) {
115+
.hero {
116+
grid-template-columns: 7fr 4fr;
117+
gap: 3%;
118+
padding-block: clamp(2.5rem, calc(1rem + 10vmin), 10rem);
119+
}
120+
121+
.hero > img,
122+
.hero > .hero-html {
123+
order: 2;
124+
width: min(100%, 25rem);
125+
}
126+
127+
.stack {
128+
text-align: start;
129+
}
130+
131+
.copy {
132+
align-items: flex-start;
133+
}
134+
135+
.actions {
136+
justify-content: flex-start;
137+
}
138+
}
139+
}
140+
</style>

0 commit comments

Comments
 (0)