Template for starting apps, powered by Next.js
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.
 
 

62 lines
1.5 KiB

  1. import Document, {Html, Head, Main, NextScript} from 'next/document'
  2. import {ServerStyleSheet} from 'styled-components'
  3. import pkg from '../../package.json'
  4. import config from '../../next.config'
  5. const publicUrl = process.env.NODE_ENV === 'production' ? pkg.homepage : config.basePath
  6. export default class MyDocument extends Document {
  7. static async getInitialProps(ctx) {
  8. const sheet = new ServerStyleSheet()
  9. const originalRenderPage = ctx.renderPage
  10. try {
  11. ctx.renderPage = () =>
  12. originalRenderPage({
  13. enhanceApp: (App) => (props) =>
  14. sheet.collectStyles(
  15. <App
  16. {...props}
  17. />,
  18. ),
  19. })
  20. const initialProps = await Document.getInitialProps(ctx)
  21. return {
  22. ...initialProps,
  23. styles: (
  24. <>
  25. {initialProps.styles}
  26. <link rel="preconnect" href="https://fonts.gstatic.com" />
  27. <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Encode+Sans:wdth,wght@75..112.5,100..900&display=swap" />
  28. <link rel="stylesheet" href={`${publicUrl}/global.css`} />
  29. <link rel="stylesheet" href={`${publicUrl}/theme.css`} />
  30. <link rel="stylesheet" title="Dark" href={`${publicUrl}/theme/dark.css`} />
  31. <link rel="alternate stylesheet" title="Light" href={`${publicUrl}/theme/light.css`} />
  32. {sheet.getStyleElement()}
  33. </>
  34. ),
  35. }
  36. } catch (err) {
  37. console.error(err)
  38. } finally {
  39. sheet.seal()
  40. }
  41. }
  42. render() {
  43. return (
  44. <Html
  45. lang="en-PH"
  46. >
  47. <Head />
  48. <body>
  49. <Main />
  50. <NextScript />
  51. </body>
  52. </Html>
  53. )
  54. }
  55. }