-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBlogGridItem.tsx
More file actions
71 lines (63 loc) · 2.09 KB
/
Copy pathBlogGridItem.tsx
File metadata and controls
71 lines (63 loc) · 2.09 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
import dayjs from 'dayjs'
import Image from 'next/image'
import Link from 'next/link'
import authors from '@/lib/authors.json'
import {
BLOG_GRID_IMAGE_SIZES,
BLOG_PLACEHOLDER_IMAGE,
getBlogThumbnailImage,
} from '@/lib/blog-images'
import type Author from '@/types/author'
import type PostTypes from '@/types/post'
interface Props {
post: PostTypes
}
const BlogGridItem = ({ post }: Props) => {
const authorArray: string[] | undefined = post.author ? post.author.split(',') : []
const author = []
if (authorArray) {
for (let i = 0; i < authorArray.length; i++) {
author.push(
authors.find((authors: Author) => {
return authors.author_id === authorArray[i]
})
)
}
}
const imageUrl = getBlogThumbnailImage(post) ?? BLOG_PLACEHOLDER_IMAGE
return (
<Link
href={post.path}
prefetch={false}
className="group inline-block min-w-full p-2 sm:p-4 h-full border border-transparent transition-all hover:bg-surface-200 dark:hover:bg-surface-75 rounded-xl"
>
<div className="flex flex-col space-y-2">
<div className="flex flex-col space-y-1">
<div className="border-default relative mb-3 w-full aspect-[1.91/1] overflow-hidden rounded-lg border shadow-sm">
<Image
fill
sizes={BLOG_GRID_IMAGE_SIZES}
src={imageUrl}
className="scale-100 object-cover overflow-hidden"
alt={`${post.title} thumbnail`}
/>
</div>
{post.date && (
<div className="text-foreground-lighter flex items-center space-x-1.5 text-sm">
<p>{dayjs(post.date).format('D MMM YYYY')}</p>
{post.readingTime && (
<>
<p>·</p>
<p>{post.readingTime}</p>
</>
)}
</div>
)}
<h3 className="text-foreground max-w-sm text-xl">{post.title}</h3>
<p className="text-foreground-light max-w-sm text-base !mb-0">{post.description}</p>
</div>
</div>
</Link>
)
}
export default BlogGridItem