rickvanlieshout.com/html.js

53 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-03-11 23:28:19 +01:00
import React from 'react'
import DocumentTitle from 'react-document-title'
2016-06-03 01:32:38 +02:00
import { prefixLink } from 'gatsby-helpers'
const BUILD_TIME = new Date().getTime()
2016-03-11 23:28:19 +01:00
module.exports = React.createClass({
2016-06-03 01:32:38 +02:00
displayName: 'HTML',
propTypes: {
body: React.PropTypes.string,
2016-03-21 18:03:01 +01:00
},
render() {
2016-06-03 01:32:38 +02:00
const {body, route} = this.props
const title = DocumentTitle.rewind()
2016-03-11 23:28:19 +01:00
2016-06-03 01:32:38 +02:00
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
2016-03-21 18:03:01 +01:00
if (process.env.NODE_ENV === 'production') {
2016-06-03 01:32:38 +02:00
css = <style dangerouslySetInnerHTML={ { __html: require('!raw!postcss!./public/styles.css')} } />
2016-03-21 18:03:01 +01:00
}
2016-03-11 23:28:19 +01:00
2016-03-21 18:03:01 +01:00
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
2016-06-03 01:32:38 +02:00
<meta name="viewport" content="width=device-width, initial-scale=1.0 maximum-scale=5.0" />
2016-03-21 18:03:01 +01:00
<title>
{ title }
</title>
</head>
<body>
<div id="react-mount" dangerouslySetInnerHTML={ { __html: this.props.body} } />
2016-06-03 01:32:38 +02:00
<script dangerouslySetInnerHTML={ { __html: font} } />
{ css }
<script src={ prefixLink(`/bundle.js?t=${BUILD_TIME}`) } />
2016-03-21 18:03:01 +01:00
</body>
</html>
)
},
2016-06-03 01:32:38 +02:00
})