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

+ 1 - 0
lib/models/page.js

@@ -490,6 +490,7 @@ 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);

+ 21 - 5
lib/routes/page.js

@@ -245,6 +245,7 @@ module.exports = function(crowi, app) {
     var pageTeamplate = 'customlayout-selector/page';
     var pageTeamplate = 'customlayout-selector/page';
 
 
     var isRedirect = false;
     var isRedirect = false;
+    var originalUrl = path;
     Page.findPage(path, req.user, req.query.revision)
     Page.findPage(path, req.user, req.query.revision)
     .then(function(page) {
     .then(function(page) {
       debug('Page found', page._id, page.path);
       debug('Page found', page._id, page.path);
@@ -262,6 +263,9 @@ module.exports = function(crowi, app) {
         renderVars.path = page.path;
         renderVars.path = page.path;
         renderVars.revision = page.revision;
         renderVars.revision = page.revision;
         renderVars.author = page.revision.author;
         renderVars.author = page.revision.author;
+        console.log(renderVars.path);
+        console.log(renderVars.revision);
+        console.log(renderVars.author);
 
 
         return Revision.findRevisionList(page.path, {})
         return Revision.findRevisionList(page.path, {})
         .then(function(tree) {
         .then(function(tree) {
@@ -307,9 +311,20 @@ module.exports = function(crowi, app) {
     })
     })
     // page not exists
     // page not exists
     .catch(function(err) {
     .catch(function(err) {
-      debug('Page not found', path);
-      // change template
-      pageTeamplate = 'customlayout-selector/not_found';
+      const pageName = originalUrl.replace(/^\/([^/]*).*$/, '$1');
+      Page.findPage(`/${pageName}/_template`)
+      .then(function(page) {
+        console.log('---------------------------template found');
+        pageTeamplate = 'customlayout-selector/not_found';
+      })
+      .catch(function(err) {
+        debug('Page not found', path);
+        console.log('---------------------------not found');
+        // change template
+        pageTeamplate = 'customlayout-selector/not_found';
+      });
+
+
     })
     })
     // get list pages
     // get list pages
     .then(function() {
     .then(function() {
@@ -514,7 +529,6 @@ module.exports = function(crowi, app) {
     var isMarkdown = req.params[0].match(/.+\.md$/) || false;
     var isMarkdown = req.params[0].match(/.+\.md$/) || false;
 
 
     res.locals.path = path;
     res.locals.path = path;
-
     Page.findPage(path, req.user, req.query.revision)
     Page.findPage(path, req.user, req.query.revision)
     .then(function(page) {
     .then(function(page) {
       debug('Page found', page._id, page.path);
       debug('Page found', page._id, page.path);
@@ -849,6 +863,7 @@ module.exports = function(crowi, app) {
     const pagePath = req.query.path || null;
     const pagePath = req.query.path || null;
     const pageId = req.query.page_id || null; // TODO: handling
     const pageId = req.query.page_id || null; // TODO: handling
     const revisionId = req.query.revision_id || null;
     const revisionId = req.query.revision_id || null;
+    console.log('-------path-------', req.query.path);
 
 
     if (!pageId && !pagePath) {
     if (!pageId && !pagePath) {
       return res.json(ApiResponse.error(new Error('Parameter path or page_id is required.')));
       return res.json(ApiResponse.error(new Error('Parameter path or page_id is required.')));
@@ -856,7 +871,8 @@ module.exports = function(crowi, app) {
 
 
     let pageFinder;
     let pageFinder;
     if (pageId) { // prioritized
     if (pageId) { // prioritized
-      pageFinder = Page.findPageByIdAndGrantedUser(pageId, req.user);
+      pageFinder = Page.
+      ByIdAndGrantedUser(pageId, req.user);
     }
     }
     else if (pagePath) {
     else if (pagePath) {
       pageFinder = Page.findPage(pagePath, req.user, revisionId);
       pageFinder = Page.findPage(pagePath, req.user, revisionId);