forked from codelion/example-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml.js
More file actions
145 lines (139 loc) · 4.97 KB
/
html.js
File metadata and controls
145 lines (139 loc) · 4.97 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'use strict'
import PropTypes from 'prop-types'
import React, { PureComponent } from 'react'
import serialize from 'serialize-javascript'
// @twreporter
import webfonts from '@twreporter/react-components/lib/text/utils/webfonts'
import {
colorGrayscale,
colorBrand,
} from '@twreporter/core/lib/constants/color'
// lodash
import map from 'lodash/map'
const _ = {
map,
}
export default class Html extends PureComponent {
static propTypes = {
scripts: PropTypes.array.isRequired,
scriptElement: PropTypes.arrayOf(PropTypes.element).isRequired,
styles: PropTypes.array.isRequired,
contentMarkup: PropTypes.string.isRequired,
store: PropTypes.object.isRequired,
styleElement: PropTypes.arrayOf(PropTypes.element).isRequired,
helmet: PropTypes.object.isRequired,
}
render() {
const {
contentMarkup,
scripts,
scriptElement,
store,
styleElement,
styles,
helmet,
} = this.props
return (
<html lang="zh-TW">
<head>
<script
async
src="https://www.googleoptimize.com/optimize.js?id=OPT-NGNDMW8"
/>
{helmet.base.toComponent()}
{helmet.title.toComponent()}
{helmet.priority.toComponent()}
{helmet.meta.toComponent()}
{helmet.link.toComponent()}
{helmet.script.toComponent()}
<meta charSet="utf-8" />
<meta httpEquiv="x-ua-compatible" content="ie=edge" />
<meta httpEquiv="content-type" content="text/html; charSet=utf-8" />
<meta httpEquiv="Cache-control" content="public" />
<meta
name="viewport"
content="viewport-fit=cover, width=device-width, user-scalable=no, minimum-scale=1, initial-scale=1"
/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="theme-color" content={colorGrayscale.gray100} />
<link
rel="alternate"
type="application/rss+xml"
title="RSS 2.0"
href="https://www.twreporter.org/a/rss2.xml"
/>
<link rel="manifest" href="/meta/manifest.json" />
{/* Add to home screen for Safari on iOS */}
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta
name="apple-mobile-web-app-title"
content="報導者 The Reporter"
/>
<link
rel="apple-touch-icon"
href="https://www.twreporter.org/images/apple-touch-icon-152x152.png"
/>
{/* Title icon for windows */}
<meta
name="msapplication-TileImage"
content="https://www.twreporter.org/images/icon-normal.png"
/>
<meta name="msapplication-TileColor" content={colorBrand.main} />
<link href="/asset/favicon.png" rel="shortcut icon" />
<link rel="stylesheet" href="/asset/normalize.css" />
{_.map(webfonts.fontGCSFiles, (fileSrc, key) => (
<link
rel="preload"
href={fileSrc}
key={'webfont' + key}
as="font"
crossOrigin="anonymous"
/>
))}
{_.map(styles, (stylesheet, key) => (
<link
href={stylesheet}
key={'stylesheet' + key}
media="all"
rel="stylesheet"
type="text/css"
charSet="UTF-8"
/>
))}
{styleElement}
</head>
<body>
<div id="root" dangerouslySetInnerHTML={{ __html: contentMarkup }} />
<script
defer
src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.zh-Hant-TW"
/>
<script
dangerouslySetInnerHTML={{
__html: `window.__REDUX_STATE__=${serialize(store.getState())};`,
}}
charSet="UTF-8"
/>
{_.map(scripts, (script, key) => (
<script src={script} key={'scripts' + key} charSet="UTF-8" />
))}
{scriptElement}
<script
dangerouslySetInnerHTML={{
__html: `(function(d) {
var config = {
kitId: 'vlk1qbe',
scriptTimeout: 3000,
async: true
},
h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+" wf-inactive";},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+=" wf-loading";tk.src='https://use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)
})(document);
`,
}}
/>
</body>
</html>
)
}
}