Yuki Takei 3 лет назад
Родитель
Сommit
54e1be603a

+ 7 - 18
packages/app/src/pages/_document.page.tsx

@@ -1,9 +1,8 @@
 /* eslint-disable @next/next/google-font-display */
 import React from 'react';
 
-import { readFileSync } from 'fs';
-
 import type { PresetThemesManifest } from '@growi/preset-themes';
+import presetThemesManifest from '@growi/preset-themes/dist/manifest.json';
 import mongoose from 'mongoose';
 import Document, {
   DocumentContext, DocumentInitialProps,
@@ -13,18 +12,14 @@ import Document, {
 import { ActivatePluginService, GrowiPluginManifestEntries } from '~/client/services/activate-plugin';
 import { CrowiRequest } from '~/interfaces/crowi-request';
 import { GrowiPlugin, GrowiPluginResourceType } from '~/interfaces/plugin';
-import { resolveFromRoot } from '~/utils/project-dir-utils';
 
-type HeadersForPresetThemesProps = {
-  manifest: PresetThemesManifest;
-}
 
-const HeadersForPresetThemes = (props: HeadersForPresetThemesProps): JSX.Element => {
-  const { manifest } = props;
+const HeadersForPresetThemes = (): JSX.Element => {
+  const manifest: PresetThemesManifest = presetThemesManifest;
 
   const themeName = 'halloween';
   const manifestResourceKey = `src/${themeName}.css`;
-  const href = `/static/preset-themes/${manifest[manifestResourceKey].file}`;
+  const href = `/static/preset-themes/${manifest[manifestResourceKey].file}`; // configured by express.static
 
   const elements: JSX.Element[] = [];
 
@@ -72,7 +67,6 @@ const HeadersForGrowiPlugin = (props: HeadersForGrowiPluginProps): JSX.Element =
 
 interface GrowiDocumentProps {
   customCss: string;
-  presetThemeManifest: PresetThemesManifest;
   pluginManifestEntries: GrowiPluginManifestEntries;
 }
 declare type GrowiDocumentInitialProps = DocumentInitialProps & GrowiDocumentProps;
@@ -85,23 +79,18 @@ class GrowiDocument extends Document<GrowiDocumentInitialProps> {
     const { customizeService } = crowi;
     const customCss: string = customizeService.getCustomCss();
 
-    // retrieve preset-theme manifest
-    const presetThemeManifestPath = resolveFromRoot('public/static/preset-themes/manifest.json');
-    const presetThemeManifestStr: string = await readFileSync(presetThemeManifestPath, 'utf-8');
-    const presetThemeManifest = JSON.parse(presetThemeManifestStr);
-
     // retrieve plugin manifests
     const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
     const growiPlugins = await GrowiPlugin.find({ isEnabled: true });
     const pluginManifestEntries: GrowiPluginManifestEntries = await ActivatePluginService.retrievePluginManifests(growiPlugins);
 
     return {
-      ...initialProps, customCss, presetThemeManifest, pluginManifestEntries,
+      ...initialProps, customCss, pluginManifestEntries,
     };
   }
 
   override render(): JSX.Element {
-    const { customCss, presetThemeManifest, pluginManifestEntries } = this.props;
+    const { customCss, pluginManifestEntries } = this.props;
 
     return (
       <Html>
@@ -119,7 +108,7 @@ class GrowiDocument extends Document<GrowiDocumentInitialProps> {
           <link rel='preload' href="/static/fonts/Lato-Regular-latin-ext.woff2" as="font" type="font/woff2" />
           <link rel='preload' href="/static/fonts/Lato-Bold-latin.woff2" as="font" type="font/woff2" />
           <link rel='preload' href="/static/fonts/Lato-Bold-latin-ext.woff2" as="font" type="font/woff2" />
-          <HeadersForPresetThemes manifest={presetThemeManifest} />
+          <HeadersForPresetThemes />
           <HeadersForGrowiPlugin pluginManifestEntries={pluginManifestEntries} />
         </Head>
         <body>

+ 2 - 0
packages/app/src/server/crowi/express-init.js

@@ -4,6 +4,7 @@ import mongoose from 'mongoose';
 import { i18n, localePath } from '^/config/next-i18next.config';
 
 import loggerFactory from '~/utils/logger';
+import { resolveFromRoot } from '~/utils/project-dir-utils';
 
 const logger = loggerFactory('growi:crowi:express-init');
 
@@ -115,6 +116,7 @@ module.exports = function(crowi, app) {
 
   const staticOption = (crowi.node_env === 'production') ? { maxAge: '30d' } : {};
   app.use(express.static(crowi.publicDir, staticOption));
+  app.use('/static/preset-themes', express.static(resolveFromRoot('../../node_modules/@growi/preset-themes/dist')));
   app.use('/plugins', express.static(path.resolve(__dirname, '../../../tmp/plugins')));
 
   app.engine('html', swig.renderFile);

+ 1 - 0
packages/app/tsconfig.build.client.json

@@ -8,6 +8,7 @@
     "paths": {
       "~/*": ["./src/*"],
       "^/*": ["./*"],
+      "@growi/preset-themes/*": ["../preset-themes/*"],
       "@growi/remark-lsx/*": ["../remark-lsx/src/*"],
       "@growi/*": ["../*/src"],
       "debug": ["./src/server/utils/logger/alias-for-debug"]

+ 1 - 0
packages/app/tsconfig.build.server.json

@@ -11,6 +11,7 @@
     "paths": {
       "~/*": ["./src/*"],
       "^/*": ["./*"],
+      "@growi/preset-themes/*": ["../preset-themes/*"],
       "@growi/remark-lsx/*": ["../remark-lsx/dist/cjs/*"],
       "debug": ["./src/utils/logger/alias-for-debug"]
     }

+ 1 - 0
packages/app/tsconfig.json

@@ -5,6 +5,7 @@
     "paths": {
       "~/*": ["./src/*"],
       "^/*": ["./*"],
+      "@growi/preset-themes/*": ["../preset-themes/*"],
       "@growi/remark-lsx/*": ["../remark-lsx/src/*"],
       "@growi/*": ["../*/src"],
       "debug": ["./src/server/utils/logger/alias-for-debug"]