_app.page.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React, { ReactElement, ReactNode, useEffect } from 'react';
  2. import { NextPage } from 'next';
  3. import { appWithTranslation } from 'next-i18next';
  4. import { AppProps } from 'next/app';
  5. import { Lato } from 'next/font/google';
  6. import localFont from 'next/font/local';
  7. import { SWRConfig } from 'swr';
  8. import * as nextI18nConfig from '^/config/next-i18next.config';
  9. import { useI18nextHMR } from '~/services/i18next-hmr';
  10. import {
  11. useAppTitle, useConfidential, useGrowiVersion, useSiteUrl, useIsDefaultLogo, useForcedColorScheme,
  12. } from '~/stores/context';
  13. import { swrGlobalConfiguration } from '~/utils/swr-utils';
  14. import { CommonProps } from './utils/commons';
  15. import { registerTransformerForObjectId } from './utils/objectid-transformer';
  16. import '~/styles/prebuilt/vendor.css';
  17. import '~/styles/font-icons.scss';
  18. import '~/styles/style-app.scss';
  19. import '~/styles/prebuilt/apply-colors.css';
  20. const isDev = process.env.NODE_ENV === 'development';
  21. // define fonts
  22. const lato = Lato({
  23. weight: ['400', '700'],
  24. style: ['normal', 'italic'],
  25. subsets: ['latin'],
  26. display: 'swap',
  27. });
  28. const sourceHanCodeJPSubsetMain = localFont({
  29. src: '../../resource/fonts/SourceHanCodeJP-Regular-subset-main.woff2',
  30. display: 'optional',
  31. });
  32. const sourceHanCodeJPSubsetJis2 = localFont({
  33. src: '../../resource/fonts/SourceHanCodeJP-Regular-subset-jis2.woff2',
  34. display: 'optional',
  35. });
  36. // eslint-disable-next-line @typescript-eslint/ban-types
  37. export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
  38. getLayout?: (page: ReactElement) => ReactNode,
  39. }
  40. type GrowiAppProps = AppProps & {
  41. Component: NextPageWithLayout,
  42. };
  43. // register custom serializer
  44. registerTransformerForObjectId();
  45. function GrowiApp({ Component, pageProps }: GrowiAppProps): JSX.Element {
  46. useI18nextHMR(isDev);
  47. useEffect(() => {
  48. import('bootstrap/dist/js/bootstrap');
  49. }, []);
  50. const commonPageProps = pageProps as CommonProps;
  51. useAppTitle(commonPageProps.appTitle);
  52. useSiteUrl(commonPageProps.siteUrl);
  53. useConfidential(commonPageProps.confidential);
  54. useGrowiVersion(commonPageProps.growiVersion);
  55. useIsDefaultLogo(commonPageProps.isDefaultLogo);
  56. useForcedColorScheme(commonPageProps.forcedColorScheme);
  57. // Use the layout defined at the page level, if available
  58. const getLayout = Component.getLayout ?? (page => page);
  59. return (
  60. <>
  61. <style jsx global>{`
  62. :root {
  63. --font-family-sans-serif: ${lato.style.fontFamily}, -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
  64. --font-family-serif: Georgia, 'Times New Roman', Times, serif;
  65. --font-family-monospace: monospace, ${sourceHanCodeJPSubsetMain.style.fontFamily}, ${sourceHanCodeJPSubsetJis2.style.fontFamily};
  66. }
  67. `}</style>
  68. <SWRConfig value={swrGlobalConfiguration}>
  69. {getLayout(<Component {...pageProps} />)}
  70. </SWRConfig>
  71. </>
  72. );
  73. }
  74. export default appWithTranslation(GrowiApp, nextI18nConfig);