diff --git a/blog/Makefile b/blog/Makefile index 7249a7a..65a463c 100644 --- a/blog/Makefile +++ b/blog/Makefile @@ -1,6 +1,6 @@ BUILDDIR = ../build/blog -copyfiles = *.html assets *.lua *.ls view +copyfiles = *.html assets *.lua view main: - mkdir $(BUILDDIR) diff --git a/blog/index.ls b/blog/index.ls deleted file mode 100644 index 7e7b26b..0000000 --- a/blog/index.ls +++ /dev/null @@ -1,28 +0,0 @@ - \ No newline at end of file diff --git a/blog/index.lua b/blog/index.lua new file mode 100644 index 0000000..6241237 --- /dev/null +++ b/blog/index.lua @@ -0,0 +1 @@ +require("blog.router") \ No newline at end of file diff --git a/blog/router.lua b/blog/router.lua index 4ff5f31..ca29384 100644 --- a/blog/router.lua +++ b/blog/router.lua @@ -2,7 +2,6 @@ BLOG_ROOT = __ROOT__.."/blog" MAX_ENTRY = 10 local user = "mrsang" local handle = function(p) - std.html() local args = {} local sort = {} local i = 1 @@ -28,4 +27,12 @@ local handle = function(p) end end end -return handle \ No newline at end of file +std.html() +local action = REQUEST.query.action +if not action then action = "r:top:10" end +local r, s = action:find("^r:") +if r then + handle(action:sub(s+1)) +else + echo("Unknow action "..action) +end diff --git a/blog/view.lua b/blog/view.lua index 1ccecad..60c0ea6 100644 --- a/blog/view.lua +++ b/blog/view.lua @@ -2,10 +2,8 @@ local view = {} view.html = function(name) local path = BLOG_ROOT.."/view/"..name..".html" - local f = io.open(path, "rb") - if f then - echo(f:read("*all")) - f:close() + if unix.exists(path) then + std.f(path) else echo("Cannot find "..path) end @@ -17,12 +15,20 @@ view.render = function(action, data, sort) local fn = nil local e if action == "id" then + --echo(bytes.__tostring(std.b64decode(data[0].rendered)):gsub("%%","%%%%")) + --return true fn, e = loadscript(path.."/detail.ls") + --echo(data[0].rendered) + --fn = require("blog.view.compiledd") else + --fn = require("blog.view.compiledd") fn, e = loadscript(path.."/entries.ls") end if fn then - fn(data, sort) + local r,o = pcall(fn, data, sort) + if not r then + echo(o) + end else echo(e) end diff --git a/blog/view/detail.ls b/blog/view/detail.ls index 5c7d767..4390ffa 100644 --- a/blog/view/detail.ls +++ b/blog/view/detail.ls @@ -27,9 +27,11 @@ local i = 1 for tag in data.tags:gmatch(",*([^,]+)") do tag = std.trim(tag, " ") - local b64tag = std.b64encode(tag) - atags[i] = ''..tag.."" - i = i+ 1 + if tag ~= "" then + local b64tag = std.b64encode(tag) + atags[i] = ''..tag.."" + i = i+ 1 + end end echo(table.concat(atags, ", ")) ?> @@ -40,7 +42,7 @@