Skip to content

Instantly share code, notes, and snippets.

View astrotim's full-sized avatar

Tim Holt astrotim

View GitHub Profile
@astrotim
astrotim / Post.js
Created December 29, 2017 00:56
retrieve entry data per post id
import React from 'react';
import { createClient } from 'contentful';
class Post extends React.Component {
constructor(props) {
super(props);
this.state = {
data: null
};
@astrotim
astrotim / Post.js.diff
Last active December 29, 2017 11:20
update Post.js to render content
render() {
- console.log(this.state.data);
- return <p>Post</p>;
+ if (!this.state.data) return null;
+
+ return (
+ <React.Fragment>
+ <h1>{this.state.data.title}</h1>
+ {this.state.data.content}
+ </React.Fragment>
@astrotim
astrotim / Post.js.diff
Last active December 29, 2017 11:21
added page title with react-helmet
import React from 'react';
import { createClient } from 'contentful';
+import Helmet from 'react-helmet';
return (
<React.Fragment>
+ <Helmet title={this.state.data.title} />
<h1>{this.state.data.title}</h1>
{this.state.data.content}
</React.Fragment>
@astrotim
astrotim / Post.js.diff
Last active December 29, 2017 01:48
added Markdown support to Post.js
-import React from 'react';
+import React, { createElement } from 'react';
import { createClient } from 'contentful';
import Helmet from 'react-helmet';
+import marksy from 'marksy';
+
+// Markdown helper function
+const getMarkup = field => {
+ if (!field) return null;
+ const compile = marksy({