Просмотр исходного кода

Access to .md page, show raw markdown data

Sotaro KARASAWA 10 лет назад
Родитель
Сommit
7f1f9b66b6
2 измененных файлов с 8 добавлено и 4 удалено
  1. 1 0
      lib/models/page.js
  2. 7 4
      lib/routes/page.js

+ 1 - 0
lib/models/page.js

@@ -283,6 +283,7 @@ module.exports = function(crowi) {
       /^\/_r\/.*/,
       /^\/user\/[^\/]+\/(bookmarks|comments|activities|pages|recent-create|recent-edit)/, // reserved
       /.+\/edit$/,
+      /.+\.md$/,
       /^\/(installer|register|login|logout|admin|me|files|trash|paste|comments).+/,
     ];
 

+ 7 - 4
lib/routes/page.js

@@ -11,7 +11,7 @@ module.exports = function(crowi, app) {
 
   function getPathFromRequest(req) {
     var path = '/' + (req.params[0] || '');
-    return path;
+    return path.replace(/\.md$/, '');
   }
 
   function isUserPage(path) {
@@ -176,13 +176,16 @@ module.exports = function(crowi, app) {
       return ;
     }
 
-    // single page
-    var parentPath = path.split('/').slice(0, -1).join('/'); // TODO : limitation
-
     Page.findPage(path, req.user, req.query.revision)
     .then(function(page) {
       debug('Page found', page._id, page.path);
 
+      // FIXME: せっかく getPathFromRequest になってるのにここが生 params[0] だとダサイ
+      if (req.params[0].match(/.+\.md$/)) {
+        res.set('Content-Type', 'text/plain');
+        return res.send(page.revision.body);
+      }
+
       return renderPage(page, req, res);
     }).catch(function(err) {
       if (req.query.revision) {