|
|
@@ -13,6 +13,8 @@ module.exports = function(crowi, app) {
|
|
|
, ApiResponse = require('../util/apiResponse')
|
|
|
, interceptorManager = crowi.getInterceptorManager()
|
|
|
, pagePathUtil = require('../util/pagePathUtil')
|
|
|
+ , swig = require('swig-templates')
|
|
|
+ , getToday = require('../util/getToday')
|
|
|
|
|
|
, actions = {};
|
|
|
|
|
|
@@ -257,7 +259,6 @@ module.exports = function(crowi, app) {
|
|
|
var pageTeamplate = 'customlayout-selector/page';
|
|
|
|
|
|
var isRedirect = false;
|
|
|
- var originalPath = path;
|
|
|
Page.findPage(path, req.user, req.query.revision)
|
|
|
.then(function(page) {
|
|
|
debug('Page found', page._id, page.path);
|
|
|
@@ -281,7 +282,7 @@ module.exports = function(crowi, app) {
|
|
|
renderVars.tree = tree;
|
|
|
})
|
|
|
.then(function() {
|
|
|
- return Page.checkIfTemplatesExist(originalPath);
|
|
|
+ return Page.checkIfTemplatesExist(path);
|
|
|
})
|
|
|
.then(() => {
|
|
|
return PageGroupRelation.findByPage(renderVars.page);
|
|
|
@@ -327,8 +328,12 @@ module.exports = function(crowi, app) {
|
|
|
.catch(function(err) {
|
|
|
pageTeamplate = 'customlayout-selector/not_found';
|
|
|
|
|
|
- return Page.findTemplate(originalPath)
|
|
|
+ return Page.findTemplate(path)
|
|
|
.then(template => {
|
|
|
+ if (template) {
|
|
|
+ template = replacePlaceholders(template, req);
|
|
|
+ }
|
|
|
+
|
|
|
renderVars.template = template;
|
|
|
});
|
|
|
})
|
|
|
@@ -365,6 +370,17 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ const replacePlaceholders = (template, req) => {
|
|
|
+ const definitions = {
|
|
|
+ pagepath: getPathFromRequest(req),
|
|
|
+ username: req.user.name,
|
|
|
+ today: getToday(),
|
|
|
+ };
|
|
|
+ const compiledTemplate = swig.compile(template);
|
|
|
+
|
|
|
+ return compiledTemplate(definitions);
|
|
|
+ };
|
|
|
+
|
|
|
actions.deletedPageListShow = function(req, res) {
|
|
|
var path = '/trash' + getPathFromRequest(req);
|
|
|
var limit = 50;
|
|
|
@@ -437,8 +453,13 @@ module.exports = function(crowi, app) {
|
|
|
function renderPage(pageData, req, res) {
|
|
|
// create page
|
|
|
if (!pageData) {
|
|
|
- return Page.findTemplate(getPathFromRequest(req))
|
|
|
- .then((template) => {
|
|
|
+ const path = getPathFromRequest(req);
|
|
|
+ return Page.findTemplate(path)
|
|
|
+ .then(template => {
|
|
|
+ if (template) {
|
|
|
+ template = replacePlaceholders(template, req);
|
|
|
+ }
|
|
|
+
|
|
|
return res.render('customlayout-selector/not_found', {
|
|
|
author: {},
|
|
|
page: false,
|