sou 7 лет назад
Родитель
Сommit
76939f12fa
2 измененных файлов с 44 добавлено и 6 удалено
  1. 0 1
      lib/models/page.js
  2. 44 5
      lib/routes/page.js

+ 0 - 1
lib/models/page.js

@@ -490,7 +490,6 @@ module.exports = function(crowi) {
     var PageGroupRelation = crowi.model('PageGroupRelation');
     var PageGroupRelation = crowi.model('PageGroupRelation');
 
 
     return new Promise(function(resolve, reject) {
     return new Promise(function(resolve, reject) {
-      console.log('----------------model', path)
       self.findOne({path: path}, function(err, pageData) {
       self.findOne({path: path}, function(err, pageData) {
         if (err) {
         if (err) {
           return reject(err);
           return reject(err);

+ 44 - 5
lib/routes/page.js

@@ -308,16 +308,55 @@ module.exports = function(crowi, app) {
     })
     })
     // page not exists
     // page not exists
     .catch(function(err) {
     .catch(function(err) {
-      const pageName = originalUrl.replace(/^\/([^/]*).*$/, '$1');
+      const pageName = originalUrl.replace(/^\/([^\/]*).*$/, '$1');
       Page.findPage(`/${pageName}/_template`)
       Page.findPage(`/${pageName}/_template`)
       .then(function(page) {
       .then(function(page) {
-        debug('Page not found', path);
-        console.log('---------------------------template found');
-        pageTeamplate = 'customlayout-selector/not_found';
+        //new page object and do as when found
+        var templateRevision = page.revision;
+
+        var templatePage = new Page();
+        templatePage.path = originalUrl;
+        templatePage.creator = req.user;
+        templatePage.lastUpdateUser = req.user;
+        templatePage.createdAt = Date.now();
+        templatePage.updatedAt = Date.now();
+        templatePage.redirectTo = null;
+        templatePage.grant = 1;
+        templatePage.status = 'published';
+        templatePage.grantedUsers = [];
+        templatePage.grantedUsers.push(req.user);
+
+        renderVars.page = templatePage;
+        renderVars.path = templatePage.path;
+        renderVars.revision = templateRevision;
+        renderVars.author = templatePage.revision.author;
+
+        // redirect
+        if (page.redirectTo) {
+          debug(`Redirect to '${page.redirectTo}'`);
+          isRedirect = true;
+          return res.redirect(encodeURI(page.redirectTo + '?redirectFrom=' + pagePathUtil.encodePagePath(page.path)));
+        }
+
+        renderVars.page = templatePage;
+
+        if (page) {
+          renderVars.path = templatePage.path;
+          renderVars.revision = templateRevision;
+          renderVars.author = templatePage.revision.author;
+
+          // これいる??
+          return Revision.findRevisionList(page.path, {})
+          .then(function(tree) {
+            renderVars.tree = tree;
+            return Promise.resolve();
+          }).then(function() {
+            return Promise.resolve();
+          });
+        }
       })
       })
       .catch(function(err) {
       .catch(function(err) {
         debug('Page not found', path);
         debug('Page not found', path);
-        console.log('---------------------------not found');
         // change template
         // change template
         pageTeamplate = 'customlayout-selector/not_found';
         pageTeamplate = 'customlayout-selector/not_found';
       });
       });