import type { FrontMatterMeta } from '@rspress/core'; import { normalizeImagePath, useFrontmatter } from '@rspress/core/runtime'; import { Button, Link, renderHtmlOrText } from '@rspress/core/theme'; import './index.scss'; import clsx from 'clsx'; const DEFAULT_HERO = { badge: '', name: '', text: '', tagline: '', actions: [], image: undefined, } satisfies FrontMatterMeta['hero']; interface HomeHeroProps { beforeHeroActions?: React.ReactNode; afterHeroActions?: React.ReactNode; image?: React.ReactNode; } function HomeHero({ beforeHeroActions, afterHeroActions, image, }: HomeHeroProps) { const { frontmatter } = useFrontmatter(); const hero = frontmatter?.hero || DEFAULT_HERO; const hasImage = hero.image !== undefined || image !== undefined; const multiHeroText = hero.text ? hero.text .toString() .split(/\n/g) .filter(text => text !== '') : []; const imageSrc = typeof hero.image?.src === 'string' ? { light: hero.image.src, dark: hero.image.src } : hero.image?.src || { light: '', dark: '' }; return (
{hero.badge && (typeof hero.badge === 'string' ? (
{hero.badge}
) : hero.badge.link ? ( {hero.badge.text} ) : (
{hero.badge.text}
))}
{multiHeroText.length !== 0 && multiHeroText.map(heroText => (
))}

<> {beforeHeroActions}
{hero.actions?.map(action => { return (
{afterHeroActions}
{image ? (
{image}
) : hero.image ? (
{hero.image?.alt} {hero.image?.alt}
) : null}
); } function normalizeSrcsetAndSizes( field: undefined | string | string[], ): string | undefined { const r = (Array.isArray(field) ? field : [field]).filter(Boolean).join(', '); return r || undefined; } export type { HomeHeroProps }; export { HomeHero };