Last active
April 6, 2020 15:18
-
-
Save tonyspiro/0ebb3b984255eef1f6d7dd9d3170ce8d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// index.js | |
const api = require('cosmicjs')(); | |
const bucket = api.bucket({ | |
slug: 'simple-react-blog', | |
read_key: '' // Find this in Bucket > Settings > API Access after logging in https://app.cosmicjs.com/login | |
}) | |
export async function getStaticProps() { | |
const post = (await bucket.getObject({ | |
slug: 'a-wonderful-blog-post-about-earth' | |
})).object | |
return { | |
props: { | |
post | |
} | |
} | |
} | |
const Post = ({ post }) => ( | |
<div style={{ maxWidth: 700, margin: '0 auto' }}> | |
<h1> | |
{ post.title } | |
</h1> | |
<img style={{ width: `100%`}} src={`${post.metadata.hero.imgix_url}?w=1000`} /> | |
<div dangerouslySetInnerHTML={{ __html: post.content }}/> | |
</div> | |
) | |
export default Post |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment