Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions build/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const mkdirp = require('mkdirp')
const { createElement } = require('react')
const { renderToStaticMarkup } = require('react-dom/server')
const requireDirectory = require('require-directory')
const { Helmet } = require('react-helmet')

console.time('Build html total')

Expand All @@ -28,12 +29,27 @@ requireDirectory(module, '../pages', {
pages: data.pages
}
const Component = require(filePath).default
const html = `<!doctype html>
${renderToStaticMarkup(createElement(Component, props))}`

const appHtml = renderToStaticMarkup(createElement(Component, props))
const helmet = Helmet.renderStatic()
const docHtml = `<!doctype html>
<html ${helmet.htmlAttributes.toString()}>
<head>
${helmet.title.toString()}
${helmet.meta.toString()}
${helmet.link.toString()}
</head>
<body ${helmet.bodyAttributes.toString()}>
<div id="react-root">
${appHtml}
</div>
</body>
</html>`

const subdir = name === 'home' ? '.' : name
const outFile = path.join(outputDir, subdir, 'index.html')
mkdirp.sync(path.dirname(outFile))
fs.writeFileSync(outFile, html)
fs.writeFileSync(outFile, docHtml)
console.timeEnd(`Build ${name}`)
}
})
Expand Down
37 changes: 36 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"postcss-import": "^11.0.0",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-helmet": "^5.2.0",
"react-markdown": "^2.5.0",
"react-responsive-embed": "^2.1.0",
"require-directory": "^2.1.1",
Expand Down Expand Up @@ -51,4 +52,4 @@
"IE >= 9",
"last 4 versions"
]
}
}
15 changes: 7 additions & 8 deletions pages/layout.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Helmet } from 'react-helmet'
import HelplineBox from '../components/helpline-box'

const Header = ({relativePathToRoot}) => (
Expand All @@ -14,21 +15,19 @@ const Header = ({relativePathToRoot}) => (
)

const Layout = ({ content, facts, children }) => (
<html>
<head>
<div className='sans-serif'>
<Helmet>
<meta charSet='UTF-8' />
<meta httpEquiv='x-ua-compatible' content='ie=edge' />
<meta name='viewport' content='width=device-width, initial-scale=1' />
<meta name='description' content={facts.description} />
<meta name='keywords' content={facts.keywords} />
<title>{facts.title}</title>
<link rel='stylesheet' href={`${content.meta.relativePathToRoot}/bundle.css`} />
</head>
<body className='sans-serif'>
<Header relativePathToRoot={content.meta.relativePathToRoot} />
{children}
</body>
</html>
</Helmet>
<Header relativePathToRoot={content.meta.relativePathToRoot} />
{children}
</div>
)

Layout.propTypes = {
Expand Down