|
| 1 | +'use strict' |
| 2 | +importPropTypesfrom'prop-types' |
| 3 | +importReact,{PureComponent}from'react' |
| 4 | +importserializefrom'serialize-javascript' |
| 5 | + |
| 6 | +//@twreporter |
| 7 | +importwebfontsfrom'@twreporter/react-components/lib/text/utils/webfonts' |
| 8 | +import{ |
| 9 | +colorGrayscale, |
| 10 | +colorBrand, |
| 11 | +}from'@twreporter/core/lib/constants/color' |
| 12 | + |
| 13 | +// lodash |
| 14 | +importmapfrom'lodash/map' |
| 15 | +const_={ |
| 16 | + map, |
| 17 | +} |
| 18 | + |
| 19 | +exportdefaultclassHtmlextendsPureComponent{ |
| 20 | +staticpropTypes={ |
| 21 | +scripts:PropTypes.array.isRequired, |
| 22 | +scriptElement:PropTypes.arrayOf(PropTypes.element).isRequired, |
| 23 | +styles:PropTypes.array.isRequired, |
| 24 | +contentMarkup:PropTypes.string.isRequired, |
| 25 | +store:PropTypes.object.isRequired, |
| 26 | +styleElement:PropTypes.arrayOf(PropTypes.element).isRequired, |
| 27 | +helmet:PropTypes.object.isRequired, |
| 28 | +} |
| 29 | +render(){ |
| 30 | +const{ |
| 31 | + contentMarkup, |
| 32 | + scripts, |
| 33 | + scriptElement, |
| 34 | + store, |
| 35 | + styleElement, |
| 36 | + styles, |
| 37 | + helmet, |
| 38 | +}=this.props |
| 39 | + |
| 40 | +return( |
| 41 | +<htmllang="zh-TW"> |
| 42 | +<head> |
| 43 | +<script |
| 44 | +async |
| 45 | +src="https://www.googleoptimize.com/optimize.js?id=OPT-NGNDMW8" |
| 46 | +/> |
| 47 | +{helmet.base.toComponent()} |
| 48 | +{helmet.title.toComponent()} |
| 49 | +{helmet.priority.toComponent()} |
| 50 | +{helmet.meta.toComponent()} |
| 51 | +{helmet.link.toComponent()} |
| 52 | +{helmet.script.toComponent()} |
| 53 | + |
| 54 | +<metacharSet="utf-8"/> |
| 55 | +<metahttpEquiv="x-ua-compatible"content="ie=edge"/> |
| 56 | +<metahttpEquiv="content-type"content="text/html; charSet=utf-8"/> |
| 57 | +<metahttpEquiv="Cache-control"content="public"/> |
| 58 | +<meta |
| 59 | +name="viewport" |
| 60 | +content="viewport-fit=cover, width=device-width, user-scalable=no, minimum-scale=1, initial-scale=1" |
| 61 | +/> |
| 62 | +<metaname="apple-mobile-web-app-capable"content="yes"/> |
| 63 | +<metaname="theme-color"content={colorGrayscale.gray100}/> |
| 64 | +<link |
| 65 | +rel="alternate" |
| 66 | +type="application/rss+xml" |
| 67 | +title="RSS 2.0" |
| 68 | +href="https://www.twreporter.org/a/rss2.xml" |
| 69 | +/> |
| 70 | +<linkrel="manifest"href="/meta/manifest.json"/> |
| 71 | +{/* Add to home screen for Safari on iOS */} |
| 72 | +<metaname="apple-mobile-web-app-capable"content="yes"/> |
| 73 | +<metaname="apple-mobile-web-app-status-bar-style"content="black"/> |
| 74 | +<meta |
| 75 | +name="apple-mobile-web-app-title" |
| 76 | +content="報導者 The Reporter" |
| 77 | +/> |
| 78 | +<link |
| 79 | +rel="apple-touch-icon" |
| 80 | +href="https://www.twreporter.org/images/apple-touch-icon-152x152.png" |
| 81 | +/> |
| 82 | +{/* Title icon for windows */} |
| 83 | +<meta |
| 84 | +name="msapplication-TileImage" |
| 85 | +content="https://www.twreporter.org/images/icon-normal.png" |
| 86 | +/> |
| 87 | +<metaname="msapplication-TileColor"content={colorBrand.main}/> |
| 88 | + |
| 89 | +<linkhref="/asset/favicon.png"rel="shortcut icon"/> |
| 90 | +<linkrel="stylesheet"href="/asset/normalize.css"/> |
| 91 | +{_.map(webfonts.fontGCSFiles,(fileSrc,key)=>( |
| 92 | +<link |
| 93 | +rel="preload" |
| 94 | +href={fileSrc} |
| 95 | +key={'webfont'+key} |
| 96 | +as="font" |
| 97 | +crossOrigin="anonymous" |
| 98 | +/> |
| 99 | +))} |
| 100 | +{_.map(styles,(stylesheet,key)=>( |
| 101 | +<link |
| 102 | +href={stylesheet} |
| 103 | +key={'stylesheet'+key} |
| 104 | +media="all" |
| 105 | +rel="stylesheet" |
| 106 | +type="text/css" |
| 107 | +charSet="UTF-8" |
| 108 | +/> |
| 109 | +))} |
| 110 | +{styleElement} |
| 111 | +</head> |
| 112 | +<body> |
| 113 | +<divid="root"dangerouslySetInnerHTML={{__html:contentMarkup}}/> |
| 114 | +<script |
| 115 | +defer |
| 116 | +src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.zh-Hant-TW" |
| 117 | +/> |
| 118 | +<script |
| 119 | +dangerouslySetInnerHTML={{ |
| 120 | +__html:`window.__REDUX_STATE__=${serialize(store.getState())};`, |
| 121 | +}} |
| 122 | +charSet="UTF-8" |
| 123 | +/> |
| 124 | +{_.map(scripts,(script,key)=>( |
| 125 | +<scriptsrc={script}key={'scripts'+key}charSet="UTF-8"/> |
| 126 | +))} |
| 127 | +{scriptElement} |
| 128 | +<script |
| 129 | +dangerouslySetInnerHTML={{ |
| 130 | +__html:`(function(d) { |
| 131 | + var config = { |
| 132 | + kitId: 'vlk1qbe', |
| 133 | + scriptTimeout: 3000, |
| 134 | + async: true |
| 135 | + }, |
| 136 | + 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) |
| 137 | + })(document); |
| 138 | + `, |
| 139 | +}} |
| 140 | +/> |
| 141 | +</body> |
| 142 | +</html> |
| 143 | +) |
| 144 | +} |
| 145 | +} |