-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadNextCard.astro
More file actions
124 lines (115 loc) · 2.79 KB
/
ReadNextCard.astro
File metadata and controls
124 lines (115 loc) · 2.79 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
import { format } from 'date-fns';
import type { CollectionEntry } from 'astro:content';
interface Props {
currentSlug: string;
tags: string[];
relatedPosts: CollectionEntry<'posts'>[];
}
const { currentSlug, tags, relatedPosts } = Astro.props;
const tag = tags[0];
const tagSlug = tag?.toLowerCase().replace(/\s+/g, '-');
const filteredPosts = relatedPosts.filter(p => p.id !== currentSlug).slice(0, 3);
---
<div class="related-card">
<header class="related-header">
<span>More in</span>
<a href={`/tags/${tagSlug}/`}>{tag}</a>
</header>
<ul class="related-list">
{
filteredPosts.map(post => {
const d = new Date(post.data.date);
const words = post.body?.split(/\s+/).length ?? 0;
const readingTime = Math.max(1, Math.ceil(words / 265));
return (
<li>
<a href={`/posts/${post.id}/`}>{post.data.title}</a>
<span class="related-meta">
{format(d, 'dd LLL yyyy')} · {readingTime} min read
</span>
</li>
);
})
}
</ul>
<footer class="related-footer">
<a href={`/tags/${tagSlug}/`}>
See all {relatedPosts.length}
{relatedPosts.length === 1 ? 'post' : 'posts'} →
</a>
</footer>
</div>
<style>
.related-card {
background: #fff;
border-radius: var(--radius-lg);
padding: 24px;
box-shadow: var(--shadow-sm);
border: 1px solid var(--color-border);
}
@media (prefers-color-scheme: dark) {
.related-card {
background: var(--color-darkmode-l08);
border-color: var(--color-darkmode-border);
box-shadow: none;
}
}
.related-header {
font-size: 1.2rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
color: var(--color-midgrey);
margin-bottom: 16px;
}
.related-header a {
color: var(--color-accent);
text-decoration: none;
font-weight: 700;
}
.related-header a:hover {
text-decoration: underline;
}
.related-list {
list-style: none;
padding: 0;
margin: 0 0 16px;
display: flex;
flex-direction: column;
gap: 12px;
}
.related-list li {
display: flex;
flex-direction: column;
gap: 2px;
}
.related-list li a {
font-size: 1.5rem;
font-weight: 600;
color: var(--color-darkgrey);
text-decoration: none;
line-height: 1.35;
}
.related-list li a:hover {
color: var(--color-accent);
}
@media (prefers-color-scheme: dark) {
.related-list li a {
color: rgba(255, 255, 255, 0.85);
}
}
.related-meta {
font-size: 1.2rem;
color: var(--color-midgrey);
}
.related-footer a {
font-size: 1.35rem;
font-weight: 600;
color: var(--color-accent);
text-decoration: none;
}
.related-footer a:hover {
text-decoration: underline;
}
</style>