Get siteMetadata via GraphQL

It is important that decoupling between node code and browser code.
The 'gatsby-config.js' file must be kept in node code, but it exposed
into browser code because of the Disqus module.
To decouple this, all of the siteMetadata information is served via
GraphQL.
This commit has this change.
This commit is contained in:
ybbarng 2018-02-06 17:45:30 +09:00
parent 35c31a25fa
commit 1995b25ba3
No known key found for this signature in database
GPG Key ID: 80C507AF0D39B643
3 changed files with 7 additions and 6 deletions

View File

@ -1,6 +1,5 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import ReactDisqusComments from 'react-disqus-comments'; import ReactDisqusComments from 'react-disqus-comments';
import config from '../../../gatsby-config';
class Disqus extends Component { class Disqus extends Component {
constructor(props) { constructor(props) {
@ -20,15 +19,15 @@ class Disqus extends Component {
this.setState({ toasts }); this.setState({ toasts });
} }
render() { render() {
const { postNode } = this.props; const { postNode, siteMetadata } = this.props;
if (!config.siteMetadata.disqusShortname) { if (!siteMetadata.disqusShortname) {
return null; return null;
} }
const post = postNode.frontmatter; const post = postNode.frontmatter;
const url = config.siteMetadata.url + postNode.fields.slug; const url = siteMetadata.url + postNode.fields.slug;
return ( return (
<ReactDisqusComments <ReactDisqusComments
shortname={config.siteMetadata.disqusShortname} shortname={siteMetadata.disqusShortname}
identifier={post.title} identifier={post.title}
title={post.title} title={post.title}
url={url} url={url}

View File

@ -32,7 +32,7 @@ class PostTemplateDetails extends React.Component {
const commentsBlock = ( const commentsBlock = (
<div> <div>
<Disqus postNode={post} /> <Disqus postNode={post} siteMetadata={this.props.data.site.siteMetadata} />
</div> </div>
); );

View File

@ -34,6 +34,8 @@ export const pageQuery = graphql`
name name
twitter twitter
} }
disqusShortname
url
} }
} }
markdownRemark(fields: { slug: { eq: $slug } }) { markdownRemark(fields: { slug: { eq: $slug } }) {