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