-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog-post.jsx
137 lines (119 loc) · 2.97 KB
/
blog-post.jsx
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
132
133
134
135
136
137
/** @jsx jsx */
import { jsx, BaseStyles } from 'theme-ui'
import { Link, graphql } from 'gatsby'
import Layout from 'src/components/layout'
import SEO from 'src/components/seo'
import 'katex/dist/katex.min.css'
function Pagination(props) {
const { previous, next } = props
return (
<ul
style={{
display: 'flex',
flexWrap: 'wrap',
justifyContent: 'space-between',
listStyle: 'none',
padding: 0,
}}
>
<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>
</ul>
)
}
function BlogPostTemplate(props) {
const post = props.data.markdownRemark
const siteTitle = props.data.site.siteMetadata.title
const { previous, next } = props.pageContext
const { location } = props
const { excerpt, html: postHtml, tableOfContents } = post
const { title: postTitle, date: postDate, tags, modified } = post.frontmatter
const genTagSection = (tagsArray) => {
if (tagsArray === null || tagsArray === undefined) {
return null
}
const tagsLink = tagsArray.map(
(tag, i) => (
<span key={tag}><Link to={tag}>{tags[i]}</Link></span>
),
).reduce((prev, curr) => [prev, ', ', curr])
return (
<span
css={{
fontStyle: 'normal',
textAlign: 'left',
}}
>
{' '}
· tags:
{' '}
{tagsLink}
</span>
)
}
const tagSection = genTagSection(post.fields.tagSlugs)
return (
<Layout location={location} title={siteTitle}>
<SEO title={postTitle} description={excerpt} />
<BaseStyles>
<h1>{postTitle}</h1>
<p sx={{
mb: 3,
a: {
textDecoration: 'underline 1px solid',
},
}}
>
{postDate !== null && postDate}
{/* {modified !== null && modified !== postDate && ` · ${modified}`} */}
{tagSection !== null && tagSection}
</p>
{/* {tableOfContents !== ''
&& <p dangerouslySetInnerHTML={{ __html: tableOfContents }} />} */}
{/* eslint-disable-next-line react/no-danger */}
<p dangerouslySetInnerHTML={{ __html: postHtml }} />
<hr />
</BaseStyles>
<Pagination previous={previous} next={next} />
</Layout>
)
}
export default BlogPostTemplate
export const pageQuery = graphql`
query BlogPostBySlug($slug: String!) {
site {
siteMetadata {
title
author
}
}
markdownRemark(fields: { slug: { eq: $slug } }) {
id
excerpt(pruneLength: 144)
html
fields {
slug
tagSlugs
}
tableOfContents
frontmatter {
title
date(formatString: "MMMM DD, YYYY")
# modified(formatString: "MMMM DD, YYYY")
tags
}
}
}
`