-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlog.tsx
More file actions
92 lines (87 loc) · 2.85 KB
/
Blog.tsx
File metadata and controls
92 lines (87 loc) · 2.85 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
90
91
92
import Link from 'next/link';
import { Post, Author } from '../../lib/blog';
import { StyledBlog, Inner, Article, ArticleLink } from './Blog.styled';
import { Hero } from './Blog.styled';
import caveImgPng from './hero-images/chad-syntax-blog-cave.png';
import caveImgPng2x from './hero-images/chad-syntax-blog-cave@2x.png';
import caveImgWebp from './hero-images/chad-syntax-blog-cave.webp';
import caveImgWebp2x from './hero-images/chad-syntax-blog-cave@2x.png';
import { BreadCrumbs } from '../BreadCrumbs/BreadCrumbs';
import { useMemo } from 'react';
interface BlogProps {
posts: Post[];
authors: Author[];
}
const maxDescCharCount = 275;
export const Blog = (props: BlogProps) => {
const { posts, authors } = props;
const authorsMap = useMemo(() => {
const map = new Map();
for (const author of authors) {
map.set(author.slug, author);
}
return map;
}, [authors]);
return (
<StyledBlog>
<Inner>
<BreadCrumbs />
<Hero>
<h1>
Chad $yntax's Blog of infinite Wonders!
<picture>
<source
srcSet={`${caveImgPng.src}, ${caveImgPng2x.src} 2x`}
type="image/png"
/>
<source
srcSet={`${caveImgWebp.src}, ${caveImgWebp2x.src} 2x`}
type="image/webp"
/>
<img
src={caveImgWebp.src}
alt="Chad $yntax's Blog of infinite Wonders Logo!"
/>
</picture>
</h1>
<h2>
A Blog of posts. Posts about software engineering, web development,
and whatever else.
</h2>
<h3>
*Disclaimer: Wonders non-transferrable, see fine print for details.
</h3>
</Hero>
{posts.length === 0 && <p>The cave is... empty? Wtf.</p>}
<div>
{posts.map((post) => {
const { title, author } = post.data;
const targetAuthor = authorsMap.get(author);
let description = post.data.description ?? '';
if (description.length > maxDescCharCount) {
description = `${description
.slice(0, maxDescCharCount)
.trim()}...`;
}
return (
<Link key={title} href={`/blog/${post.slug}`} passHref>
<ArticleLink>
<Article>
<h3>{post.data.title}</h3>
<h5>
By
<Link href={`/blog/authors/${targetAuthor.slug}`}>
<a>{targetAuthor.name}</a>
</Link>
</h5>
<p>{description}</p>
</Article>
</ArticleLink>
</Link>
);
})}
</div>
</Inner>
</StyledBlog>
);
};