Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Commit

Permalink
Added _document.js w/ support for a language prop
Browse files Browse the repository at this point in the history
This provides some support for issues rasied in #57 and #59.
  • Loading branch information
iaincollins committed Jan 6, 2018
1 parent 9113e61 commit 2117b6e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export default class extends React.Component {
// Expose session to all pages
static async getInitialProps({req}) {
return {
session: await Session.getSession({req})
session: await Session.getSession({req}),
lang: 'en'
}
}
}
28 changes: 28 additions & 0 deletions pages/_document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Document, { Head, Main, NextScript } from 'next/document'
import flush from 'styled-jsx/server'

export default class MyDocument extends Document {
static getInitialProps({ renderPage }) {
const { html, head, errorHtml, chunks } = renderPage()
const styles = flush()
return { html, head, errorHtml, chunks, styles }
}

render() {
/**
* Here we use _document.js to add a "lang" propery to the HTML object if
* one is set on the page.
**/
return (
<html lang={this.props.__NEXT_DATA__.props.lang || 'en'}>
<Head>
</Head>
<body>
{this.props.customValue}
<Main />
<NextScript />
</body>
</html>
)
}
}
3 changes: 3 additions & 0 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ now`}
<p>
For tips on configuring authentication see <a href="https://github.com/iaincollins/nextjs-starter/blob/master/AUTHENTICATION.md">AUTHENTICATION.md</a>
</p>
<p>
The next.js repository has a <a href="https://github.com/zeit/next.js/tree/master/examples">great selection of examples</a> which are excellent reference.
</p>
</Container>
</Layout>
)
Expand Down

0 comments on commit 2117b6e

Please sign in to comment.