-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathPostCard.astro
More file actions
89 lines (85 loc) · 2 KB
/
PostCard.astro
File metadata and controls
89 lines (85 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
/**
* PostCard Pattern Component
*
* An article card with a label, title, and author avatar(s).
*
* @example — Single author
* <PostCard
* href="/blog/secure-express-app"
* labels={["Security"]}
* title="How to secure your Express app"
* coverSrc="/images/cover.jpg"
* authors={[{ src: "/images/author.jpg", name: "John Doe" }]}
* avatarCaption="Jun 05, 2025"
* />
*
* @example — Multiple authors
* <PostCard
* href="/blog/express-5"
* labels={["Release"]}
* title="Express 5.0 is here"
* coverSrc="/images/cover.jpg"
* authors={[
* { src: "/images/author1.jpg", name: "Jane Smith" },
* { src: "/images/author2.jpg", name: "John Doe" },
* ]}
* avatarCaption="Mar 04, 2026"
* />
*/
import './PostCard.css';
import type { HTMLAttributes } from 'astro/types';
import { Image } from 'astro:assets';
import { H3, Avatar, Tag } from '@components/primitives';
interface Author {
src: string;
alt?: string;
name: string;
}
interface Props extends HTMLAttributes<'article'> {
href: string;
labels: string[];
title: string;
coverSrc?: string;
coverAlt?: string;
authors: Author[];
avatarCaption?: string;
}
const {
href,
labels,
title,
coverSrc,
coverAlt = '',
authors,
avatarCaption,
class: className,
...rest
} = Astro.props;
---
<article class:list={['post-card', className]} {...rest}>
<a href={href} class="post-card__link">
<div>
<!-- TODO: this will replaced by auto-generated OG images -->
{
coverSrc && (
<Image
class="post-card__cover"
src={coverSrc}
alt={coverAlt || ''}
width={800}
height={160}
loading="eager"
/>
)
}
<div class="post-card__labels">
{labels.map((label) => <Tag>{label}</Tag>)}
</div>
<H3 as="h2" vMargin={false} class="post-card__title">
{title}
</H3>
</div>
<Avatar authors={authors} caption={avatarCaption} size="md" />
</a>
</article>