-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
template-blog-post.js
384 lines (378 loc) · 11.7 KB
/
template-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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
import React from "react"
import Helmet from "react-helmet"
import { Link, graphql } from "gatsby"
import rehypeReact from "rehype-react"
import ArrowForwardIcon from "react-icons/lib/md/arrow-forward"
import ArrowBackIcon from "react-icons/lib/md/arrow-back"
import Img from "gatsby-image"
import Layout from "../components/layout"
import presets, { colors } from "../utils/presets"
import typography, { rhythm, scale, options } from "../utils/typography"
import Container from "../components/container"
import EmailCaptureForm from "../components/email-capture-form"
import TagsSection from "../components/tags-section"
import HubspotForm from "../components/hubspot-form"
import Chart from "../components/chart"
const renderAst = new rehypeReact({
createElement: React.createElement,
components: {
"hubspot-form": HubspotForm,
"date-chart": Chart,
},
}).Compiler
class BlogPostTemplate extends React.Component {
render() {
const post = this.props.data.markdownRemark
const prev = this.props.pageContext.prev
const next = this.props.pageContext.next
const prevNextLinkStyles = {
"&&": {
boxShadow: `none`,
borderBottom: 0,
fontFamily: options.headerFontFamily.join(`,`),
fontWeight: `bold`,
color: colors.gatsby,
},
}
const prevNextLabelStyles = {
marginTop: 0,
marginBottom: 0,
color: colors.gray.calm,
fontWeight: `normal`,
...scale(0),
lineHeight: 1,
}
const BioLine = ({ children }) => (
<p
css={{
...scale(-2 / 5),
fontFamily: typography.options.headerFontFamily.join(`,`),
lineHeight: 1.3,
margin: 0,
color: colors.gray.calm,
[presets.Mobile]: {
...scale(-1 / 5),
lineHeight: 1.3,
},
}}
>
{children}
</p>
)
let canonicalLink
if (post.frontmatter.canonicalLink) {
canonicalLink = (
<link rel="canonical" href={post.frontmatter.canonicalLink} />
)
}
return (
<Layout location={this.props.location}>
<Container className="post" css={{ paddingBottom: `0` }}>
<main id={`reach-skip-nav`}>
{/* Add long list of social meta tags */}
<Helmet>
<title>{post.frontmatter.title}</title>
<link
rel="author"
href={`https://gatsbyjs.org${
post.frontmatter.author.fields.slug
}`}
/>
<meta
name="description"
content={
post.frontmatter.excerpt
? post.frontmatter.excerpt
: post.excerpt
}
/>
<meta property="og:description" content={post.excerpt} />
<meta name="twitter:description" content={post.excerpt} />
<meta property="og:title" content={post.frontmatter.title} />
{post.frontmatter.image && (
<meta
property="og:image"
content={`https://gatsbyjs.org${
post.frontmatter.image.childImageSharp.resize.src
}`}
/>
)}
{post.frontmatter.image && (
<meta
name="twitter:image"
content={`https://gatsbyjs.org${
post.frontmatter.image.childImageSharp.resize.src
}`}
/>
)}
<meta property="og:type" content="article" />
<meta
name="article:author"
content={post.frontmatter.author.id}
/>
<meta
name="twitter:creator"
content={post.frontmatter.author.twitter}
/>
<meta name="author" content={post.frontmatter.author.id} />
<meta name="twitter:label1" content="Reading time" />
<meta
name="twitter:data1"
content={`${post.timeToRead} min read`}
/>
<meta
name="article:published_time"
content={post.frontmatter.rawDate}
/>
{canonicalLink}
</Helmet>
<section
css={{
display: `flex`,
marginTop: rhythm(-1 / 4),
marginBottom: rhythm(1),
[presets.Tablet]: {
marginTop: rhythm(1 / 2),
marginBottom: rhythm(2),
},
}}
>
<div
css={{
flex: `0 0 auto`,
}}
>
<Link to={post.frontmatter.author.fields.slug}>
<Img
fixed={post.frontmatter.author.avatar.childImageSharp.fixed}
css={{
height: rhythm(2.3),
width: rhythm(2.3),
margin: 0,
borderRadius: `100%`,
display: `inline-block`,
verticalAlign: `middle`,
}}
/>
</Link>
</div>
<div
css={{
flex: `1 1 auto`,
marginLeft: rhythm(1 / 2),
}}
>
<Link to={post.frontmatter.author.fields.slug}>
<h4
css={{
...scale(0),
fontWeight: 400,
margin: 0,
color: `${colors.gatsby}`,
}}
>
<span
css={{
borderBottom: `1px solid ${colors.ui.bright}`,
boxShadow: `inset 0 -2px 0 0 ${colors.ui.bright}`,
transition: `all ${presets.animation.speedFast} ${
presets.animation.curveDefault
}`,
"&:hover": {
background: colors.ui.bright,
},
}}
>
{post.frontmatter.author.id}
</span>
</h4>
</Link>
<BioLine>{post.frontmatter.author.bio}</BioLine>
<BioLine>
{post.timeToRead} min read · {post.frontmatter.date}
{post.frontmatter.canonicalLink && (
<span>
{` `}
(originally published at
{` `}
<a href={post.frontmatter.canonicalLink}>
{post.frontmatter.publishedAt}
</a>
)
</span>
)}
</BioLine>
</div>
</section>
<h1
css={{
marginTop: 0,
[presets.Desktop]: {
marginBottom: rhythm(5 / 4),
},
}}
>
{this.props.data.markdownRemark.frontmatter.title}
</h1>
{post.frontmatter.image &&
!(post.frontmatter.showImageInArticle === false) && (
<div
css={{
marginBottom: rhythm(1),
}}
>
<Img fluid={post.frontmatter.image.childImageSharp.fluid} />
{post.frontmatter.imageAuthor &&
post.frontmatter.imageAuthorLink && (
<em>
Image by
{` `}
<a href={post.frontmatter.imageAuthorLink}>
{post.frontmatter.imageAuthor}
</a>
</em>
)}
</div>
)}
<section className="post-body">
{renderAst(this.props.data.markdownRemark.htmlAst)}
</section>
<TagsSection
tags={this.props.data.markdownRemark.frontmatter.tags}
/>
<EmailCaptureForm />
</main>
</Container>
<div
css={{
borderTop: `1px solid ${colors.ui.light}`,
marginTop: rhythm(2),
[presets.Tablet]: {
marginTop: rhythm(2),
paddingBottom: rhythm(1),
paddingTop: rhythm(1),
},
[presets.Desktop]: {
marginTop: rhythm(3),
paddingBottom: rhythm(2),
paddingTop: rhythm(2),
},
}}
>
<Container>
<div
css={{ [presets.Phablet]: { display: `flex`, width: `100%` } }}
>
<div
css={{
[presets.Phablet]: {
width: `50%`,
},
}}
>
{prev && (
<Link to={prev.fields.slug} css={prevNextLinkStyles}>
<h4 css={prevNextLabelStyles}>Previous</h4>
<span
css={{
[presets.Tablet]: {
marginLeft: `-1rem`,
},
}}
>
<ArrowBackIcon style={{ verticalAlign: `sub` }} />
{prev.frontmatter.title}
</span>
</Link>
)}
</div>
<div
css={{
textAlign: `right`,
marginTop: rhythm(1),
[presets.Phablet]: { marginTop: 0, width: `50%` },
}}
>
{next && (
<Link to={next.fields.slug} css={prevNextLinkStyles}>
<h4 css={prevNextLabelStyles}>Next</h4>
<span
css={{
[presets.Tablet]: {
marginRight: `-1rem`,
},
}}
>
{next.frontmatter.title}
<ArrowForwardIcon style={{ verticalAlign: `sub` }} />
</span>
</Link>
)}
</div>
</div>
</Container>
</div>
</Layout>
)
}
}
export default BlogPostTemplate
export const pageQuery = graphql`
query($slug: String!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
htmlAst
excerpt
timeToRead
fields {
slug
}
frontmatter {
title
excerpt
date(formatString: "MMMM Do YYYY")
rawDate: date
canonicalLink
publishedAt
tags
image {
childImageSharp {
resize(width: 1500, height: 1500) {
src
}
fluid(maxWidth: 786) {
...GatsbyImageSharpFluid
}
}
}
imageAuthor
imageAuthorLink
imageTitle
showImageInArticle
author {
id
bio
twitter
avatar {
childImageSharp {
fixed(
width: 63
height: 63
quality: 75
traceSVG: {
turdSize: 10
background: "#f6f2f8"
color: "#e0d6eb"
}
) {
...GatsbyImageSharpFixed_tracedSVG
}
}
}
fields {
slug
}
}
}
}
}
`