Created
September 29, 2017 09:51
-
-
Save OllieJT/3bb93fd02349a6fd3fe9d27fabe52a1f to your computer and use it in GitHub Desktop.
Need help setting inline style from Gatsby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
import Link from "gatsby-link"; | |
// This component pulls articles and lists them | |
class PostListing extends React.Component { | |
// This fetches the frontmatter from the .md files | |
getPostList() { | |
const postList = []; | |
this.props.postEdges.forEach(postEdge => { | |
postList.push({ | |
path: postEdge.node.fields.slug, | |
tags: postEdge.node.frontmatter.tags, | |
cover: postEdge.node.frontmatter.cover, | |
title: postEdge.node.frontmatter.title, | |
date: postEdge.node.frontmatter.date, | |
excerpt: postEdge.node.excerpt, | |
timeToRead: postEdge.node.timeToRead | |
}); | |
}); | |
return postList; | |
} | |
render() { | |
const postList = this.getPostList(); | |
// This one variation of what I have been trying | |
var cardBackground = { | |
//backgroundImage: "url(" + this.getPostList().map(post => post.cover) + ")", | |
//color: "red" | |
}; | |
return ( | |
<section className={`row ${ this.props.containerClass }`}> | |
{/* Your post list here. */ | |
postList.map(post => | |
<div className="col c4" key={post.title}> | |
<Link className="card" to={post.path}> | |
<ul className="tags"> | |
{post.tags && | |
post.tags.map(tag => | |
<li className="tag" key={tag}>{tag}</li> | |
)} | |
</ul> | |
<div className="title"> | |
<h6>{post.date}</h6> | |
<h5>{post.title}</h5> | |
</div> | |
<div className="overlay"></div> | |
{/* THIS is where I need the inline style /*} | |
<img className="thumbnail" src={post.cover} style={cardBackground}/> | |
</Link> | |
</div> | |
)} | |
</section> | |
); | |
} | |
} | |
export default PostListing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment