diff --git a/controllers/document.js b/controllers/document.js index e8f6ca950..e5a47c5f4 100644 --- a/controllers/document.js +++ b/controllers/document.js @@ -70,33 +70,6 @@ exports.view = function (aReq, aRes, aNext) { //--- Tasks - // Read file listing - tasks.push( - function (aCallback) { - fs.readdir(documentPath, function (aErr, aFileList) { - var file = null; - - if (aErr || !aFileList) { - aCallback({ statusCode: 500, statusMessage : 'Error retrieving page list' }); - return; - } - - // Dynamically create a file listing of the pages - options.fileList = []; - for (file in aFileList) { - if (/\.md$/.test(aFileList[file])) { - options.fileList.push({ - href: aFileList[file].replace(/\.md$/, ''), - textContent: aFileList[file].replace(/\.md$/, '').replace(/-/g, ' ') - }); - } - } - - aCallback(null); - }); - } - ); - // Read the requested md file contents tasks.push( function (aCallback) { @@ -131,6 +104,33 @@ exports.view = function (aReq, aRes, aNext) { }); } ); + + // Read file listing + tasks.push( + function (aCallback) { + fs.readdir(documentPath, function (aErr, aFileList) { + var file = null; + + if (aErr || !aFileList) { + aCallback({ statusCode: 500, statusMessage : 'Error retrieving page list' }); + return; + } + + // Dynamically create a file listing of the pages + options.fileList = []; + for (file in aFileList) { + if (/\.md$/.test(aFileList[file])) { + options.fileList.push({ + href: aFileList[file].replace(/\.md$/, ''), + textContent: aFileList[file].replace(/\.md$/, '').replace(/-/g, ' ') + }); + } + } + + aCallback(null); + }); + } + ); } else { // Page metadata