_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. const isDev = process.env.NODE_ENV === 'development';
  20. // define fonts
  21. const lato = Lato({
  22. weight: ['400', '700'],
  23. style: ['normal', 'italic'],
  24. subsets: ['latin'],
  25. display: 'swap',
  26. });
  27. const sourceHanCodeJPSubsetMain = localFont({
  28. src: '../../resource/fonts/SourceHanCodeJP-Regular-subset-main.woff2',
  29. display: 'optional',
  30. });
  31. const sourceHanCodeJPSubsetJis2 = localFont({
  32. src: '../../resource/fonts/SourceHanCodeJP-Regular-subset-jis2.woff2',
  33. display: 'optional',
  34. });
  35. // eslint-disable-next-line @typescript-eslint/ban-types
  36. export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
  37. getLayout?: (page: ReactElement) => ReactNode,
  38. }
  39. type GrowiAppProps = AppProps & {
  40. Component: NextPageWithLayout,
  41. };
  42. // register custom serializer
  43. registerTransformerForObjectId();
  44. function GrowiApp({ Component, pageProps }: GrowiAppProps): JSX.Element {
  45. useI18nextHMR(isDev);
  46. useEffect(() => {
  47. import('bootstrap/dist/js/bootstrap');
  48. }, []);
  49. const commonPageProps = pageProps as CommonProps;
  50. useAppTitle(commonPageProps.appTitle);
  51. useSiteUrl(commonPageProps.siteUrl);
  52. useConfidential(commonPageProps.confidential);
  53. useGrowiVersion(commonPageProps.growiVersion);
  54. useIsDefaultLogo(commonPageProps.isDefaultLogo);
  55. useForcedColorScheme(commonPageProps.forcedColorScheme);
  56. // Use the layout defined at the page level, if available
  57. const getLayout = Component.getLayout ?? (page => page);
  58. return (
  59. <>
  60. <style jsx global>{`
  61. :root {
  62. --font-family-sans-serif: ${lato.style.fontFamily}, -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
  63. --font-family-serif: Georgia, 'Times New Roman', Times, serif;
  64. --font-family-monospace: monospace, ${sourceHanCodeJPSubsetMain.style.fontFamily}, ${sourceHanCodeJPSubsetJis2.style.fontFamily};
  65. }
  66. `}
  67. </style>
  68. <SWRConfig value={swrGlobalConfiguration}>
  69. {getLayout(<Component {...pageProps} />)}
  70. </SWRConfig>
  71. </>
  72. );
  73. }
  74. export default appWithTranslation(GrowiApp, nextI18nConfig);