website/src/components/HeroCard.astro

59 lines
1.4 KiB
Plaintext
Raw Normal View History

2024-04-03 14:27:48 +02:00
---
import markdownToText from "@helpers/markdownToText";
import { Card } from "./card";
2024-04-03 16:18:30 +02:00
import { useTranslatedPath, useTranslations } from "@i18n/utils";
2024-04-03 14:27:48 +02:00
import Image from "@components/Image.astro";
2024-04-03 18:54:51 +02:00
import type { ImageMetadata } from "astro";
2024-04-03 14:27:48 +02:00
interface Props {
post: {
data: {
title: string;
icon?: string;
2024-04-03 18:54:51 +02:00
cover?: ImageMetadata;
2024-04-03 14:27:48 +02:00
};
collection: string;
slug: string;
body: string;
};
}
const {
2024-04-03 18:54:51 +02:00
data: { title, cover, icon },
2024-04-03 14:27:48 +02:00
collection,
body,
slug,
} = Astro.props.post;
2024-04-03 18:07:54 +02:00
const translatePath = useTranslatedPath(Astro.url);
const t = useTranslations(Astro.url);
2024-04-03 14:27:48 +02:00
const link = translatePath(`/${collection}/${slug.split("/")[0]}`);
---
<Card
2024-04-03 18:54:51 +02:00
classes={`grid gradient border-1 border-neutral overflow-hidden ${cover ? "grid-rows-[200px_1fr] sm:grid-rows-none sm:grid-cols-[1fr_200px]" : ""}`}
2024-04-03 14:27:48 +02:00
>
<Card.Content classes="px-8 py-7 order-last sm:order-first">
<Card.Title classes="text-4xl flex items-center gap-2">
{icon && <img src={icon} class="h-6" />}
{title}
</Card.Title>
<Card.Description>
{markdownToText(body).slice(0, 200)}
</Card.Description>
2024-04-03 16:18:30 +02:00
<Card.ReadMoreButton link={link} text={t("read-more")} />
2024-04-03 14:27:48 +02:00
</Card.Content>
{
2024-04-03 18:54:51 +02:00
cover && (
2024-04-03 14:27:48 +02:00
<a href={link}>
<Image
2024-04-03 18:54:51 +02:00
src={cover}
2024-04-03 14:27:48 +02:00
alt={"cover for " + title}
class="right-0 h-full object-cover object-center rounded-none border-l border-neutral"
/>
</a>
)
}
</Card>