-
Notifications
You must be signed in to change notification settings - Fork 4
/
BlogList.js
131 lines (125 loc) · 3.41 KB
/
BlogList.js
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
125
126
127
128
129
130
131
import Link from "next/link";
import ReactMarkdown from "react-markdown";
const BlogList = (props) => {
function truncateSummary(content) {
return content.slice(0, 200).trimEnd();
}
function reformatDate(fullDate) {
const date = new Date(fullDate)
return date.toDateString().slice(4);
}
return (
<>
<ul className="list">
{props.allBlogs.length > 1 && props.allBlogs.map(post => (
<Link
key={post.slug}
href={{ pathname: `/blog/${post.slug}` }}
>
<a>
<li>
<div className="hero_image">
<img src={post.document.data.hero_image} alt={post.document.data.hero_image} />
</div>
<div className="blog__info">
<h2>{post.document.data.title}</h2>
<h3> {reformatDate(post.document.data.date)}</h3>
<p>
<ReactMarkdown source={truncateSummary(post.document.content)} />
</p>
</div>
</li>
</a>
</Link>
))}
</ul>
<style jsx>
{`
margin-bottom: 0;
a:hover {
opacity: 1;
}
a:hover li div.hero_image img {
opacity: 0.8;
transition: opacity 0.3s ease;
}
a:hover li .blog__info h2, a:hover li .blog__info h3, a:hover li .blog__info p {
transform: translateX(10px);
transition: transform 0.5s ease-out;
}
.hero_image {
width: 100%;
height: 33vh;
overflow: hidden;
background-color: #000;
}
.hero_image img {
object-fit: cover;
object-position: 50% 50%;
opacity: 1;
transition: opacity 0.3s ease;
min-height: 100%;
}
.blog__info {
display: flex;
flex-direction: column;
justify-content: center;
padding: 1.5rem 1.25rem;
transform: translateX(0px);
transition: transform 0.3s ease-in;
border-bottom: 1px solid #ebebeb;
}
.blog__info h2, .blog__info h3, .blog__info p {
transform: translateX(0px);
transition: transform 0.5s ease-out;
}
li {
opacity: inherit;
display: flex;
justify-content: center;
flex-direction: column;
min-height: 38vh;
margin-bottom: 0;
}
h2 {
margin-bottom: 0.5rem;
}
h3 {
margin-bottom: 1rem;
}
p {
max-width: 900px;
}
@media (min-width: 768px) {
li {
min-height: 250px;
height: 33.333vh;
flex-direction: row;
}
.hero_image {
height: 100%;
}
.hero_image img {
min-width: 100%;
height: 100%;
width: auto;
min-height: 0;
}
.blog__info {
min-width: 70%;
}
}
@media (min-width: 1280px) {
.blog__info {
padding: 3rem;
}
h3 {
margin-bottom: 1.2rem;
}
}
`}
</style>
</>
);
};
export default BlogList;