-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathblog-post.js
More file actions
137 lines (133 loc) · 3.59 KB
/
blog-post.js
File metadata and controls
137 lines (133 loc) · 3.59 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
125
126
127
128
129
130
131
132
133
134
135
136
137
import React from 'react'
import { Link, graphql } from 'gatsby'
import get from 'lodash/get'
import Bio from '../components/Bio'
import Layout from '../components/Layout'
import SEO from '../components/SEO'
import { formatReadingTime } from '../utils/helpers'
import { rhythm, scale } from '../utils/typography'
const GITHUB_USERNAME = '10secondsofcode'
const GITHUB_REPO_NAME = '10secondsofcode'
const PAGE_URL = 'https://10secondsofcode.com'
class BlogPostTemplate extends React.Component {
render() {
const post = this.props.data.markdownRemark
const siteTitle = get(this.props, 'data.site.siteMetadata.title')
const { previous, next, slug } = this.props.pageContext
const editUrl = `https://github.com/${GITHUB_USERNAME}/${GITHUB_REPO_NAME}/edit/master/src/pages/${slug.replace(
/\//g,
''
)}.md`
const discussUrl = `https://mobile.twitter.com/search?q=${encodeURIComponent(
`${PAGE_URL}${slug}`
)}`
return (
<Layout location={this.props.location} title={siteTitle}>
<SEO
title={post.frontmatter.title}
description={post.frontmatter.spoiler}
slug={post.fields.slug}
/>
<Link to={'/blog'}>← Back to Blog list</Link>
<h1>{post.frontmatter.title}</h1>
<p
style={{
...scale(-1 / 5),
display: 'block',
marginBottom: rhythm(1),
marginTop: rhythm(-1),
}}
>
{post.frontmatter.date}
{` • ${formatReadingTime(post.timeToRead)}`}
</p>
<div dangerouslySetInnerHTML={{ __html: post.html }} />
<hr></hr>
<p>
<Link to={'/blog'}>Back to Blog list</Link>
{` • `}
<a href={editUrl} target="_blank" rel="noopener noreferrer">
Edit on GitHub
</a>
{` • `}
<a href={discussUrl} target="_blank" rel="noopener noreferrer">
Discuss on Twitter
</a>
</p>
<hr
style={{
marginBottom: rhythm(1),
}}
/>
<h3
style={{
fontFamily: 'Montserrat, sans-serif',
marginTop: rhythm(0.25),
}}
>
<Link
style={{
boxShadow: 'none',
textDecoration: 'none',
color: 'rgb(240, 94, 94)',
}}
to={'/'}
>
{siteTitle}
</Link>
</h3>
{/* <Bio /> */}
<nav>
<ul
style={{
display: 'flex',
flexWrap: 'wrap',
justifyContent: 'space-between',
listStyle: 'none',
padding: 0,
}}
>
<li>
{previous && (
<Link to={'/blog' + previous.fields.slug} rel="prev">
← {previous.frontmatter.title}
</Link>
)}
</li>
<li>
{next && (
<Link to={'/blog' + next.fields.slug} rel="next">
{next.frontmatter.title} →
</Link>
)}
</li>
</ul>
</nav>
</Layout>
)
}
}
export default BlogPostTemplate
export const pageQuery = graphql`
query BlogPostBySlug($slug: String!) {
site {
siteMetadata {
title
author
}
}
markdownRemark(fields: { slug: { eq: $slug } }) {
id
html
timeToRead
frontmatter {
title
date(formatString: "MMMM DD, YYYY")
spoiler
}
fields {
slug
}
}
}
`