|
@@ -1,6 +1,9 @@
|
|
|
/* eslint-disable @next/next/google-font-display */
|
|
/* eslint-disable @next/next/google-font-display */
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
|
|
|
|
|
|
|
+import { readFileSync } from 'fs';
|
|
|
|
|
+
|
|
|
|
|
+import type { PresetThemesManifest } from '@growi/preset-themes';
|
|
|
import mongoose from 'mongoose';
|
|
import mongoose from 'mongoose';
|
|
|
import Document, {
|
|
import Document, {
|
|
|
DocumentContext, DocumentInitialProps,
|
|
DocumentContext, DocumentInitialProps,
|
|
@@ -10,11 +13,31 @@ import Document, {
|
|
|
import { ActivatePluginService, GrowiPluginManifestEntries } from '~/client/services/activate-plugin';
|
|
import { ActivatePluginService, GrowiPluginManifestEntries } from '~/client/services/activate-plugin';
|
|
|
import { CrowiRequest } from '~/interfaces/crowi-request';
|
|
import { CrowiRequest } from '~/interfaces/crowi-request';
|
|
|
import { GrowiPlugin, GrowiPluginResourceType } from '~/interfaces/plugin';
|
|
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 themeName = 'halloween';
|
|
|
|
|
+ const manifestResourceKey = `src/${themeName}.css`;
|
|
|
|
|
+ const href = `/static/preset-themes/${manifest[manifestResourceKey].file}`;
|
|
|
|
|
+
|
|
|
|
|
+ const elements: JSX.Element[] = [];
|
|
|
|
|
+
|
|
|
|
|
+ elements.push(
|
|
|
|
|
+ <link rel="stylesheet" key={`link_preset-themes-${themeName}`} href={href} />,
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ return <>{elements}</>;
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
type HeadersForGrowiPluginProps = {
|
|
type HeadersForGrowiPluginProps = {
|
|
|
pluginManifestEntries: GrowiPluginManifestEntries;
|
|
pluginManifestEntries: GrowiPluginManifestEntries;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
const HeadersForGrowiPlugin = (props: HeadersForGrowiPluginProps): JSX.Element => {
|
|
const HeadersForGrowiPlugin = (props: HeadersForGrowiPluginProps): JSX.Element => {
|
|
|
const { pluginManifestEntries } = props;
|
|
const { pluginManifestEntries } = props;
|
|
|
|
|
|
|
@@ -49,6 +72,7 @@ const HeadersForGrowiPlugin = (props: HeadersForGrowiPluginProps): JSX.Element =
|
|
|
|
|
|
|
|
interface GrowiDocumentProps {
|
|
interface GrowiDocumentProps {
|
|
|
customCss: string;
|
|
customCss: string;
|
|
|
|
|
+ presetThemeManifest: PresetThemesManifest;
|
|
|
pluginManifestEntries: GrowiPluginManifestEntries;
|
|
pluginManifestEntries: GrowiPluginManifestEntries;
|
|
|
}
|
|
}
|
|
|
declare type GrowiDocumentInitialProps = DocumentInitialProps & GrowiDocumentProps;
|
|
declare type GrowiDocumentInitialProps = DocumentInitialProps & GrowiDocumentProps;
|
|
@@ -61,15 +85,23 @@ class GrowiDocument extends Document<GrowiDocumentInitialProps> {
|
|
|
const { customizeService } = crowi;
|
|
const { customizeService } = crowi;
|
|
|
const customCss: string = customizeService.getCustomCss();
|
|
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 GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
|
|
|
const growiPlugins = await GrowiPlugin.find({ isEnabled: true });
|
|
const growiPlugins = await GrowiPlugin.find({ isEnabled: true });
|
|
|
const pluginManifestEntries: GrowiPluginManifestEntries = await ActivatePluginService.retrievePluginManifests(growiPlugins);
|
|
const pluginManifestEntries: GrowiPluginManifestEntries = await ActivatePluginService.retrievePluginManifests(growiPlugins);
|
|
|
|
|
|
|
|
- return { ...initialProps, customCss, pluginManifestEntries };
|
|
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...initialProps, customCss, presetThemeManifest, pluginManifestEntries,
|
|
|
|
|
+ };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override render(): JSX.Element {
|
|
override render(): JSX.Element {
|
|
|
- const { customCss, pluginManifestEntries } = this.props;
|
|
|
|
|
|
|
+ const { customCss, presetThemeManifest, pluginManifestEntries } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<Html>
|
|
<Html>
|
|
@@ -87,6 +119,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-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.woff2" as="font" type="font/woff2" />
|
|
|
<link rel='preload' href="/static/fonts/Lato-Bold-latin-ext.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} />
|
|
|
<HeadersForGrowiPlugin pluginManifestEntries={pluginManifestEntries} />
|
|
<HeadersForGrowiPlugin pluginManifestEntries={pluginManifestEntries} />
|
|
|
</Head>
|
|
</Head>
|
|
|
<body>
|
|
<body>
|