2016-10-05 23:52:50 +00:00
|
|
|
import React, { Component, PropTypes } from 'react'
|
|
|
|
import htmlescape from 'htmlescape'
|
|
|
|
|
|
|
|
export default class Document extends Component {
|
|
|
|
static childContextTypes = {
|
|
|
|
_documentProps: PropTypes.any
|
|
|
|
}
|
|
|
|
|
|
|
|
getChildContext () {
|
|
|
|
return {
|
|
|
|
_documentProps: this.props
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return <html>
|
|
|
|
<Head/>
|
|
|
|
<body>
|
|
|
|
<Main/>
|
|
|
|
<DevTools/>
|
|
|
|
<NextScript/>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function Head (props, context) {
|
2016-10-06 02:42:55 +00:00
|
|
|
const { head, css } = context._documentProps
|
2016-10-05 23:52:50 +00:00
|
|
|
const h = (head || [])
|
|
|
|
.map((h, i) => React.cloneElement(h, { key: '_next' + i }))
|
2016-10-06 02:42:55 +00:00
|
|
|
return <head>
|
|
|
|
{h}
|
2016-10-09 09:50:41 +00:00
|
|
|
<style data-aphrodite dangerouslySetInnerHTML={{ __html: css.content }} />
|
2016-10-06 02:42:55 +00:00
|
|
|
</head>
|
2016-10-05 23:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Head.contextTypes = { _documentProps: PropTypes.any }
|
|
|
|
|
|
|
|
export function Main (props, context) {
|
2016-10-10 04:24:30 +00:00
|
|
|
const { html, data, staticMarkup } = context._documentProps;
|
2016-10-05 23:52:50 +00:00
|
|
|
return <div>
|
|
|
|
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} />
|
2016-10-10 04:24:30 +00:00
|
|
|
{staticMarkup ? null : <script dangerouslySetInnerHTML={{ __html: '__NEXT_DATA__ = ' + htmlescape(data) }} />}
|
2016-10-05 23:52:50 +00:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
|
|
|
|
Main.contextTypes = { _documentProps: PropTypes.any }
|
|
|
|
|
|
|
|
export function DevTools (props, context) {
|
|
|
|
const { hotReload } = context._documentProps
|
|
|
|
return hotReload ? <div id='__next-hot-code-reloading-indicator'/> : null
|
|
|
|
}
|
|
|
|
|
|
|
|
DevTools.contextTypes = { _documentProps: PropTypes.any }
|
|
|
|
|
|
|
|
export function NextScript (props, context) {
|
2016-10-10 04:24:30 +00:00
|
|
|
const { dev, staticMarkup } = context._documentProps;
|
|
|
|
if (staticMarkup) return null
|
2016-10-06 11:05:52 +00:00
|
|
|
const src = !dev ? '/_next/next.bundle.js' : '/_next/next-dev.bundle.js'
|
2016-10-05 23:52:50 +00:00
|
|
|
return <script type='text/javascript' src={src}/>
|
|
|
|
}
|
|
|
|
|
|
|
|
NextScript.contextTypes = { _documentProps: PropTypes.any }
|