_document.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { createCache, StyleProvider } from '@ant-design/cssinjs';
  2. import Document, { DocumentContext, Head, Html, Main, NextScript } from 'next/document';
  3. import { doExtraStyle } from '../genAntdCss';
  4. class MyDocument extends Document {
  5. static async getInitialProps(ctx: DocumentContext) {
  6. const cache = createCache();
  7. let fileName = '';
  8. const originalRenderPage = ctx.renderPage;
  9. ctx.renderPage = () =>
  10. originalRenderPage({
  11. enhanceApp: App => props => (
  12. <StyleProvider cache={cache} hashPriority='high'>
  13. <App {...props} />
  14. </StyleProvider>
  15. ),
  16. });
  17. const initialProps = await Document.getInitialProps(ctx);
  18. fileName = doExtraStyle({
  19. cache,
  20. });
  21. return {
  22. ...initialProps,
  23. styles: (
  24. <>
  25. {initialProps.styles}
  26. {/* 1.2 inject css */}
  27. {fileName && <link rel='stylesheet' href={`/${fileName}`} />}
  28. </>
  29. ),
  30. };
  31. }
  32. render() {
  33. return (
  34. <Html lang='en'>
  35. <Head>
  36. <link rel='icon' href='/favicon.ico' />
  37. <meta name='description' content='Revolutionizing Database Interactions with Private LLM Technology' />
  38. <meta property='og:description' content='eosphoros-ai' />
  39. <meta property='og:title' content='DB-GPT' />
  40. </Head>
  41. <body>
  42. <Main />
  43. <NextScript />
  44. </body>
  45. </Html>
  46. );
  47. }
  48. }
  49. export default MyDocument;