|
|
@@ -2,7 +2,6 @@ module.exports = function(crowi, app) {
|
|
|
'use strict';
|
|
|
|
|
|
var debug = require('debug')('growi:routes:page')
|
|
|
- , swig = require('swig-templates')
|
|
|
, Page = crowi.model('Page')
|
|
|
, User = crowi.model('User')
|
|
|
, Config = crowi.model('Config')
|
|
|
@@ -14,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 = {};
|
|
|
|
|
|
@@ -258,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);
|
|
|
@@ -282,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);
|
|
|
@@ -328,23 +328,16 @@ 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) {
|
|
|
- const today = new Date();
|
|
|
- const month = ('0' + (today.getMonth() + 1)).slice(-2);
|
|
|
- const day = ('0' + today.getDate()).slice(-2);
|
|
|
- const dateString = today.getFullYear() + '/' + month + '/' + day;
|
|
|
-
|
|
|
const definitions = {
|
|
|
- pagepath: originalPath,
|
|
|
+ pagepath: path,
|
|
|
username: req.user.name,
|
|
|
- today: dateString,
|
|
|
+ today: getToday(),
|
|
|
};
|
|
|
|
|
|
- const compiledTemplate = swig.compile(template);
|
|
|
-
|
|
|
- template = compiledTemplate(definitions);
|
|
|
+ template = placeholderReader(template, definitions);
|
|
|
}
|
|
|
|
|
|
renderVars.template = template;
|
|
|
@@ -383,6 +376,11 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ const placeholderReader = (template, definitions) => {
|
|
|
+ const compiledTemplate = swig.compile(template);
|
|
|
+ return compiledTemplate(definitions);
|
|
|
+ };
|
|
|
+
|
|
|
actions.deletedPageListShow = function(req, res) {
|
|
|
var path = '/trash' + getPathFromRequest(req);
|
|
|
var limit = 50;
|
|
|
@@ -455,8 +453,19 @@ 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) {
|
|
|
+ const definitions = {
|
|
|
+ pagepath: path,
|
|
|
+ username: req.user.name,
|
|
|
+ today: getToday(),
|
|
|
+ };
|
|
|
+
|
|
|
+ template = placeholderReader(template, definitions);
|
|
|
+ }
|
|
|
+
|
|
|
return res.render('customlayout-selector/not_found', {
|
|
|
author: {},
|
|
|
page: false,
|