rickvanlieshout.com/html.js
2016-06-03 02:32:38 +03:00

53 lines
1.9 KiB
JavaScript

import React from 'react'
import DocumentTitle from 'react-document-title'
import { prefixLink } from 'gatsby-helpers'
const BUILD_TIME = new Date().getTime()
module.exports = React.createClass({
displayName: 'HTML',
propTypes: {
body: React.PropTypes.string,
},
render() {
const {body, route} = this.props
const title = DocumentTitle.rewind()
const font = `
WebFontConfig = {
google: { families: [ 'Roboto:400,500,700:latin,cyrillic' ] }
};
(function() {
var wf = document.createElement('script');
wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
`
let css
if (process.env.NODE_ENV === 'production') {
css = <style dangerouslySetInnerHTML={ { __html: require('!raw!postcss!./public/styles.css')} } />
}
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0 maximum-scale=5.0" />
<title>
{ title }
</title>
</head>
<body>
<div id="react-mount" dangerouslySetInnerHTML={ { __html: this.props.body} } />
<script dangerouslySetInnerHTML={ { __html: font} } />
{ css }
<script src={ prefixLink(`/bundle.js?t=${BUILD_TIME}`) } />
</body>
</html>
)
},
})