_document.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import Document, { Head, Main, NextScript } from "next/document";
  2. import { ServerStyleSheet } from "styled-components";
  3. import getConfig from "next/config";
  4. import React from "react";
  5. import { Colors } from "../consts";
  6. const { publicRuntimeConfig } = getConfig();
  7. interface Props {
  8. styleTags: any;
  9. }
  10. class AppDocument extends Document<Props> {
  11. static async getInitialProps(ctx) {
  12. const initialProps = await Document.getInitialProps(ctx);
  13. const sheet = new ServerStyleSheet();
  14. const page = ctx.renderPage(
  15. (App) => (props) => sheet.collectStyles(<App {...props} />)
  16. );
  17. const styleTags = sheet.getStyleElement();
  18. return { ...initialProps, ...page, styleTags };
  19. }
  20. render() {
  21. return (
  22. <html lang="en">
  23. <Head>
  24. <meta charSet="utf-8" />
  25. <meta
  26. name="viewport"
  27. content="width=device-width, initial-scale=1, viewport-fit=cover"
  28. />
  29. <meta
  30. name="description"
  31. content={`${publicRuntimeConfig.SITE_NAME} is a free and open source URL shortener with custom domains and stats.`}
  32. />
  33. <link
  34. href="https://fonts.googleapis.com/css?family=Nunito:300,400,700&display=optional"
  35. rel="stylesheet"
  36. />
  37. <link rel="icon" sizes="196x196" href="/images/favicon-196x196.png" />
  38. <link rel="icon" sizes="32x32" href="/images/favicon-32x32.png" />
  39. <link rel="icon" sizes="16x16" href="/images/favicon-16x16.png" />
  40. <link rel="apple-touch-icon" href="/images/favicon-196x196.png" />
  41. <link rel="mask-icon" href="/images/icon.svg" color="blue" />
  42. <link rel="manifest" href="manifest.webmanifest" />
  43. <meta name="theme-color" content="#f3f3f3" />
  44. <meta property="fb:app_id" content="123456789" />
  45. <meta
  46. property="og:url"
  47. content={`https://${publicRuntimeConfig.DEFAULT_DOMAIN}`}
  48. />
  49. <meta property="og:type" content="website" />
  50. <meta property="og:title" content={publicRuntimeConfig.SITE_NAME} />
  51. <meta
  52. property="og:image"
  53. content={`https://${publicRuntimeConfig.DEFAULT_DOMAIN}/images/card.png`}
  54. />
  55. <meta
  56. property="og:description"
  57. content="Free & Open Source Modern URL Shortener"
  58. />
  59. <meta
  60. name="twitter:url"
  61. content={`https://${publicRuntimeConfig.DEFAULT_DOMAIN}`}
  62. />
  63. <meta name="twitter:title" content={publicRuntimeConfig.SITE_NAME} />
  64. <meta
  65. name="twitter:description"
  66. content="Free & Open Source Modern URL Shortener"
  67. />
  68. <meta
  69. name="twitter:image"
  70. content={`https://${publicRuntimeConfig.DEFAULT_DOMAIN}/images/card.png`}
  71. />
  72. {this.props.styleTags}
  73. <script
  74. dangerouslySetInnerHTML={{
  75. __html: `window.recaptchaCallback = function() { window.isCaptchaReady = true; }`
  76. }}
  77. />
  78. <script
  79. src="https://www.google.com/recaptcha/api.js?render=explicit"
  80. async
  81. defer
  82. />
  83. </Head>
  84. <body
  85. style={{
  86. margin: 0,
  87. backgroundColor: Colors.Bg,
  88. font: '16px/1.45 "Nunito", sans-serif',
  89. overflowX: "hidden",
  90. color: Colors.Text
  91. }}
  92. >
  93. <Main />
  94. <NextScript />
  95. </body>
  96. </html>
  97. );
  98. }
  99. }
  100. export default AppDocument;