-
Notifications
You must be signed in to change notification settings - Fork 52
/
blog-post.js
153 lines (147 loc) · 4.25 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
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
/* eslint react/no-danger: "off" */
import React from 'react';
import PropTypes from 'prop-types';
import SEO from '../components/SEO';
import Layout from '../components/Layout';
import PostMeta from '../components/PostMeta';
import FloatingHead from '../components/FloatingHead';
import ContentWithFootnotes from '../components/ContentWithFootnotes';
import CTA from '../components/CTA';
import WithPopover from '../components/WithPopover';
import styles from '../styles/blog.module.css';
const getTitle = frontmatter => frontmatter.seo_title || frontmatter.title;
export default class BlogPost extends React.Component {
static propTypes = {
data: PropTypes.shape({
markdownRemark: PropTypes.any,
}).isRequired,
pathContext: PropTypes.shape({
slug: PropTypes.string.isRequired,
}).isRequired,
};
render() {
const {
data: { postData, imageSharp, offer, thumb, author, popoverImages },
} = this.props;
const postID = postData.internal.contentDigest;
const postImage = imageSharp && imageSharp.sizes && imageSharp.sizes.src;
if (!postImage) {
throw Error(`Missing image for ${this.props.pathContext.slug}`);
}
return [
<SEO
key={`seo-${postID}`}
postImage={postImage}
postData={postData}
isBlogPost
/>,
<WithPopover
key={`layout-${postID}`}
heading={offer.frontmatter.popover.heading}
imageArr={popoverImages.edges}
benefits={offer.frontmatter.popover.benefits}
button={offer.frontmatter.popover.button}
group={offer.frontmatter.popover.group}
source={`/${postData.frontmatter.slug}/`}
render={() => (
<Layout
title={getTitle(postData.frontmatter)}
className={styles.main}
>
<article className={styles.blog}>
<header className={styles.header}>
<h1 className={styles.heading}>{postData.frontmatter.title}</h1>
</header>
<PostMeta
className={styles.meta}
thumb={thumb}
categories={postData.frontmatter.category}
tags={postData.frontmatter.tag}
/>
<ContentWithFootnotes
className={styles.article}
render={() => (
<section
dangerouslySetInnerHTML={{ __html: postData.html }}
/>
)}
/>
<CTA
content={offer.html}
button={offer.frontmatter.button}
link={offer.frontmatter.link}
className={styles.cta}
/>
<FloatingHead className={styles.floatingHead} thumb={author} />
</article>
</Layout>
)}
/>,
];
}
}
export const pageQuery = graphql`
query BlogPostBySlug($slug: String!, $imageRegex: String!, $offer: String!) {
postData: markdownRemark(fields: { slug: { eq: $slug } }) {
internal {
contentDigest
}
html
frontmatter {
title
description
category
tag
# Used for schema.org
datePublished: date(formatString: "YYYY-MM-DDTHH:mm:ssZ")
images
seo_title
slug
cta
}
fields {
slug
}
}
offer: markdownRemark(id: { regex: $offer }) {
html
frontmatter {
button
link
popover {
heading
benefits
button
group
}
}
}
imageSharp(id: { regex: $imageRegex }) {
sizes(maxWidth: 1380) {
src
}
}
author: imageSharp(id: { regex: "/jason-lengstorf-square/" }) {
sizes(maxWidth: 690, traceSVG: { color: "#e7e3e8" }) {
...GatsbyImageSharpSizes_tracedSVG
}
}
thumb: imageSharp(id: { regex: $imageRegex }) {
sizes(maxWidth: 690, traceSVG: { color: "#e7e3e8" }) {
...GatsbyImageSharpSizes_tracedSVG
}
}
popoverImages: allImageSharp(
filter: { id: { regex: "/popover/.*.jpg/" } }
) {
edges {
node {
id
sizes(maxWidth: 660, traceSVG: { color: "#e7e3e8" }) {
...GatsbyImageSharpSizes_tracedSVG
}
}
}
}
}
`;