@kiwicom/smart-faq
Version:
Smart FAQ
60 lines (52 loc) • 1.45 kB
JavaScript
// @flow
import * as React from 'react';
import Document, { Head, Main, NextScript } from 'next/document';
import { ServerStyleSheet } from 'styled-components';
import flush from 'styled-jsx/server';
type Context = {
renderPage(cb: Function): void,
req: Object,
};
export default class MyDocument extends Document {
static async getInitialProps(ctx: Context) {
const { renderPage, req } = ctx;
const sheet = new ServerStyleSheet();
const page = renderPage(App => props => {
return sheet.collectStyles(<App {...props} />);
});
const styles = flush();
const styledComponentsStyles = sheet.getStyleElement();
const uriWithoutLang = req.url.replace(/^\/[a-z]{2}/, '');
return {
...page,
styles,
styledComponentsStyles,
uriWithoutLang,
};
}
render() {
const { styledComponentsStyles, styles } = this.props;
return (
<html lang="en">
<Head>
<meta charSet="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
{styledComponentsStyles}
{styles}
<link
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700"
rel="stylesheet"
type="text/css"
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
);
}
}