UNPKG

react-static

Version:

A progressive static site generator for React

65 lines (62 loc) 1.55 kB
import axios from 'axios' import React, { Component } from 'react' import { ServerStyleSheet } from 'styled-components' export default { getSiteData: () => ({ title: 'React Static', }), getRoutes: async () => { const { data: posts } = await axios.get('https://jsonplaceholder.typicode.com/posts') return [ { path: '/', component: 'src/containers/Home', }, { path: '/about', component: 'src/containers/About', }, { path: '/blog', component: 'src/containers/Blog', getData: () => ({ posts, }), children: posts.map(post => ({ path: `/post/${post.id}`, component: 'src/containers/Post', getData: () => ({ post, }), })), }, { is404: true, component: 'src/containers/404', }, ] }, renderToHtml: (render, Comp, meta) => { const sheet = new ServerStyleSheet() const html = render(sheet.collectStyles(<Comp />)) meta.styleTags = sheet.getStyleElement() return html }, Document: class CustomHtml extends Component { render () { const { Html, Head, Body, children, renderMeta, } = this.props return ( <Html> <Head> <meta charSet="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> {renderMeta.styleTags} </Head> <Body>{children}</Body> </Html> ) } }, }