portfolio/pages/_document.tsx

61 lines
2.0 KiB
TypeScript

import Document, { DocumentContext, DocumentInitialProps, Head, Html, Main, NextScript } from 'next/document'
import { ServerStyleSheet } from 'styled-components'
import config from '../config'
export default class MyDocument extends Document {
static async getInitialProps(
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() {
return (
<Html>
<Head>
{/* Add the favicon */}
<link rel="shortcut icon" href="/favicon.svg" />
{/* Add `Open Sans` font */}
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans&display=optional"
rel="stylesheet"
/>
{/* HTML Meta tags */}
<meta name="description" content={config.description} />
{/* OpenGraph card */}
<meta property="og:url" content={config.url} />
<meta property="og:type" content="website" />
<meta property="og:title" content={config.title} />
<meta property="og:description" content={config.description} />
<meta property="og:image" content={config.thumbnail} />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}