create-react-app
in 10 lines of codeIf you're using create-react-app - we can create a Markdown (Jekyll style) blog in 10 lines of code.
_posts
directory)npm install -g create-react-app@1.4.3
create-react-app react-blog
cd react-blog
npm install --save --save-exact react-scripts@1.0.17
npm install --save react-router@3.2.0 markdown-with-front-matter-loader@0.1.0 github-markdown-css@2.9.0
npm start
// eslint-disable-next-line import/no-webpack-loader-syntax
const webpackRequireContext = require.context('!markdown-with-front-matter-loader!./_posts', false, /.md$/);
const blogs = webpackRequireContext.keys().reduce((memo, fileName) => memo.set(fileName.match(/.\/([^.]+).*/)[1], webpackRequireContext(fileName)), new Map())
// eslint-disable-next-line import/first
import 'github-markdown-css';
const blogIndex = (blogs) => () => <ul>{[...blogs.keys()].map(path => <li key={path}><Link to={'/'+path}>{blogs.get(path).title || path}</Link></li>)}</ul>;
const blogWrapper = ({ __content }) => () => <div><Link to='/'>« Back to blog</Link><hr /><div className='markdown-body' dangerouslySetInnerHTML={{__html: __content}}></div></div>;
// eslint-disable-next-line import/first
import { Link, IndexRoute, Router, Route, browserHistory } from 'react-router';
const reactRoutes = [<IndexRoute key='index' component={blogIndex(blogs)} />].concat([...blogs.keys()].map(path => <Route key={path} path={path} component={blogWrapper(blogs.get(path))} />));
react-router
config<Route path="/">{reactRoutes}</Route>
ReactDOM.render(
<Router history={browserHistory}>
<Route path="/">{reactRoutes}</Route>
</Router>,
document.getElementById('root')
);
_posts
directory and write a blog post in Markdownget it here: https://github.com/sanfrancesco/create-react-app-blog