You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_document.tsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import NextDocument, {
  2. Html,
  3. Head,
  4. Main,
  5. NextScript,
  6. DocumentContext,
  7. } from 'next/document'
  8. import { dark, getCssString } from 'styles'
  9. import { GA_TRACKING_ID } from 'utils/gtag'
  10. class MyDocument extends NextDocument {
  11. static async getInitialProps(ctx: DocumentContext): Promise<{
  12. styles: JSX.Element
  13. html: string
  14. head?: JSX.Element[]
  15. }> {
  16. try {
  17. const initialProps = await NextDocument.getInitialProps(ctx)
  18. return {
  19. ...initialProps,
  20. styles: (
  21. <>
  22. {initialProps.styles}
  23. <style
  24. id="stitches"
  25. dangerouslySetInnerHTML={{ __html: getCssString() }}
  26. />
  27. </>
  28. ),
  29. }
  30. } catch (e) {
  31. console.error(e.message)
  32. } finally {
  33. null
  34. }
  35. }
  36. render(): JSX.Element {
  37. const APP_NAME = 'tldraw'
  38. const APP_DESCRIPTION = 'A tiny little drawing app.'
  39. const APP_URL = 'https://tldraw.com'
  40. return (
  41. <Html lang="en">
  42. <Head>
  43. <meta name="application-name" content={APP_NAME} />
  44. <meta name="apple-mobile-web-app-capable" content="yes" />
  45. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  46. <meta name="apple-mobile-web-app-title" content={APP_NAME} />
  47. <meta name="description" content={APP_DESCRIPTION} />
  48. <meta name="format-detection" content="telephone=no" />
  49. <meta name="mobile-web-app-capable" content="yes" />
  50. <meta name="theme-color" content="#fafafa" />
  51. <meta name="twitter:card" content="summary" />
  52. <meta name="twitter:url" content={APP_URL} />
  53. <meta name="twitter:title" content={APP_NAME} />
  54. <meta name="twitter:description" content={APP_DESCRIPTION} />
  55. <meta name="twitter:creator" content="@steveruizok" />
  56. <meta property="og:type" content="website" />
  57. <meta property="og:title" content={APP_NAME} />
  58. <meta property="og:description" content={APP_DESCRIPTION} />
  59. <meta property="og:site_name" content={APP_NAME} />
  60. <meta property="og:url" content={APP_URL} />
  61. <link rel="manifest" href="/manifest.json" />
  62. <link rel="shortcut icon" href="/favicon.ico" />
  63. <link
  64. rel="apple-touch-icon"
  65. sizes="180x180"
  66. href="/icons/apple-touch-icon.png"
  67. />
  68. <script
  69. async
  70. src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`}
  71. />
  72. <script
  73. dangerouslySetInnerHTML={{
  74. __html: `
  75. window.dataLayer = window.dataLayer || [];
  76. function gtag(){dataLayer.push(arguments);}
  77. gtag('js', new Date());
  78. gtag('config', '${GA_TRACKING_ID}', {
  79. page_path: window.location.pathname,
  80. });
  81. `,
  82. }}
  83. />
  84. </Head>
  85. <body className={dark}>
  86. <Main />
  87. <NextScript />
  88. </body>
  89. </Html>
  90. )
  91. }
  92. }
  93. export default MyDocument