forked from gatsbyjs/gatsby-starter-blog
/
blog-post.js
95 lines (88 loc) · 2.15 KB
/
blog-post.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
import React from "react"
import { Link, graphql } from "gatsby"
import styled from "styled-components"
import Bio from "../components/bio"
import Layout from "../components/layout"
import SEO from "../components/seo"
import { rhythm, scale } from "../utils/typography"
const Title = styled.h1`
margin-top: ${rhythm(1)}
margin-bottom: 0;;
`
const Date = styled.p`
${{ ...scale(-1 / 5) }};
display: "block";
margin-bottom: ${rhythm(1)};
`
const Hr = styled.hr`
margin-bottom: ${rhythm(1)};
`
const PrevAndNext = styled.ul`
display: flex;
flex-wrap: wrap;
justify-content: space-between;
list-style: none;
padding: 0;
`
const BlogPostTemplate = ({ data, pageContext, location }) => {
const post = data.markdownRemark
const siteTitle = data.site.siteMetadata.title
const { previous, next } = pageContext
return (
<Layout location={location} title={siteTitle}>
<SEO
title={post.frontmatter.title}
description={post.frontmatter.description || post.excerpt}
/>
<article>
<header>
<Title> {post.frontmatter.title} </Title>
<Date> {post.frontmatter.date} </Date>
</header>
<section dangerouslySetInnerHTML={{ __html: post.html }} />
<Hr />
<footer>
<Bio />
</footer>
</article>
<nav>
<PrevAndNext>
<li>
{previous && (
<Link to={previous.fields.slug} rel="prev">
← {previous.frontmatter.title}
</Link>
)}
</li>
<li>
{next && (
<Link to={next.fields.slug} rel="next">
{next.frontmatter.title} →
</Link>
)}
</li>
</PrevAndNext>
</nav>
</Layout>
)
}
export default BlogPostTemplate
export const pageQuery = graphql`
query BlogPostBySlug($slug: String!) {
site {
siteMetadata {
title
}
}
markdownRemark(fields: { slug: { eq: $slug } }) {
id
excerpt(pruneLength: 160)
html
frontmatter {
title
date(formatString: "MMMM DD, YYYY")
description
}
}
}
`