|
|
@@ -11,9 +11,11 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
// load GROWI agent script for HackMD
|
|
|
const manifest = require(path.join(crowi.publicDir, 'manifest.json'));
|
|
|
- const agentScriptPath = path.join(crowi.publicDir, manifest['js/agent-for-hackmd.js']);
|
|
|
+ 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 = undefined;
|
|
|
+ let stylesScriptContentTpl = undefined;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -54,12 +56,23 @@ module.exports = function(crowi, app) {
|
|
|
* @param {object} res
|
|
|
*/
|
|
|
const loadStyles = function(req, res) {
|
|
|
+ // generate swig template
|
|
|
+ if (stylesScriptContentTpl == null) {
|
|
|
+ stylesScriptContentTpl = swig.compileFile(stylesScriptPath);
|
|
|
+ }
|
|
|
+
|
|
|
const styleFilePath = path.join(crowi.publicDir, manifest['styles/style-hackmd.css']);
|
|
|
+ const styles = fs.readFileSync(styleFilePath).toString().replace(/\s+/g, ' ');
|
|
|
|
|
|
- const styles = fs.readFileSync(styleFilePath);
|
|
|
+ // generate definitions to replace
|
|
|
+ const definitions = {
|
|
|
+ styles,
|
|
|
+ };
|
|
|
+ // inject
|
|
|
+ const script = stylesScriptContentTpl(definitions);
|
|
|
|
|
|
- res.set('Content-Type', 'text/css');
|
|
|
- res.send(styles);
|
|
|
+ res.set('Content-Type', 'application/javascript');
|
|
|
+ res.send(script);
|
|
|
};
|
|
|
|
|
|
const validateForApi = async function(req, res, next) {
|