From a9f6baa1b6b97c56866e246a460ff8a8cff3cc34 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 16 Feb 2015 13:38:49 -0800 Subject: [PATCH] controllers/blog: handle unknown entries better --- controllers/blog.moon | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/controllers/blog.moon b/controllers/blog.moon index 7302745..91d7dc1 100644 --- a/controllers/blog.moon +++ b/controllers/blog.moon @@ -2,9 +2,9 @@ discount = require "discount" lapis = require "lapis" file = require "pl.file" oleg = require "lib/oleg" +path = require "pl.path" util = require "lapis.util" -import render_html from require "lapis.html" split = require "util" class Blog extends lapis.Application @@ -19,17 +19,24 @@ class Blog extends lapis.Application ["blog.post": "/blog/:name"]: => @name = util.slugify @params.name + + unless path.exists "blog/#{@name}.markdown" + return render: "notfound", status: 404 + @doc = oleg.cache "blogposts", @name, -> local data - with io.open "blog/#{@name}.markdown", "r" - \read "*l" - \read "*l" - \read "*l" - data = \read "*a" + do + fin = io.open "blog/#{@name}.markdown", "r" + fin\read "*l" + fin\read "*l" + fin\read "*l" + data = fin\read "*a" + fin\close! discount data, "toc", "nopants", "autolink" with io.open "blog/#{@name}.markdown", "r" @title = \read "*l" + \close! render: true