|
|
@@ -1,4 +1,7 @@
|
|
|
+const stringReplaceAsync = require('string-replace-async');
|
|
|
+
|
|
|
const BasicInterceptor = require('./BasicInterceptor');
|
|
|
+const Lsx = require('./Lsx');
|
|
|
|
|
|
/**
|
|
|
* The interceptor for lsx Server Side Rendering
|
|
|
@@ -8,6 +11,11 @@ const BasicInterceptor = require('./BasicInterceptor');
|
|
|
*/
|
|
|
class LsxBeforeRenderPageInterceptor extends BasicInterceptor {
|
|
|
|
|
|
+ constructor(crowi, app) {
|
|
|
+ super(crowi, app);
|
|
|
+ this.lsx = new Lsx(crowi, app);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @inheritdoc
|
|
|
*/
|
|
|
@@ -19,11 +27,22 @@ class LsxBeforeRenderPageInterceptor extends BasicInterceptor {
|
|
|
* @inheritdoc
|
|
|
*/
|
|
|
process(contextName, ...args) {
|
|
|
- let renderVars = args[0];
|
|
|
-
|
|
|
- // TODO replace lsx tag
|
|
|
+ const req = args[0];
|
|
|
+ const res = args[1];
|
|
|
+ const renderVars = args[2];
|
|
|
|
|
|
- return Promise.resolve(...args);
|
|
|
+ let promises = [];
|
|
|
+ return stringReplaceAsync(
|
|
|
+ renderVars.page.revision.body,
|
|
|
+ /\$lsx\((.*)\)/g, // see: https://regex101.com/r/NQq3s9/2
|
|
|
+ (all, group1) => {
|
|
|
+ return this.lsx.renderHtml(req.user, req.path, group1);
|
|
|
+ }
|
|
|
+ ).then((results) => {
|
|
|
+ // replace body
|
|
|
+ renderVars.page.revision.body = results;
|
|
|
+ return Promise.resolve(...args);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
}
|