Skip to content

Instantly share code, notes, and snippets.

@tonyspiro
Last active April 6, 2020 15:18
Show Gist options
  • Save tonyspiro/0ebb3b984255eef1f6d7dd9d3170ce8d to your computer and use it in GitHub Desktop.
Save tonyspiro/0ebb3b984255eef1f6d7dd9d3170ce8d to your computer and use it in GitHub Desktop.
// 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