1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-12-26 17:38:21 +01:00

change handler

This commit is contained in:
Xuan Sang LE 2018-02-25 01:57:42 +01:00
parent 3e809b03c6
commit 7c7caa7b6e
7 changed files with 35 additions and 45 deletions

View File

@ -1,6 +1,6 @@
BUILDDIR = ../build/blog
copyfiles = *.html assets *.lua *.ls view
copyfiles = *.html assets *.lua view
main:
- mkdir $(BUILDDIR)

View File

@ -1,28 +0,0 @@
<?lua
BLOG_ROOT = __ROOT__.."/blog"
-- if a file request, just respond it
local action = REQUEST.query.action
if not action or action == "" then
return require("blog.router")("top:10")
end
local path = BLOG_ROOT.."/"..action
if unix.exists(path) then
local mime = std.mime(path)
if mime == "application/octet-stream" then
std.html()
echo("Acess denied to: "..path)
else
std.header(mime)
if std.is_bin(path) then
std.fb(path)
else
std.f(path)
end
end
else
print("Perform action.."..action)
return require("blog.router")(action)
end
?>

1
blog/index.lua Normal file
View File

@ -0,0 +1 @@
require("blog.router")

View File

@ -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
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

View File

@ -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

View File

@ -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] = '<a href = "./bytag:'..b64tag:gsub("=","")..':'..MAX_ENTRY..'">'..tag.."</a>"
i = i+ 1
if tag ~= "" then
local b64tag = std.b64encode(tag)
atags[i] = '<a href = "./r:bytag:'..b64tag:gsub("=","")..':'..MAX_ENTRY..'">'..tag.."</a>"
i = i+ 1
end
end
echo(table.concat(atags, ", "))
?>
@ -40,7 +42,7 @@
<div class = "shortcontent">
<?lua
local content = bytes.__tostring(std.b64decode(data.rendered)):gsub("%%","%%%%")
local content = bytes.__tostring(std.b64decode(data.rendered))
local r, s = content:find("<hr/?>")
if r then
echo(content:sub(0,r-1))

View File

@ -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] = '<a href = "./bytag:'..b64tag:gsub("=","")..':'..MAX_ENTRY..'">'..tag.."</a>"
i = i+ 1
if tag ~= "" then
local b64tag = std.b64encode(tag)
atags[i] = '<a href = "./r:bytag:'..b64tag:gsub("=","")..':'..MAX_ENTRY..'">'..tag.."</a>"
i = i+ 1
end
end
echo(table.concat(atags, ", "))
?>
@ -39,7 +41,7 @@
<div class = "blogentry">
<div class = "shortcontent">
<?lua
local content = bytes.__tostring(std.b64decode(data.rendered)):gsub("%%","%%%%")
local content = bytes.__tostring(std.b64decode(data.rendered))
local r, s = content:find("(<hr/?>)")
if r then
@ -50,7 +52,7 @@
</div>
<div class = "detail">
<span></span>
<?='<a href="./id:'..data.id..'" ></a>'?>
<?='<a href="./r:id:'..data.id..'" ></a>'?>
<span></span>
</div>
</div>