-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
Copy pathindex.tsx
67 lines (52 loc) · 1.69 KB
/
index.tsx
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
import { useTranslations } from 'next-intl';
import type { FC } from 'react';
import AvatarGroup from '@/components/Common/AvatarGroup';
import FormattedTime from '@/components/Common/FormattedTime';
import Preview from '@/components/Common/Preview';
import Link from '@/components/Link';
import { mapBlogCategoryToPreviewType } from '@/util/blogUtils';
import styles from './index.module.css';
// @todo: this should probably be a global type?
type Author = { fullName: string; src: string };
type BlogPostCardProps = {
title: string;
category: string;
description?: string;
authors?: Array<Author>;
date?: Date;
slug?: string;
};
const BlogPostCard: FC<BlogPostCardProps> = ({
title,
slug,
category,
description,
authors = [],
date,
}) => {
const t = useTranslations();
const avatars = authors.map(({ fullName, src }) => ({ alt: fullName, src }));
const type = mapBlogCategoryToPreviewType(category);
return (
<article className={styles.container}>
<Link href={slug} aria-label={title}>
<Preview title={title} type={type} />
</Link>
<Link href={`/blog/${category}`} className={styles.subtitle}>
{t(`layouts.blog.categories.${category}`)}
</Link>
<Link href={slug} className={styles.title}>
{title}
</Link>
{description && <p className={styles.description}>{description}</p>}
<footer className={styles.footer}>
<AvatarGroup avatars={avatars ?? []} />
<div className={styles.author}>
{avatars && <p>{avatars.map(({ alt }) => alt).join(', ')}</p>}
{date && <FormattedTime date={date} />}
</div>
</footer>
</article>
);
};
export default BlogPostCard;