-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathpost.js
More file actions
130 lines (123 loc) · 3.84 KB
/
post.js
File metadata and controls
130 lines (123 loc) · 3.84 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
import React, { Fragment, useEffect } from 'react';
import { graphql } from 'gatsby';
import { Disqus, CommentCount } from 'gatsby-plugin-disqus'
import Image from 'gatsby-image';
import Footer from '../components/Footer';
import MainNav from '../components/MainNav';
import Sidebar from '../components/Sidebar';
import SEO from '../components/SEO';
import { buildAuthorIndex } from '../utils/authors';
const windowGlobal = typeof window !== 'undefined' && window
export default function PostTemplate({ data }) {
const { authors, post } = data;
const { frontmatter, html, fields } = post;
const authorIndex = buildAuthorIndex(authors);
const author = authorIndex[frontmatter.author] || {};
const disqusConfig = {
url: `https://codingcoach.io${windowGlobal.location && windowGlobal.location.pathname}`,
identifier: post.fields.slug,
title: post.frontmatter.title,
}
useEffect(() => {
const twitterTweet = document.querySelector('.twitter-tweet');
if (twitterTweet) {
var s1 = document.createElement('script');
s1.src = 'https://platform.twitter.com/widgets.js';
twitterTweet.parentNode.insertBefore(s1, twitterTweet);
}
}, []);
return (
<Fragment>
<SEO title={frontmatter.title} />
<MainNav showLogo title="Blog" />
<div className="container py-16 lg:flex lg:flex-row">
<main className="lg:w-3/4 xl:pr-16">
<p className=" font-body text-xs md:text-sm">
{frontmatter.tags.map(tag => (
<span
key={tag}
className="inline-block mr-2 uppercase"
>
{tag}
</span>
))}
</p>
<h1 className=" font-display text-2xl md:text-3xl lg:text-4xl">
{frontmatter.title}
</h1>
<p className="mb-4 font-body uppercase text-xs md:text-sm">
<a aria-label={author.frontmatter.name} href={author.frontmatter.link} className="hover:underline">{author.frontmatter.name}</a>{' '}
<span className="inline-block mx-2">·</span>{' '}
{frontmatter.date}{' '}
<span className="inline-block mx-2">·</span>{' '}
{fields.readingTime.text}
<span className="inline-block mx-2">·</span>{' '}
{ windowGlobal && <CommentCount config={disqusConfig} placeholder={'...'} /> }
</p>
<div className="mb-4" style={{ maxHeight: '480px' }}>
{frontmatter.image && (
<Image
fluid={frontmatter.image.childImageSharp.fluid}
style={{ maxHeight: '480px' }}
/>
)}
</div>
<div
className="blog-content"
dangerouslySetInnerHTML={{ __html: html }}
/>
{ windowGlobal && <Disqus config={disqusConfig} style={{ margin: '0', width: 'auto' }}/> }
</main>
<Sidebar author={author} />
</div>
<Footer />
</Fragment>
);
}
export const pageQuery = graphql`
query PostQuery($slug: String!) {
post: markdownRemark(fields: { slug: { eq: $slug } }) {
html
frontmatter {
title
tags
author
date(formatString: "MMMM Do, YYYY")
image {
childImageSharp {
resize(width: 1500, height: 1500) {
src
}
fluid(maxWidth: 786) {
...GatsbyImageSharpFluid
}
}
}
}
fields {
slug
readingTime {
text
}
}
}
authors: allMarkdownRemark(
filter: { fields: { slug: { regex: "/^/authors/.*/" } } }
) {
edges {
node {
frontmatter {
name
avatar
about
link
}
id
fields {
slug
}
}
}
}
}
`;