Yuken Tezuka 3 лет назад
Родитель
Сommit
1c500ff58a
2 измененных файлов с 9 добавлено и 11 удалено
  1. 1 1
      packages/app/src/client/hackmd-agent.js
  2. 8 10
      packages/app/src/server/routes/hackmd.js

+ 1 - 1
packages/app/src/client/hackmd-agent.js

@@ -16,7 +16,7 @@ const DEBUG_PENPAL = false;
 
 /* eslint-disable no-console  */
 
-const allowedOrigin = '{{origin}}'; // will be replaced by swig
+const allowedOrigin = '<%= origin %>'; // will be replaced by ejs
 
 
 /**

+ 8 - 10
packages/app/src/server/routes/hackmd.js

@@ -1,12 +1,16 @@
+import { styles, agent } from '@growi/hackmd';
+
 import loggerFactory from '~/utils/logger';
 
 /* eslint-disable no-use-before-define */
 
 const logger = loggerFactory('growi:routes:hackmd');
 const path = require('path');
+
+const axios = require('axios');
+const ejs = require('ejs');
 const fs = require('graceful-fs');
 const swig = require('swig-templates');
-const axios = require('axios');
 
 const ApiResponse = require('../util/apiResponse');
 
@@ -38,9 +42,6 @@ module.exports = function(crowi, app) {
   const manifest = require(path.join(crowi.publicDir, 'manifest.json'));
   const agentScriptPath = path.join(crowi.publicDir, manifest['js/hackmd-agent.js']);
   const stylesScriptPath = path.join(crowi.publicDir, manifest['js/hackmd-styles.js']);
-  // generate swig template
-  let agentScriptContentTpl;
-  let stylesScriptContentTpl;
 
   /**
    * GET /_hackmd/load-agent
@@ -52,10 +53,6 @@ module.exports = function(crowi, app) {
    * @param {object} res
    */
   const loadAgent = function(req, res) {
-    // generate swig template
-    if (agentScriptContentTpl == null) {
-      agentScriptContentTpl = swig.compileFile(agentScriptPath);
-    }
 
     const origin = crowi.appService.getSiteUrl();
 
@@ -63,8 +60,9 @@ module.exports = function(crowi, app) {
     const definitions = {
       origin,
     };
-    // inject
-    const script = agentScriptContentTpl(definitions);
+
+    // inject origin to script
+    const script = ejs.render(agent, definitions);
 
     res.set('Content-Type', 'application/javascript');
     res.send(script);