mirror of
https://github.com/lxsang/antd-web-apps
synced 2025-04-17 09:16:44 +02:00
add local image support
This commit is contained in:
parent
c757bd253b
commit
77d5267443
@ -1,7 +1,22 @@
|
||||
BaseController:subclass("DocController")
|
||||
|
||||
local getpath = function(vfspath, controller)
|
||||
return vfspath:gsub(controller.path_map.vfs_path, controller.path_map.local_path)
|
||||
return vfspath:gsub(controller.path_map.vfs_path,
|
||||
controller.path_map.local_path)
|
||||
end
|
||||
|
||||
local pre_process_md = function(str, obj)
|
||||
local content = str
|
||||
for capture in str:gmatch("(%[%[@book:image:.*%]%])") do
|
||||
local apath = capture:match("%[%[@book:image:(.*)%]%]")
|
||||
local pattern = capture:gsub("%[", "%%["):gsub("%]", "%%]")
|
||||
if apath then
|
||||
content = str:gsub(pattern,
|
||||
"")
|
||||
end
|
||||
end
|
||||
return content
|
||||
end
|
||||
|
||||
function DocController:loadTOC()
|
||||
@ -38,7 +53,8 @@ function DocController:loadTOC()
|
||||
local spath = getpath(vs.path, self) .. "/meta.json"
|
||||
local smeta = JSON.decodeFile(spath)
|
||||
if smeta then
|
||||
local section = {
|
||||
local section =
|
||||
{
|
||||
name = smeta.name,
|
||||
path = vs.path .. "/INTRO.md",
|
||||
tpath = vs.path,
|
||||
@ -55,8 +71,10 @@ function DocController:loadTOC()
|
||||
local line = io.read()
|
||||
io.close()
|
||||
if line then
|
||||
local file = {
|
||||
name = std.trim(std.trim(line, "#"), " "),
|
||||
local file =
|
||||
{
|
||||
name = std.trim(
|
||||
std.trim(line, "#"), " "),
|
||||
path = vf.path,
|
||||
tpath = vf.path,
|
||||
parent = section,
|
||||
@ -107,6 +125,9 @@ function DocController:index(...)
|
||||
local file = io.open(path, "r")
|
||||
local content = file:read("*a")
|
||||
file.close()
|
||||
-- replace some display plugins
|
||||
content = pre_process_md(content, self)
|
||||
|
||||
self.template:setView("index", "index")
|
||||
self.template:set("data", content)
|
||||
else
|
||||
@ -145,7 +166,9 @@ function DocController:search(...)
|
||||
end
|
||||
local content = line:gsub("^[^:]*:", ""):lower()
|
||||
for k, p in ipairs(patterns) do
|
||||
content = content:gsub(p, "<span class='pattern'>"..p.."</span>")
|
||||
content = content:gsub(p,
|
||||
"<span class='pattern'>" .. p ..
|
||||
"</span>")
|
||||
end
|
||||
table.insert(result[file], content)
|
||||
end
|
||||
@ -165,15 +188,32 @@ function DocController:search(...)
|
||||
return true
|
||||
end
|
||||
|
||||
function DocController:asset(...)
|
||||
local args = {...}
|
||||
if #args == 0 then return self:actionnotfound(table.unpack(args)) end
|
||||
|
||||
local path = self.path_map.local_path .. "/" .. implode(args, DIR_SEP)
|
||||
|
||||
if self.registry.fileaccess and ulib.exists(path) then
|
||||
local mime = std.mimeOf(path)
|
||||
print(mime)
|
||||
if POLICY.mimes[mime] then
|
||||
std.sendFile(path)
|
||||
else
|
||||
self:error("Access forbidden: " .. path)
|
||||
end
|
||||
else
|
||||
self:error("Asset file not found or access forbidden: " .. path)
|
||||
end
|
||||
return false
|
||||
end
|
||||
function DocController:api(...)
|
||||
local args = {...}
|
||||
if not self.path_map.api_path then
|
||||
return self:actionnotfound(table.unpack(args))
|
||||
end
|
||||
local rpath = "index.html"
|
||||
if #args ~= 0 then
|
||||
rpath = implode(args,"/")
|
||||
end
|
||||
if #args ~= 0 then rpath = implode(args, "/") end
|
||||
local path = self.path_map.api_path .. "/" .. rpath
|
||||
|
||||
if ulib.exists(path) then
|
||||
|
Loading…
x
Reference in New Issue
Block a user