_document.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import Document, {
  2. Html,
  3. Head,
  4. Main,
  5. NextScript,
  6. DocumentContext,
  7. DocumentInitialProps,
  8. } from "next/document";
  9. import { SeoTags } from "src/components/SeoTags";
  10. import { ServerStyleSheet } from "styled-components";
  11. class MyDocument extends Document {
  12. static async getInitialProps(
  13. ctx: DocumentContext
  14. ): Promise<DocumentInitialProps> {
  15. const sheet = new ServerStyleSheet();
  16. const originalRenderPage = ctx.renderPage;
  17. try {
  18. ctx.renderPage = () =>
  19. originalRenderPage({
  20. enhanceApp: (App) => (props) =>
  21. sheet.collectStyles(<App {...props} />),
  22. });
  23. const initialProps = await Document.getInitialProps(ctx);
  24. return {
  25. ...initialProps,
  26. styles: [initialProps.styles, sheet.getStyleElement()],
  27. };
  28. } finally {
  29. sheet.seal();
  30. }
  31. }
  32. render() {
  33. return (
  34. <Html lang="en">
  35. <Head>
  36. <SeoTags
  37. description="Simple visualization tool for your JSON data. No forced structure, paste your JSON and view it instantly."
  38. title="JSON Visio - Directly onto graphs"
  39. image="https://jsonvisio.com/jsonvisio.png"
  40. />
  41. <meta name="theme-color" content="#36393E" />
  42. <link rel="manifest" href="/manifest.json" />
  43. <link rel="icon" href="/favicon.ico" />
  44. <link rel="preconnect" href="https://fonts.googleapis.com" />
  45. <link
  46. rel="preconnect"
  47. href="https://fonts.gstatic.com"
  48. crossOrigin="anonymous"
  49. />
  50. <link
  51. href="https://fonts.googleapis.com/css2?family=Catamaran:wght@400;500;700&family=Roboto+Mono:wght@500&family=Roboto:wght@400;500;700&display=swap"
  52. rel="stylesheet"
  53. crossOrigin="anonymous"
  54. />
  55. </Head>
  56. <body>
  57. <Main />
  58. <NextScript />
  59. </body>
  60. </Html>
  61. );
  62. }
  63. }
  64. export default MyDocument;