Skip to content

Commit 57b365c

Browse files
committed
feat: ✨ add blog snippets
1 parent 9aaec5e commit 57b365c

File tree

2 files changed

+88
-4
lines changed

2 files changed

+88
-4
lines changed

src/components/blog-post-snippet.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React from 'react'
2+
import styled from 'styled-components'
3+
import { Box, Flex } from '@rebass/grid'
4+
import { format } from 'date-fns/fp'
5+
import { Link } from 'gatsby'
6+
7+
let DateWithTimeline = styled.small`
8+
position: relative;
9+
padding-right: 20px;
10+
min-width: 150px;
11+
text-align: right;
12+
13+
&:after {
14+
margin-top: -6px;
15+
position: absolute;
16+
right: -7px;
17+
top: 50%;
18+
height: 12px;
19+
width: 12px;
20+
21+
background-color: #e1e4e8;
22+
border: 2px solid #fff;
23+
border-radius: 6px;
24+
box-sizing: border-box;
25+
content: ' ';
26+
display: block;
27+
}
28+
`
29+
30+
let Tag = styled(Link)`
31+
text-decoration: underline;
32+
color: grey;
33+
&:hover {
34+
color: #4078c0;
35+
}
36+
`
37+
38+
let BlogPostSnippet = ({
39+
post: { title, date, preface, timeToRead, tags },
40+
}) => (
41+
<Flex as="section" alignItems="center">
42+
<DateWithTimeline>{format('MMMM dd, yyyy', date)}</DateWithTimeline>
43+
<Box
44+
pl={20}
45+
css={`
46+
border-left: 2px solid #e1e4e8;
47+
`}
48+
>
49+
<h2>
50+
<Link to="/blog/">{title}</Link>
51+
</h2>
52+
<small>{timeToRead}</small>
53+
<p>{preface}</p>
54+
<Flex
55+
as="ul"
56+
m={0}
57+
css={`
58+
list-style: none;
59+
`}
60+
>
61+
{tags.map(t => (
62+
<Box as="li" key={t} pr="5px">
63+
<Tag to={`/blog/tag/${t}`}>
64+
<small>#{t}</small>
65+
</Tag>
66+
</Box>
67+
))}
68+
</Flex>
69+
</Box>
70+
</Flex>
71+
)
72+
73+
export default BlogPostSnippet
74+
export { BlogPostSnippet }

src/pages/blog.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import React from 'react'
22
import { Box } from '@rebass/grid'
3-
import Layout from '../components/layout'
43
import VisuallyHidden from '@reach/visually-hidden'
54

5+
import Layout from '../components/layout'
6+
import BlogPostSnippet from '../components/blog-post-snippet'
7+
8+
let posts = []
9+
610
let BlogPage = () => (
711
<Layout pageTitle="Blog">
812
<VisuallyHidden>
9-
<h2>Portfolio</h2>
13+
<h2>Blog</h2>
1014
</VisuallyHidden>
1115

12-
<Box as="b" mt="50px" style={{ display: 'block', textAlign: 'center' }}>
13-
Some posts might be here...
16+
<Box mt={10}>
17+
{posts.length === 0 ? (
18+
<Box as="b" style={{ display: 'block', textAlign: 'center' }}>
19+
Some posts might be here...
20+
</Box>
21+
) : (
22+
posts.map(post => <BlogPostSnippet key={post.id} post={post} />)
23+
)}
1424
</Box>
1525
</Layout>
1626
)

0 commit comments

Comments
 (0)