mirror of
https://github.com/lxsang/antd-web-apps
synced 2025-04-20 02:26:45 +02:00
change handler
This commit is contained in:
parent
3e809b03c6
commit
7c7caa7b6e
@ -1,6 +1,6 @@
|
|||||||
BUILDDIR = ../build/blog
|
BUILDDIR = ../build/blog
|
||||||
|
|
||||||
copyfiles = *.html assets *.lua *.ls view
|
copyfiles = *.html assets *.lua view
|
||||||
|
|
||||||
main:
|
main:
|
||||||
- mkdir $(BUILDDIR)
|
- mkdir $(BUILDDIR)
|
||||||
|
@ -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
1
blog/index.lua
Normal file
@ -0,0 +1 @@
|
|||||||
|
require("blog.router")
|
@ -2,7 +2,6 @@ BLOG_ROOT = __ROOT__.."/blog"
|
|||||||
MAX_ENTRY = 10
|
MAX_ENTRY = 10
|
||||||
local user = "mrsang"
|
local user = "mrsang"
|
||||||
local handle = function(p)
|
local handle = function(p)
|
||||||
std.html()
|
|
||||||
local args = {}
|
local args = {}
|
||||||
local sort = {}
|
local sort = {}
|
||||||
local i = 1
|
local i = 1
|
||||||
@ -28,4 +27,12 @@ local handle = function(p)
|
|||||||
end
|
end
|
||||||
end
|
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
|
||||||
|
@ -2,10 +2,8 @@ local view = {}
|
|||||||
|
|
||||||
view.html = function(name)
|
view.html = function(name)
|
||||||
local path = BLOG_ROOT.."/view/"..name..".html"
|
local path = BLOG_ROOT.."/view/"..name..".html"
|
||||||
local f = io.open(path, "rb")
|
if unix.exists(path) then
|
||||||
if f then
|
std.f(path)
|
||||||
echo(f:read("*all"))
|
|
||||||
f:close()
|
|
||||||
else
|
else
|
||||||
echo("Cannot find "..path)
|
echo("Cannot find "..path)
|
||||||
end
|
end
|
||||||
@ -17,12 +15,20 @@ view.render = function(action, data, sort)
|
|||||||
local fn = nil
|
local fn = nil
|
||||||
local e
|
local e
|
||||||
if action == "id" then
|
if action == "id" then
|
||||||
|
--echo(bytes.__tostring(std.b64decode(data[0].rendered)):gsub("%%","%%%%"))
|
||||||
|
--return true
|
||||||
fn, e = loadscript(path.."/detail.ls")
|
fn, e = loadscript(path.."/detail.ls")
|
||||||
|
--echo(data[0].rendered)
|
||||||
|
--fn = require("blog.view.compiledd")
|
||||||
else
|
else
|
||||||
|
--fn = require("blog.view.compiledd")
|
||||||
fn, e = loadscript(path.."/entries.ls")
|
fn, e = loadscript(path.."/entries.ls")
|
||||||
end
|
end
|
||||||
if fn then
|
if fn then
|
||||||
fn(data, sort)
|
local r,o = pcall(fn, data, sort)
|
||||||
|
if not r then
|
||||||
|
echo(o)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
echo(e)
|
echo(e)
|
||||||
end
|
end
|
||||||
|
@ -27,9 +27,11 @@
|
|||||||
local i = 1
|
local i = 1
|
||||||
for tag in data.tags:gmatch(",*([^,]+)") do
|
for tag in data.tags:gmatch(",*([^,]+)") do
|
||||||
tag = std.trim(tag, " ")
|
tag = std.trim(tag, " ")
|
||||||
local b64tag = std.b64encode(tag)
|
if tag ~= "" then
|
||||||
atags[i] = '<a href = "./bytag:'..b64tag:gsub("=","")..':'..MAX_ENTRY..'">'..tag.."</a>"
|
local b64tag = std.b64encode(tag)
|
||||||
i = i+ 1
|
atags[i] = '<a href = "./r:bytag:'..b64tag:gsub("=","")..':'..MAX_ENTRY..'">'..tag.."</a>"
|
||||||
|
i = i+ 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
echo(table.concat(atags, ", "))
|
echo(table.concat(atags, ", "))
|
||||||
?>
|
?>
|
||||||
@ -40,7 +42,7 @@
|
|||||||
<div class = "shortcontent">
|
<div class = "shortcontent">
|
||||||
<?lua
|
<?lua
|
||||||
|
|
||||||
local content = bytes.__tostring(std.b64decode(data.rendered)):gsub("%%","%%%%")
|
local content = bytes.__tostring(std.b64decode(data.rendered))
|
||||||
local r, s = content:find("<hr/?>")
|
local r, s = content:find("<hr/?>")
|
||||||
if r then
|
if r then
|
||||||
echo(content:sub(0,r-1))
|
echo(content:sub(0,r-1))
|
||||||
|
@ -27,9 +27,11 @@
|
|||||||
local i = 1
|
local i = 1
|
||||||
for tag in data.tags:gmatch(",*([^,]+)") do
|
for tag in data.tags:gmatch(",*([^,]+)") do
|
||||||
tag = std.trim(tag, " ")
|
tag = std.trim(tag, " ")
|
||||||
local b64tag = std.b64encode(tag)
|
if tag ~= "" then
|
||||||
atags[i] = '<a href = "./bytag:'..b64tag:gsub("=","")..':'..MAX_ENTRY..'">'..tag.."</a>"
|
local b64tag = std.b64encode(tag)
|
||||||
i = i+ 1
|
atags[i] = '<a href = "./r:bytag:'..b64tag:gsub("=","")..':'..MAX_ENTRY..'">'..tag.."</a>"
|
||||||
|
i = i+ 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
echo(table.concat(atags, ", "))
|
echo(table.concat(atags, ", "))
|
||||||
?>
|
?>
|
||||||
@ -39,7 +41,7 @@
|
|||||||
<div class = "blogentry">
|
<div class = "blogentry">
|
||||||
<div class = "shortcontent">
|
<div class = "shortcontent">
|
||||||
<?lua
|
<?lua
|
||||||
local content = bytes.__tostring(std.b64decode(data.rendered)):gsub("%%","%%%%")
|
local content = bytes.__tostring(std.b64decode(data.rendered))
|
||||||
|
|
||||||
local r, s = content:find("(<hr/?>)")
|
local r, s = content:find("(<hr/?>)")
|
||||||
if r then
|
if r then
|
||||||
@ -50,7 +52,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class = "detail">
|
<div class = "detail">
|
||||||
<span></span>
|
<span></span>
|
||||||
<?='<a href="./id:'..data.id..'" ></a>'?>
|
<?='<a href="./r:id:'..data.id..'" ></a>'?>
|
||||||
<span></span>
|
<span></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user