diff --git a/app.js b/app.js index 4d0b492..a35f4a9 100644 --- a/app.js +++ b/app.js @@ -1,7 +1,6 @@ var Express = require('express'); var Routes = require('./routes'); -// TODO: Uncomment when we have internet // var TryCatch = require('./trycatch'); var App = module.exports = Express.createServer(); @@ -12,7 +11,6 @@ App.configure(function(){ App.set('views', __dirname + '/views'); App.set('view engine', 'jade'); // This gives us scoped errors with long stack traces - // TODO: Uncomment when we have internet // App.use(function (req, res, next) { // TryCatch(next, next); // }); diff --git a/db.js b/db.js index b36cdf0..e179aa8 100644 --- a/db.js +++ b/db.js @@ -8,26 +8,26 @@ function pathFromName(name) { return Path.join(__dirname, "pages", name + ".markdown"); } -// Load a file from disk and parse out the title and generate the HTML +// Load a file, parse the title and generate the HTML exports.loadPage = function (name, callback) { - // Attempt to load the file from disk var path = pathFromName(name); + FS.readFile(path, 'utf8', function (err, markdown) { + var exists = true; if (err) { - // If it's not there, generate a placeholder body if (err.code === "ENOENT") { - markdown = "# " + name.replace(/_/g, " ") + "\n\n" + - "This page does not exist yet. Be the first to write it."; + // Generate a placeholder body. + markdown = "# " + name.replace(/_/g, " ") + + "\n\n" + "This page does not exist yet."; exists = false; } else { - // Forward all other errors on + // Forward on all other errors. return callback(err); } } - // Parse the markdown extracting the first header as the title - // and then render as an HTML string + // Parse and render the markdown. var tree = Markdown.parse(markdown); var title = name; for (var i = 1, l = tree.length; i < l; i++) { @@ -39,7 +39,6 @@ exports.loadPage = function (name, callback) { } var html = Markdown.toHTML(tree); - // Send back the page as an object callback(null, { name: name, title: title, @@ -47,6 +46,7 @@ exports.loadPage = function (name, callback) { markdown: markdown, html: html, }); + }); }; diff --git a/package.json b/package.json index de95d17..ec8c770 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "dependencies": { "express": "2.5.5", "jade": ">= 0.0.1", - "markdown": "~0.3.1" + "markdown": "~0.3.1", + "trycatch": "~0.1.0" } -} \ No newline at end of file +} diff --git a/views/view.jade b/views/view.jade index 3d49644..5fb0ed6 100644 --- a/views/view.jade +++ b/views/view.jade @@ -1,3 +1,3 @@ h1= title .article!= html -a(href="/" + name + "/edit")= (exists ? "Edit" : "Create") + " this Page" \ No newline at end of file +a(href="/" + name + "/edit")= "Edit this Page" \ No newline at end of file