mirror of
https://github.com/lxsang/antd-web-apps
synced 2024-11-20 02:18:20 +01:00
Silk can now handle the asset file directly in url
This commit is contained in:
parent
48ad3a30da
commit
8e8139e709
@ -1,6 +1,6 @@
|
||||
BUILDDIR = ../build/blog
|
||||
|
||||
copyfiles = *.html assets *.lua view
|
||||
copyfiles = *.html assets *.lua view robot.txt
|
||||
|
||||
main:
|
||||
- mkdir $(BUILDDIR)
|
||||
|
2
blog/robot.txt
Normal file
2
blog/robot.txt
Normal file
@ -0,0 +1,2 @@
|
||||
User-agent: *
|
||||
Allow: /
|
@ -1,6 +1,6 @@
|
||||
BUILDDIR = ../build/info
|
||||
|
||||
copyfiles = index.ls style.css router.lua models views controllers logs
|
||||
copyfiles = index.ls style.css router.lua models views controllers logs robot.txt
|
||||
|
||||
main:
|
||||
- mkdir $(BUILDDIR)
|
||||
|
2
info/robot.txt
Normal file
2
info/robot.txt
Normal file
@ -0,0 +1,2 @@
|
||||
User-agent: *
|
||||
Allow: /
|
@ -5,9 +5,9 @@
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="<?=HTTP_ROOT?>/asset/get/rst/gscripts/showdown.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/asset/get/style.css" />
|
||||
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/asset/get/rst/font-awesome.css" />
|
||||
<script type="text/javascript" src="rst/gscripts/showdown.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
<link rel="stylesheet" type="text/css" href="rst/font-awesome.css" />
|
||||
<title>Porfolio</title>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -90,6 +90,7 @@ function AssetController:get(...)
|
||||
local path = WWW_ROOT..DIR_SEP..implode({...}, DIR_SEP)
|
||||
local mime = std.mimeOf(path)
|
||||
|
||||
if ulib.exists(path) then
|
||||
if POLICY.mimes[mime] then
|
||||
std.header(mime)
|
||||
if std.isBinary(path) then
|
||||
@ -97,6 +98,11 @@ function AssetController:get(...)
|
||||
else
|
||||
std.f(path)
|
||||
end
|
||||
else
|
||||
self:error("Access fobiden: "..path)
|
||||
end
|
||||
else
|
||||
self:error("Assset file not found: "..path)
|
||||
end
|
||||
return false
|
||||
end
|
@ -1,4 +1,3 @@
|
||||
|
||||
--define the class
|
||||
BaseObject:subclass("Router", {registry = {}})
|
||||
function Router:setPath(path)
|
||||
@ -28,17 +27,20 @@ function Router:infer(url)
|
||||
url = std.trim(url, "/")
|
||||
local args = explode(url, "/")
|
||||
local data = {
|
||||
name = 'index',
|
||||
action = 'index',
|
||||
name = "index",
|
||||
action = "index",
|
||||
args = {}
|
||||
}
|
||||
if args and #args > 0 and args[1] ~= "" then
|
||||
data.name = args[1]
|
||||
if args[2] then data.action = args[2] end
|
||||
for i = 3, #args do table.insert( data.args, args[i] ) end
|
||||
if args[2] then
|
||||
data.action = args[2]
|
||||
end
|
||||
for i = 3, #args do
|
||||
table.insert(data.args, args[i])
|
||||
end
|
||||
end
|
||||
|
||||
self:log('Controller: '..JSON.encode(data))
|
||||
-- find the controller class and init it
|
||||
local controller_name = firstToUpper(data.name) .. "Controller"
|
||||
local controller_path = self.path .. "." .. controller_name
|
||||
@ -47,28 +49,42 @@ function Router:infer(url)
|
||||
local r, e = pcall(require, controller_path)
|
||||
--require(controller_path)
|
||||
if not _G[controller_name] then
|
||||
-- verify if it is an asset
|
||||
url = url:gsub("/", DIR_SEP)
|
||||
if ulib.exists(WWW_ROOT..DIR_SEP..url) then
|
||||
data.controller = AssetController:new {registry = self.registry}
|
||||
data.action = "get"
|
||||
data.name = "asset"
|
||||
data.args ={url}
|
||||
else
|
||||
-- let the notfound controller handle the error
|
||||
data.controller = NotfoundController:new {registry = self.registry}
|
||||
data.args = {controller_name, e}
|
||||
data.action = "index"
|
||||
data.name = "notfound"
|
||||
end
|
||||
else
|
||||
-- create the coresponding controller
|
||||
data.controller = _G[controller_name]:new {registry = self.registry}
|
||||
if not data.controller[data.action] then
|
||||
data.args = {data.action}
|
||||
data.action = "actionnotfound"
|
||||
end
|
||||
end
|
||||
|
||||
self:log("Controller: " .. data.controller.class .. ", action: "..data.action..", args: ".. JSON.encode(data.args))
|
||||
return data
|
||||
end
|
||||
|
||||
|
||||
function Router:delegate()
|
||||
local views = {}
|
||||
local data = self:infer()
|
||||
-- set the controller to the main controller
|
||||
data.controller.main = true
|
||||
views.__main__ = self:call(data)
|
||||
if not views.__main__ then return end
|
||||
if not views.__main__ then
|
||||
return
|
||||
end
|
||||
-- get all visible routes
|
||||
local routes = self:dependencies(data.name .. "/" .. data.action)
|
||||
for k, v in pairs(routes) do
|
||||
@ -90,7 +106,9 @@ function Router:delegate()
|
||||
end
|
||||
|
||||
function Router:dependencies(url)
|
||||
if not self.routes[self.registry.layout] then return {} end
|
||||
if not self.routes[self.registry.layout] then
|
||||
return {}
|
||||
end
|
||||
local list = {}
|
||||
--self:log("comparing "..url)
|
||||
for k, v in pairs(self.routes[self.registry.layout]) do
|
||||
|
Loading…
Reference in New Issue
Block a user