2016-10-17 08:08:53 +00:00
|
|
|
import React from 'react'
|
2016-10-05 23:52:50 +00:00
|
|
|
import htmlescape from 'htmlescape'
|
2016-10-25 05:50:33 +00:00
|
|
|
import pkg from '../../package.json'
|
2016-10-05 23:52:50 +00:00
|
|
|
|
2016-10-28 14:38:24 +00:00
|
|
|
export default ({ head, css, html, data, dev, staticMarkup, cdn }) => {
|
2016-10-17 08:08:53 +00:00
|
|
|
return <html>
|
|
|
|
<head>
|
|
|
|
{(head || []).map((h, i) => React.cloneElement(h, { key: i }))}
|
2016-10-21 16:39:20 +00:00
|
|
|
<style dangerouslySetInnerHTML={{ __html: css }} />
|
2016-10-17 08:08:53 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} />
|
|
|
|
{staticMarkup ? null : <script dangerouslySetInnerHTML={{ __html: '__NEXT_DATA__ = ' + htmlescape(data) }} />}
|
2016-10-28 14:38:24 +00:00
|
|
|
{staticMarkup ? null : createClientScript({ dev, cdn })}
|
2016-10-17 08:08:53 +00:00
|
|
|
</body>
|
|
|
|
</html>
|
2016-10-05 23:52:50 +00:00
|
|
|
}
|
2016-10-28 14:38:24 +00:00
|
|
|
|
|
|
|
function createClientScript ({ dev, cdn }) {
|
|
|
|
if (dev) {
|
|
|
|
return <script type='text/javascript' src='/_next/next-dev.bundle.js' />
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cdn) {
|
|
|
|
return <script type='text/javascript' src='/_next/next.bundle.js' />
|
|
|
|
}
|
|
|
|
|
|
|
|
return <script dangerouslySetInnerHTML={{ __html: `
|
|
|
|
(function () {
|
|
|
|
load('https://cdn.zeit.co/next.js/${pkg.version}/next.min.js', function (err) {
|
|
|
|
if (err) load('/_next/next.bundle.js')
|
|
|
|
})
|
|
|
|
|
|
|
|
function load (src, fn) {
|
|
|
|
fn = fn || function () {}
|
|
|
|
var script = document.createElement('script')
|
|
|
|
script.src = src
|
|
|
|
script.onload = function () { fn(null) }
|
|
|
|
script.onerror = fn
|
|
|
|
script.crossorigin = 'anonymous'
|
|
|
|
document.head.appendChild(script)
|
|
|
|
}
|
|
|
|
})()
|
|
|
|
`}} />
|
|
|
|
}
|