-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml.js
123 lines (114 loc) · 3.98 KB
/
html.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import React from 'react';
import PropTypes from 'prop-types';
import { Helmet } from 'react-helmet';
import { prefixLink } from 'gatsby-helpers';
import styleSheet from 'styled-components/lib/models/StyleSheet';
const BUILD_TIME = new Date().getTime();
class Html extends React.Component {
static displayName = 'HTML';
static propTypes = {
body: PropTypes.string
};
static defaultProps = {
body: null
};
render() {
const { body } = this.props;
const helmet = Helmet.rewind();
let bootstrap;
if (process.env.NODE_ENV === 'production') {
bootstrap = (
<style
dangerouslySetInnerHTML={{
__html: require('!raw!./public/styles.css')
}}
/>
);
}
let styledComponents;
if (process.env.NODE_ENV === 'production') {
const styles = styleSheet
.rules()
.map(rule => rule.cssText)
.join('\n');
styledComponents = (
<style dangerouslySetInnerHTML={{ __html: styles }} />
);
}
let serviceWorker;
if (process.env.NODE_ENV === 'production') {
serviceWorker = (
<script
type="text/javascript"
dangerouslySetInnerHTML={{
__html: `
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register(
'/service-worker.js'
);
}
`
}}
/>
);
}
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"
/>
{helmet.title.toComponent()}
{helmet.meta.toComponent()}
<link
rel="apple-touch-icon"
sizes="180x180"
href="/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicon-16x16.png"
/>
<link rel="manifest" href="/manifest.json" />
<link
rel="mask-icon"
href="/safari-pinned-tab.svg"
color="#2b5797"
/>
<meta
name="apple-mobile-web-app-title"
content="Adam Krogh"
/>
<meta name="application-name" content="Adam Krogh" />
<meta name="theme-color" content="#ffffff" />
<link
href="https://fonts.googleapis.com/css?family=Raleway"
rel="stylesheet"
/>
{bootstrap}
{styledComponents}
</head>
<body>
<div
id="react-mount"
dangerouslySetInnerHTML={{ __html: this.props.body }}
/>
<script src={prefixLink(`/bundle.js?t=${BUILD_TIME}`)} />
{serviceWorker}
</body>
</html>
);
}
}
export default Html;