Permalink
Browse files

Fix twitter-card image

  • Loading branch information...
snamiki1212 committed Dec 31, 2018
1 parent 35eae8d commit be8c7566270da0eb8af2e89352231b142f0ce502
Showing with 52 additions and 3 deletions.
  1. +4 −1 src/components/SEO/index.jsx
  2. +45 −0 src/components/SEOWrapper/index.jsx
  3. +3 −2 src/templates/post.jsx
@@ -5,7 +5,7 @@ import config from "../../../data/SiteConfig";

class SEO extends Component {
render() {
const { postNode, postPath, postSEO } = this.props;
const { postNode, postPath, postSEO, postImgNode} = this.props;
let title;
let description;
let image;
@@ -23,6 +23,9 @@ class SEO extends Component {
description = config.siteDescription;
image = config.siteLogo;
}
if(postImgNode){
image = postImgNode.childImageSharp.fluid.src;
}
image = urljoin(config.siteUrl, image);
const blogURL = config.siteUrl;
const schemaOrgJSONLD = [
@@ -0,0 +1,45 @@
import React from 'react';
import { StaticQuery, graphql } from 'gatsby'
import Img from 'gatsby-image';
import SEO from '../SEO';

class SEOWrapper extends React.Component{
render() {
const {postPath, postNode, postSEO} = this.props;
return (
<StaticQuery
query={query}
render={ data =>{
const postImgNode =
data.allFile.edges
.filter(edge=> edge.node.childImageSharp )
.find(edge => edge.node.childImageSharp.fixed.originalName === postNode.frontmatter.cover)
.node;
return <SEO postPath={postPath} postNode={postNode} postSEO postImgNode={postImgNode}/>
}}
/>
)
}
}

export default SEOWrapper;

const query =
graphql`
query IndexAllFiles{
allFile{
edges{
node{
childImageSharp{
fixed {
originalName
}
fluid {
src
}
}
}
}
}
}
`
@@ -12,7 +12,7 @@ import PostCover from "../components/PostCover";
import SocialLinks from "../components/SocialLinks";
import PostSuggestions from "../components/PostSuggestions";
import HeaderTitle from "../components/HeaderTitle";
import SEO from "../components/SEO";
import SEOWrapper from "../components/SEOWrapper";
import config from "../../data/SiteConfig";
import "./post.scss";

@@ -62,7 +62,8 @@ export default class PostTemplate extends React.Component {
<title>{`${post.title} | ${config.siteTitle}`}</title>
<link rel="canonical" href={`${config.siteUrl}${post.id}`} />
</Helmet>
<SEO postPath={slug} postNode={postNode} postSEO />
<SEOWrapper postPath={slug} postNode={postNode} postSEO />
{/* <SEO postPath={slug} postNode={postNode} postSEO /> */}
<PostCover
postNode={postNode}
coverHeight={coverHeight}

0 comments on commit be8c756

Please sign in to comment.