controllers/blog: handle unknown entries better
This commit is contained in:
parent
b793cf2100
commit
a9f6baa1b6
|
@ -2,9 +2,9 @@ discount = require "discount"
|
||||||
lapis = require "lapis"
|
lapis = require "lapis"
|
||||||
file = require "pl.file"
|
file = require "pl.file"
|
||||||
oleg = require "lib/oleg"
|
oleg = require "lib/oleg"
|
||||||
|
path = require "pl.path"
|
||||||
util = require "lapis.util"
|
util = require "lapis.util"
|
||||||
|
|
||||||
import render_html from require "lapis.html"
|
|
||||||
split = require "util"
|
split = require "util"
|
||||||
|
|
||||||
class Blog extends lapis.Application
|
class Blog extends lapis.Application
|
||||||
|
@ -19,17 +19,24 @@ class Blog extends lapis.Application
|
||||||
|
|
||||||
["blog.post": "/blog/:name"]: =>
|
["blog.post": "/blog/:name"]: =>
|
||||||
@name = util.slugify @params.name
|
@name = util.slugify @params.name
|
||||||
|
|
||||||
|
unless path.exists "blog/#{@name}.markdown"
|
||||||
|
return render: "notfound", status: 404
|
||||||
|
|
||||||
@doc = oleg.cache "blogposts", @name, ->
|
@doc = oleg.cache "blogposts", @name, ->
|
||||||
local data
|
local data
|
||||||
with io.open "blog/#{@name}.markdown", "r"
|
do
|
||||||
\read "*l"
|
fin = io.open "blog/#{@name}.markdown", "r"
|
||||||
\read "*l"
|
fin\read "*l"
|
||||||
\read "*l"
|
fin\read "*l"
|
||||||
data = \read "*a"
|
fin\read "*l"
|
||||||
|
data = fin\read "*a"
|
||||||
|
fin\close!
|
||||||
|
|
||||||
discount data, "toc", "nopants", "autolink"
|
discount data, "toc", "nopants", "autolink"
|
||||||
|
|
||||||
with io.open "blog/#{@name}.markdown", "r"
|
with io.open "blog/#{@name}.markdown", "r"
|
||||||
@title = \read "*l"
|
@title = \read "*l"
|
||||||
|
\close!
|
||||||
|
|
||||||
render: true
|
render: true
|
||||||
|
|
Loading…
Reference in New Issue