48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import React from "react";
|
|
import Document, {
|
|
Html, Head, Main, NextScript, DocumentContext, DocumentInitialProps,
|
|
} from "next/document";
|
|
import { ServerStyleSheet } from "styled-components";
|
|
import Favicons from "@components/Favicons";
|
|
|
|
export default class MyDocument extends Document<{ styleTags: unknown }> {
|
|
static getInitialProps = async (ctx: DocumentContext): Promise<DocumentInitialProps> => {
|
|
const sheet = new ServerStyleSheet();
|
|
const originalRenderPage = ctx.renderPage;
|
|
try {
|
|
ctx.renderPage = () => originalRenderPage({
|
|
enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />),
|
|
});
|
|
const initialProps = await Document.getInitialProps(ctx);
|
|
return {
|
|
...initialProps,
|
|
styles: (
|
|
<>
|
|
{initialProps.styles}
|
|
{sheet.getStyleElement()}
|
|
</>
|
|
),
|
|
};
|
|
} finally {
|
|
sheet.seal();
|
|
}
|
|
};
|
|
|
|
render(): JSX.Element {
|
|
const { styleTags } = this.props;
|
|
return (
|
|
<Html lang="fi">
|
|
<Head>
|
|
<link href="https://fonts.googleapis.com/css?family=Montserrat:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,800,900&display=swap" rel="stylesheet" />
|
|
<Favicons />
|
|
</Head>
|
|
<body>
|
|
{styleTags}
|
|
<Main />
|
|
<NextScript />
|
|
</body>
|
|
</Html>
|
|
);
|
|
}
|
|
}
|