mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
document: refactoring
This commit is contained in:
parent
0544c247bb
commit
60aa5869e4
|
@ -1,63 +1,16 @@
|
||||||
import React, { Component, PropTypes } from 'react'
|
import React from 'react'
|
||||||
import htmlescape from 'htmlescape'
|
import htmlescape from 'htmlescape'
|
||||||
|
|
||||||
export default class Document extends Component {
|
export default ({ head, css, html, data, dev, staticMarkup }) => {
|
||||||
static childContextTypes = {
|
return <html>
|
||||||
_documentProps: PropTypes.any
|
<head>
|
||||||
}
|
{(head || []).map((h, i) => React.cloneElement(h, { key: i }))}
|
||||||
|
<style data-aphrodite='' dangerouslySetInnerHTML={{ __html: css.content }} />
|
||||||
getChildContext () {
|
</head>
|
||||||
return {
|
<body>
|
||||||
_documentProps: this.props
|
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} />
|
||||||
}
|
{staticMarkup ? null : <script dangerouslySetInnerHTML={{ __html: '__NEXT_DATA__ = ' + htmlescape(data) }} />}
|
||||||
}
|
{staticMarkup ? null : <script type='text/javascript' src={dev ? '/_next/next-dev.bundle.js' : '/_next/next.bundle.js'} />}
|
||||||
|
</body>
|
||||||
render () {
|
</html>
|
||||||
return <html>
|
|
||||||
<Head />
|
|
||||||
<body>
|
|
||||||
<Main />
|
|
||||||
<DevTools />
|
|
||||||
<NextScript />
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Head (props, context) {
|
|
||||||
const { head, css } = context._documentProps
|
|
||||||
const h = (head || [])
|
|
||||||
.map((h, i) => React.cloneElement(h, { key: '_next' + i }))
|
|
||||||
return <head>
|
|
||||||
{h}
|
|
||||||
<style data-aphrodite='' dangerouslySetInnerHTML={{ __html: css.content }} />
|
|
||||||
</head>
|
|
||||||
}
|
|
||||||
|
|
||||||
Head.contextTypes = { _documentProps: PropTypes.any }
|
|
||||||
|
|
||||||
export function Main (props, context) {
|
|
||||||
const { html, data, staticMarkup } = context._documentProps
|
|
||||||
return <div>
|
|
||||||
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} />
|
|
||||||
{staticMarkup ? null : <script dangerouslySetInnerHTML={{ __html: '__NEXT_DATA__ = ' + htmlescape(data) }} />}
|
|
||||||
</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) {
|
|
||||||
const { dev, staticMarkup } = context._documentProps
|
|
||||||
if (staticMarkup) return null
|
|
||||||
const src = !dev ? '/_next/next.bundle.js' : '/_next/next-dev.bundle.js'
|
|
||||||
return <script type='text/javascript' src={src} />
|
|
||||||
}
|
|
||||||
|
|
||||||
NextScript.contextTypes = { _documentProps: PropTypes.any }
|
|
||||||
|
|
Loading…
Reference in a new issue