2
0
Эх сурвалжийг харах

add customHtml into noscript

Yuki Takei 3 жил өмнө
parent
commit
a4fab56add

+ 8 - 8
packages/app/src/client/services/AdminCustomizeContainer.js

@@ -36,7 +36,7 @@ export default class AdminCustomizeContainer extends Container {
       isAllReplyShown: false,
       isAllReplyShown: false,
       isSearchScopeChildrenAsDefault: false,
       isSearchScopeChildrenAsDefault: false,
       currentCustomizeTitle: '',
       currentCustomizeTitle: '',
-      currentCustomizeHeader: '',
+      currentCustomizeHtml: '',
       currentCustomizeCss: '',
       currentCustomizeCss: '',
       currentCustomizeScript: '',
       currentCustomizeScript: '',
     };
     };
@@ -73,7 +73,7 @@ export default class AdminCustomizeContainer extends Container {
         isAllReplyShown: customizeParams.isAllReplyShown,
         isAllReplyShown: customizeParams.isAllReplyShown,
         isSearchScopeChildrenAsDefault: customizeParams.isSearchScopeChildrenAsDefault,
         isSearchScopeChildrenAsDefault: customizeParams.isSearchScopeChildrenAsDefault,
         currentCustomizeTitle: customizeParams.customizeTitle,
         currentCustomizeTitle: customizeParams.customizeTitle,
-        currentCustomizeHeader: customizeParams.customizeHeader,
+        currentCustomizeHtml: customizeParams.customizeHtml,
         currentCustomizeCss: customizeParams.customizeCss,
         currentCustomizeCss: customizeParams.customizeCss,
         currentCustomizeScript: customizeParams.customizeScript,
         currentCustomizeScript: customizeParams.customizeScript,
       });
       });
@@ -160,8 +160,8 @@ export default class AdminCustomizeContainer extends Container {
   /**
   /**
    * Change customize Html header
    * Change customize Html header
    */
    */
-  changeCustomizeHeader(inputValue) {
-    this.setState({ currentCustomizeHeader: inputValue });
+  changeCustomizeHtml(inputValue) {
+    this.setState({ currentCustomizeHtml: inputValue });
   }
   }
 
 
   /**
   /**
@@ -239,14 +239,14 @@ export default class AdminCustomizeContainer extends Container {
    * Update customHeader
    * Update customHeader
    * @memberOf AdminCustomizeContainer
    * @memberOf AdminCustomizeContainer
    */
    */
-  async updateCustomizeHeader() {
+  async updateCustomizeHtml() {
     try {
     try {
-      const response = await apiv3Put('/customize-setting/customize-header', {
-        customizeHeader: this.state.currentCustomizeHeader,
+      const response = await apiv3Put('/customize-setting/customize-html', {
+        customizeHtml: this.state.currentCustomizeHtml,
       });
       });
       const { customizedParams } = response.data;
       const { customizedParams } = response.data;
       this.setState({
       this.setState({
-        currentCustomizeHeader: customizedParams.customizeHeader,
+        currentCustomizeHtml: customizedParams.customizeHtml,
       });
       });
     }
     }
     catch (err) {
     catch (err) {

+ 4 - 4
packages/app/src/components/Admin/Customize/CustomizeHeaderSetting.tsx

@@ -20,7 +20,7 @@ const CustomizeHeaderSetting = (props: Props): JSX.Element => {
 
 
   const onClickSubmit = useCallback(async() => {
   const onClickSubmit = useCallback(async() => {
     try {
     try {
-      await adminCustomizeContainer.updateCustomizeHeader();
+      await adminCustomizeContainer.updateCustomizeHtml();
       toastSuccess(t('toaster.update_successed', { target: t('admin:customize_settings.custom_header'), ns: 'commons' }));
       toastSuccess(t('toaster.update_successed', { target: t('admin:customize_settings.custom_header'), ns: 'commons' }));
     }
     }
     catch (err) {
     catch (err) {
@@ -55,9 +55,9 @@ const CustomizeHeaderSetting = (props: Props): JSX.Element => {
           <div className="form-group">
           <div className="form-group">
             <textarea
             <textarea
               className="form-control"
               className="form-control"
-              name="customizeHeader"
-              value={adminCustomizeContainer.state.currentCustomizeHeader || ''}
-              onChange={(e) => { adminCustomizeContainer.changeCustomizeHeader(e.target.value) }}
+              name="customizeHtml"
+              value={adminCustomizeContainer.state.currentCustomizeHtml || ''}
+              onChange={(e) => { adminCustomizeContainer.changeCustomizeHtml(e.target.value) }}
             />
             />
             <p className="form-text text-muted text-right">
             <p className="form-text text-muted text-right">
               <i className="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
               <i className="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>

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

@@ -73,8 +73,9 @@ const HeadersForGrowiPlugin = (props: HeadersForGrowiPluginProps): JSX.Element =
 
 
 interface GrowiDocumentProps {
 interface GrowiDocumentProps {
   theme: string,
   theme: string,
-  customCss: string | null,
   customScript: string | null,
   customScript: string | null,
+  customCss: string | null,
+  customHtml: string | null,
   presetThemesManifest: ViteManifest,
   presetThemesManifest: ViteManifest,
   pluginThemeHref: string | undefined,
   pluginThemeHref: string | undefined,
   pluginResourceEntries: GrowiPluginResourceEntries;
   pluginResourceEntries: GrowiPluginResourceEntries;
@@ -89,8 +90,9 @@ class GrowiDocument extends Document<GrowiDocumentInitialProps> {
     const { configManager, customizeService, pluginService } = crowi;
     const { configManager, customizeService, pluginService } = crowi;
 
 
     const theme = configManager.getConfig('crowi', 'customize:theme');
     const theme = configManager.getConfig('crowi', 'customize:theme');
-    const customCss: string = customizeService.getCustomCss();
-    const customScript: string = customizeService.getCustomScript();
+    const customScript: string | null = customizeService.getCustomScript();
+    const customCss: string | null = customizeService.getCustomCss();
+    const customHtml: string | null = customizeService.getCustomHtml();
 
 
     // import preset-themes manifest
     // import preset-themes manifest
     const presetThemesManifest = await import('@growi/preset-themes/dist/themes/manifest.json').then(imported => imported.default);
     const presetThemesManifest = await import('@growi/preset-themes/dist/themes/manifest.json').then(imported => imported.default);
@@ -102,14 +104,22 @@ class GrowiDocument extends Document<GrowiDocumentInitialProps> {
     return {
     return {
       ...initialProps,
       ...initialProps,
       theme,
       theme,
-      customCss,
       customScript,
       customScript,
+      customCss,
+      customHtml,
       presetThemesManifest,
       presetThemesManifest,
       pluginThemeHref,
       pluginThemeHref,
       pluginResourceEntries,
       pluginResourceEntries,
     };
     };
   }
   }
 
 
+  renderCustomHtml(customHtml: string | null): JSX.Element {
+    if (customHtml == null || customHtml.length === 0) {
+      return <></>;
+    }
+    return <noscript dangerouslySetInnerHTML={{ __html: customHtml }} />;
+  }
+
   renderCustomCss(customCss: string | null): JSX.Element {
   renderCustomCss(customCss: string | null): JSX.Element {
     if (customCss == null || customCss.length === 0) {
     if (customCss == null || customCss.length === 0) {
       return <></>;
       return <></>;
@@ -126,13 +136,13 @@ class GrowiDocument extends Document<GrowiDocumentInitialProps> {
 
 
   override render(): JSX.Element {
   override render(): JSX.Element {
     const {
     const {
-      customCss, customScript, theme, presetThemesManifest, pluginThemeHref, pluginResourceEntries,
+      customCss, customScript, customHtml,
+      theme, presetThemesManifest, pluginThemeHref, pluginResourceEntries,
     } = this.props;
     } = this.props;
 
 
     return (
     return (
       <Html>
       <Html>
         <Head>
         <Head>
-          {this.renderCustomCss(customCss)}
           {this.renderCustomScript(customScript)}
           {this.renderCustomScript(customScript)}
           <link rel='preload' href="/static/fonts/PressStart2P-latin.woff2" as="font" type="font/woff2" />
           <link rel='preload' href="/static/fonts/PressStart2P-latin.woff2" as="font" type="font/woff2" />
           <link rel='preload' href="/static/fonts/PressStart2P-latin-ext.woff2" as="font" type="font/woff2" />
           <link rel='preload' href="/static/fonts/PressStart2P-latin-ext.woff2" as="font" type="font/woff2" />
@@ -143,8 +153,10 @@ class GrowiDocument extends Document<GrowiDocumentInitialProps> {
           <HeadersForThemes theme={theme}
           <HeadersForThemes theme={theme}
             presetThemesManifest={presetThemesManifest} pluginThemeHref={pluginThemeHref} />
             presetThemesManifest={presetThemesManifest} pluginThemeHref={pluginThemeHref} />
           <HeadersForGrowiPlugin pluginResourceEntries={pluginResourceEntries} />
           <HeadersForGrowiPlugin pluginResourceEntries={pluginResourceEntries} />
+          {this.renderCustomCss(customCss)}
         </Head>
         </Head>
         <body>
         <body>
+          {this.renderCustomHtml(customHtml)}
           <Main />
           <Main />
           <NextScript />
           <NextScript />
         </body>
         </body>

+ 1 - 1
packages/app/src/server/models/config.ts

@@ -118,7 +118,7 @@ export const defaultCrowiConfigs: { [key: string]: any } = {
 
 
   'customize:css' : undefined,
   'customize:css' : undefined,
   'customize:script' : undefined,
   'customize:script' : undefined,
-  'customize:header' : undefined,
+  'customize:noscript' : undefined,
   'customize:title' : undefined,
   'customize:title' : undefined,
   'customize:highlightJsStyle' : 'github',
   'customize:highlightJsStyle' : 'github',
   'customize:highlightJsStyleBorder' : false,
   'customize:highlightJsStyleBorder' : false,

+ 21 - 21
packages/app/src/server/routes/apiv3/customize-setting.js

@@ -77,11 +77,11 @@ const multer = require('multer');
  *        properties:
  *        properties:
  *          customizeTitle:
  *          customizeTitle:
  *            type: string
  *            type: string
- *      CustomizeHeader:
- *        description: CustomizeHeader
+ *      CustomizeHtml:
+ *        description: CustomizeHtml
  *        type: object
  *        type: object
  *        properties:
  *        properties:
- *          customizeHeader:
+ *          customizeHtml:
  *            type: string
  *            type: string
  *      CustomizeCss:
  *      CustomizeCss:
  *        description: CustomizeCss
  *        description: CustomizeCss
@@ -131,20 +131,20 @@ module.exports = (crowi) => {
     customizeTitle: [
     customizeTitle: [
       body('customizeTitle').isString(),
       body('customizeTitle').isString(),
     ],
     ],
-    customizeHeader: [
-      body('customizeHeader').isString(),
-    ],
     highlight: [
     highlight: [
       body('highlightJsStyle').isString().isIn([
       body('highlightJsStyle').isString().isIn([
         'github', 'github-gist', 'atom-one-light', 'xcode', 'vs', 'atom-one-dark', 'hybrid', 'monokai', 'tomorrow-night', 'vs2015',
         'github', 'github-gist', 'atom-one-light', 'xcode', 'vs', 'atom-one-dark', 'hybrid', 'monokai', 'tomorrow-night', 'vs2015',
       ]),
       ]),
       body('highlightJsStyleBorder').isBoolean(),
       body('highlightJsStyleBorder').isBoolean(),
     ],
     ],
+    customizeScript: [
+      body('customizeScript').isString(),
+    ],
     customizeCss: [
     customizeCss: [
       body('customizeCss').isString(),
       body('customizeCss').isString(),
     ],
     ],
-    customizeScript: [
-      body('customizeScript').isString(),
+    customizeHtml: [
+      body('customizeHtml').isString(),
     ],
     ],
     logo: [
     logo: [
       body('isDefaultLogo').isBoolean().optional({ nullable: true }),
       body('isDefaultLogo').isBoolean().optional({ nullable: true }),
@@ -186,9 +186,9 @@ module.exports = (crowi) => {
       styleName: await crowi.configManager.getConfig('crowi', 'customize:highlightJsStyle'),
       styleName: await crowi.configManager.getConfig('crowi', 'customize:highlightJsStyle'),
       styleBorder: await crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
       styleBorder: await crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
       customizeTitle: await crowi.configManager.getConfig('crowi', 'customize:title'),
       customizeTitle: await crowi.configManager.getConfig('crowi', 'customize:title'),
-      customizeHeader: await crowi.configManager.getConfig('crowi', 'customize:header'),
-      customizeCss: await crowi.configManager.getConfig('crowi', 'customize:css'),
       customizeScript: await crowi.configManager.getConfig('crowi', 'customize:script'),
       customizeScript: await crowi.configManager.getConfig('crowi', 'customize:script'),
+      customizeCss: await crowi.configManager.getConfig('crowi', 'customize:css'),
+      customizeHtml: await crowi.configManager.getConfig('crowi', 'customize:noscript'),
     };
     };
 
 
     return res.apiv3({ customizeParams });
     return res.apiv3({ customizeParams });
@@ -531,43 +531,43 @@ module.exports = (crowi) => {
   /**
   /**
    * @swagger
    * @swagger
    *
    *
-   *    /customize-setting/customizeHeader:
+   *    /customize-setting/customize-html:
    *      put:
    *      put:
    *        tags: [CustomizeSetting]
    *        tags: [CustomizeSetting]
-   *        operationId: updateCustomizeHeaderCustomizeSetting
-   *        summary: /customize-setting/customizeHeader
-   *        description: Update customizeHeader
+   *        operationId: updateCustomizeHtmlCustomizeSetting
+   *        summary: /customize-setting/customize-html
+   *        description: Update customizeHtml
    *        requestBody:
    *        requestBody:
    *          required: true
    *          required: true
    *          content:
    *          content:
    *            application/json:
    *            application/json:
    *              schema:
    *              schema:
-   *                $ref: '#/components/schemas/CustomizeHeader'
+   *                $ref: '#/components/schemas/customizeHtml'
    *        responses:
    *        responses:
    *          200:
    *          200:
    *            description: Succeeded to update customize header
    *            description: Succeeded to update customize header
    *            content:
    *            content:
    *              application/json:
    *              application/json:
    *                schema:
    *                schema:
-   *                  $ref: '#/components/schemas/CustomizeHeader'
+   *                  $ref: '#/components/schemas/customizeHtml'
    */
    */
-  router.put('/customize-header', loginRequiredStrictly, adminRequired, addActivity, validator.customizeHeader, apiV3FormValidator, async(req, res) => {
+  router.put('/customize-html', loginRequiredStrictly, adminRequired, addActivity, validator.customizeHtml, apiV3FormValidator, async(req, res) => {
     const requestParams = {
     const requestParams = {
-      'customize:header': req.body.customizeHeader,
+      'customize:noscript': req.body.customizeHtml,
     };
     };
     try {
     try {
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
       const customizedParams = {
       const customizedParams = {
-        customizeHeader: await crowi.configManager.getConfig('crowi', 'customize:header'),
+        customizeHtml: await crowi.configManager.getConfig('crowi', 'customize:noscript'),
       };
       };
       const parameters = { action: SupportedAction.ACTION_ADMIN_CUSTOM_HTML_HEADER_UPDATE };
       const parameters = { action: SupportedAction.ACTION_ADMIN_CUSTOM_HTML_HEADER_UPDATE };
       activityEvent.emit('update', res.locals.activity._id, parameters);
       activityEvent.emit('update', res.locals.activity._id, parameters);
       return res.apiv3({ customizedParams });
       return res.apiv3({ customizedParams });
     }
     }
     catch (err) {
     catch (err) {
-      const msg = 'Error occurred in updating customizeHeader';
+      const msg = 'Error occurred in updating customizeHtml';
       logger.error('Error', err);
       logger.error('Error', err);
-      return res.apiv3Err(new ErrorV3(msg, 'update-customizeHeader-failed'));
+      return res.apiv3Err(new ErrorV3(msg, 'update-customizeHtml-failed'));
     }
     }
   });
   });
 
 

+ 8 - 5
packages/app/src/server/service/customize.ts

@@ -1,12 +1,13 @@
 // eslint-disable-next-line no-unused-vars
 // eslint-disable-next-line no-unused-vars
+import { DevidedPagePath } from '@growi/core';
 import uglifycss from 'uglifycss';
 import uglifycss from 'uglifycss';
 
 
-import { DevidedPagePath } from '@growi/core';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
 import S2sMessage from '../models/vo/s2s-message';
 import S2sMessage from '../models/vo/s2s-message';
-import { S2sMessageHandlable } from './s2s-messaging/handlable';
+
 import ConfigManager from './config-manager';
 import ConfigManager from './config-manager';
+import { S2sMessageHandlable } from './s2s-messaging/handlable';
 
 
 const logger = loggerFactory('growi:service:CustomizeService');
 const logger = loggerFactory('growi:service:CustomizeService');
 
 
@@ -80,8 +81,6 @@ class CustomizeService implements S2sMessageHandlable {
    * initialize custom css strings
    * initialize custom css strings
    */
    */
   initCustomCss() {
   initCustomCss() {
-    const uglifycss = require('uglifycss');
-
     const rawCss = this.configManager.getConfig('crowi', 'customize:css') || '';
     const rawCss = this.configManager.getConfig('crowi', 'customize:css') || '';
 
 
     // uglify and store
     // uglify and store
@@ -95,7 +94,11 @@ class CustomizeService implements S2sMessageHandlable {
   }
   }
 
 
   getCustomScript() {
   getCustomScript() {
-    return this.configManager.getConfig('crowi', 'customize:script') || '';
+    return this.configManager.getConfig('crowi', 'customize:script');
+  }
+
+  getCustomHtml() {
+    return this.configManager.getConfig('crowi', 'customize:noscript');
   }
   }
 
 
   initCustomTitle() {
   initCustomTitle() {