This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
blog.js
106 lines (95 loc) 路 4.06 KB
/
blog.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
import { graphql } from 'gatsby';
import Helmet from 'react-helmet';
import React from 'react';
import Footer from '../components/Footer';
import CodeTabs from '../components/CodeTabs';
import CodeClipboard from '../components/CodeClipboard';
import BlogMain from '../components/Blog/BlogMain';
import BlogArticle from '../components/Blog/BlogArticle';
import LayoutNav from '../components/LayoutNav';
import Auth from '../components/Auth';
export default class Blog extends React.Component {
componentDidMount() {
this._codeTabs = new CodeTabs();
this._codeClipboard = new CodeClipboard();
}
componentWillUnmount() {
this._codeTabs = null;
this._codeClipboard.dispose();
}
render() {
const { data } = this.props;
const { mdx: { code, frontmatter: { title, mainPage, date, author, needsAuth }, excerpt, timeToRead } } = data;
return (
<Auth needsAuth={needsAuth}>
<div className="blog">
<Helmet>
<title>{title}</title>
<meta name="description" content={excerpt} />
<meta name="og:description" content={excerpt} />
<meta name="twitter:description" content={excerpt} />
<meta name="og:title" content={title} />
<meta name="og:type" content="article" />
<meta name="twitter.label1" content="Reading time" />
<meta
name="twitter:data1"
content={`${timeToRead} min read`}
/>
</Helmet>
<main className="content">
<header className="header">
<LayoutNav opaque={!mainPage} fixed={mainPage}/>
{mainPage &&
<div className="container-fluid">
<div className="row">
<div className="intro blog-intro text-center col">
<div className="container-fluid container-fluid-max-lg">
<h1 className="h1">Blog</h1>
<h2 className="h3">Where good ideas come from</h2>
</div>
</div>
</div>
</div>
}
</header>
<div className="clay-site-container container">
<div className="row">
<div className="col-md-12">
{/*renders a blog post content */}
{!mainPage &&
<article>
<BlogArticle title={title} author={author} date={date} codeBody={code.body} location={this.props.location} />
</article>
}
{/* renders the main page */}
{mainPage &&
<BlogMain title={title} excerpt={excerpt} timeToRead={timeToRead} />
}
</div>
</div>
</div>
</main>
<Footer />
</div>
</Auth>
);
}
}
export const pageQuery = graphql`
query($slug: String!) {
mdx(fields: { slug: { eq: $slug } }) {
excerpt
timeToRead
frontmatter {
title
mainPage
date(formatString: "MMMM DD, YYYY")
author
needsAuth
}
code {
body
}
}
}
`;