|
@@ -1,8 +1,6 @@
|
|
|
/* eslint-disable @next/next/google-font-display */
|
|
/* eslint-disable @next/next/google-font-display */
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
|
|
|
|
|
-import type { ViteManifest } from '@growi/core';
|
|
|
|
|
-import { DefaultThemeMetadata, PresetThemesMetadatas } from '@growi/preset-themes';
|
|
|
|
|
import Document, {
|
|
import Document, {
|
|
|
DocumentContext, DocumentInitialProps,
|
|
DocumentContext, DocumentInitialProps,
|
|
|
Html, Head, Main, NextScript,
|
|
Html, Head, Main, NextScript,
|
|
@@ -14,40 +12,6 @@ import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
const logger = loggerFactory('growi:page:_document');
|
|
const logger = loggerFactory('growi:page:_document');
|
|
|
|
|
|
|
|
-type HeadersForThemesProps = {
|
|
|
|
|
- theme: string,
|
|
|
|
|
- presetThemesManifest: ViteManifest,
|
|
|
|
|
- pluginThemeHref: string | undefined,
|
|
|
|
|
-}
|
|
|
|
|
-const HeadersForThemes = (props: HeadersForThemesProps): JSX.Element => {
|
|
|
|
|
- const {
|
|
|
|
|
- theme, presetThemesManifest, pluginThemeHref,
|
|
|
|
|
- } = props;
|
|
|
|
|
-
|
|
|
|
|
- const elements: JSX.Element[] = [];
|
|
|
|
|
-
|
|
|
|
|
- // when plugin theme is specified
|
|
|
|
|
- if (pluginThemeHref != null) {
|
|
|
|
|
- elements.push(
|
|
|
|
|
- <link rel="stylesheet" key={`link_custom-themes-${theme}`} href={pluginThemeHref} />,
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
- // preset theme
|
|
|
|
|
- else {
|
|
|
|
|
- const themeMetadata = PresetThemesMetadatas.find(p => p.name === theme);
|
|
|
|
|
- const manifestKey = themeMetadata?.manifestKey ?? DefaultThemeMetadata.manifestKey;
|
|
|
|
|
- if (themeMetadata == null || !(themeMetadata.manifestKey in presetThemesManifest)) {
|
|
|
|
|
- logger.warn(`Use default theme because the key for '${theme} does not exist in preset-themes manifest`);
|
|
|
|
|
- }
|
|
|
|
|
- const href = `/static/preset-themes/${presetThemesManifest[manifestKey].file}`; // configured by express.static
|
|
|
|
|
- elements.push(
|
|
|
|
|
- <link rel="stylesheet" key={`link_preset-themes-${theme}`} href={href} />,
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return <>{elements}</>;
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
type HeadersForGrowiPluginProps = {
|
|
type HeadersForGrowiPluginProps = {
|
|
|
pluginResourceEntries: GrowiPluginResourceEntries;
|
|
pluginResourceEntries: GrowiPluginResourceEntries;
|
|
|
}
|
|
}
|
|
@@ -72,12 +36,10 @@ const HeadersForGrowiPlugin = (props: HeadersForGrowiPluginProps): JSX.Element =
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
interface GrowiDocumentProps {
|
|
interface GrowiDocumentProps {
|
|
|
- theme: string,
|
|
|
|
|
|
|
+ themeHref: string,
|
|
|
customScript: string | null,
|
|
customScript: string | null,
|
|
|
customCss: string | null,
|
|
customCss: string | null,
|
|
|
customNoscript: string | null,
|
|
customNoscript: string | null,
|
|
|
- presetThemesManifest: ViteManifest,
|
|
|
|
|
- pluginThemeHref: string | undefined,
|
|
|
|
|
pluginResourceEntries: GrowiPluginResourceEntries;
|
|
pluginResourceEntries: GrowiPluginResourceEntries;
|
|
|
}
|
|
}
|
|
|
declare type GrowiDocumentInitialProps = DocumentInitialProps & GrowiDocumentProps;
|
|
declare type GrowiDocumentInitialProps = DocumentInitialProps & GrowiDocumentProps;
|
|
@@ -87,28 +49,22 @@ class GrowiDocument extends Document<GrowiDocumentInitialProps> {
|
|
|
static override async getInitialProps(ctx: DocumentContext): Promise<GrowiDocumentInitialProps> {
|
|
static override async getInitialProps(ctx: DocumentContext): Promise<GrowiDocumentInitialProps> {
|
|
|
const initialProps: DocumentInitialProps = await Document.getInitialProps(ctx);
|
|
const initialProps: DocumentInitialProps = await Document.getInitialProps(ctx);
|
|
|
const { crowi } = ctx.req as CrowiRequest<any>;
|
|
const { crowi } = ctx.req as CrowiRequest<any>;
|
|
|
- const { configManager, customizeService, pluginService } = crowi;
|
|
|
|
|
|
|
+ const { customizeService, pluginService } = crowi;
|
|
|
|
|
|
|
|
- const theme = configManager.getConfig('crowi', 'customize:theme');
|
|
|
|
|
|
|
+ const { themeHref } = customizeService;
|
|
|
const customScript: string | null = customizeService.getCustomScript();
|
|
const customScript: string | null = customizeService.getCustomScript();
|
|
|
const customCss: string | null = customizeService.getCustomCss();
|
|
const customCss: string | null = customizeService.getCustomCss();
|
|
|
const customNoscript: string | null = customizeService.getCustomNoscript();
|
|
const customNoscript: string | null = customizeService.getCustomNoscript();
|
|
|
|
|
|
|
|
- // import preset-themes manifest
|
|
|
|
|
- const presetThemesManifest = await import('@growi/preset-themes/dist/themes/manifest.json').then(imported => imported.default);
|
|
|
|
|
-
|
|
|
|
|
// retrieve plugin manifests
|
|
// retrieve plugin manifests
|
|
|
const pluginResourceEntries = await (pluginService as IPluginService).retrieveAllPluginResourceEntries();
|
|
const pluginResourceEntries = await (pluginService as IPluginService).retrieveAllPluginResourceEntries();
|
|
|
- const pluginThemeHref = await (pluginService as IPluginService).retrieveThemeHref(theme);
|
|
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
...initialProps,
|
|
...initialProps,
|
|
|
- theme,
|
|
|
|
|
|
|
+ themeHref,
|
|
|
customScript,
|
|
customScript,
|
|
|
customCss,
|
|
customCss,
|
|
|
customNoscript,
|
|
customNoscript,
|
|
|
- presetThemesManifest,
|
|
|
|
|
- pluginThemeHref,
|
|
|
|
|
pluginResourceEntries,
|
|
pluginResourceEntries,
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
@@ -137,7 +93,7 @@ class GrowiDocument extends Document<GrowiDocumentInitialProps> {
|
|
|
override render(): JSX.Element {
|
|
override render(): JSX.Element {
|
|
|
const {
|
|
const {
|
|
|
customCss, customScript, customNoscript,
|
|
customCss, customScript, customNoscript,
|
|
|
- theme, presetThemesManifest, pluginThemeHref, pluginResourceEntries,
|
|
|
|
|
|
|
+ themeHref, pluginResourceEntries,
|
|
|
} = this.props;
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -150,8 +106,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" />
|
|
|
- <HeadersForThemes theme={theme}
|
|
|
|
|
- presetThemesManifest={presetThemesManifest} pluginThemeHref={pluginThemeHref} />
|
|
|
|
|
|
|
+ <link rel="stylesheet" key="link-theme" href={themeHref} />
|
|
|
<HeadersForGrowiPlugin pluginResourceEntries={pluginResourceEntries} />
|
|
<HeadersForGrowiPlugin pluginResourceEntries={pluginResourceEntries} />
|
|
|
{this.renderCustomCss(customCss)}
|
|
{this.renderCustomCss(customCss)}
|
|
|
</Head>
|
|
</Head>
|