Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sitetitle): img component #2256

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions packages/starlight/components/SiteTitle.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@
import { logos } from 'virtual:starlight/user-images';
import config from 'virtual:starlight/user-config';
import type { Props } from '../props';
import { Image } from 'astro:assets';
const { siteTitle, siteTitleHref } = Astro.props;
---

<a href={siteTitleHref} class="site-title sl-flex">
{
config.logo && logos.dark && (
<>
<img
<Image
class:list={{ 'light:sl-hidden': !('src' in config.logo) }}
alt={config.logo.alt}
src={logos.dark.src}
width={logos.dark.width}
src={logos.dark}
height={logos.dark.height}
width={logos.dark.width}
alt={config.logo.alt}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The <Image> component loads the image lazily by default, so we should explicitly override that behaviour here given this is high priority content:

Suggested change
alt={config.logo.alt}
alt={config.logo.alt}
loading="eager"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, thanks.

/>
{/* Show light alternate if a user configure both light and dark logos. */}
{!('src' in config.logo) && (
<img
{!('src' in config.logo) && logos.light && (
<Image
class="dark:sl-hidden"
src={logos.light}
height={logos.light.height}
width={logos.light.width}
alt={config.logo.alt}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then same here:

Suggested change
alt={config.logo.alt}
alt={config.logo.alt}
loading="eager"

src={logos.light?.src}
width={logos.light?.width}
height={logos.light?.height}
/>
)}
</>
Expand Down
Loading