mirror of
https://github.com/lxsang/antd-web-apps
synced 2025-06-07 14:04:22 +02:00
add local image support
This commit is contained in:
parent
c757bd253b
commit
77d5267443
@ -1,7 +1,22 @@
|
|||||||
BaseController:subclass("DocController")
|
BaseController:subclass("DocController")
|
||||||
|
|
||||||
local getpath = function(vfspath, controller)
|
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
|
end
|
||||||
|
|
||||||
function DocController:loadTOC()
|
function DocController:loadTOC()
|
||||||
@ -38,7 +53,8 @@ function DocController:loadTOC()
|
|||||||
local spath = getpath(vs.path, self) .. "/meta.json"
|
local spath = getpath(vs.path, self) .. "/meta.json"
|
||||||
local smeta = JSON.decodeFile(spath)
|
local smeta = JSON.decodeFile(spath)
|
||||||
if smeta then
|
if smeta then
|
||||||
local section = {
|
local section =
|
||||||
|
{
|
||||||
name = smeta.name,
|
name = smeta.name,
|
||||||
path = vs.path .. "/INTRO.md",
|
path = vs.path .. "/INTRO.md",
|
||||||
tpath = vs.path,
|
tpath = vs.path,
|
||||||
@ -55,8 +71,10 @@ function DocController:loadTOC()
|
|||||||
local line = io.read()
|
local line = io.read()
|
||||||
io.close()
|
io.close()
|
||||||
if line then
|
if line then
|
||||||
local file = {
|
local file =
|
||||||
name = std.trim(std.trim(line, "#"), " "),
|
{
|
||||||
|
name = std.trim(
|
||||||
|
std.trim(line, "#"), " "),
|
||||||
path = vf.path,
|
path = vf.path,
|
||||||
tpath = vf.path,
|
tpath = vf.path,
|
||||||
parent = section,
|
parent = section,
|
||||||
@ -107,6 +125,9 @@ function DocController:index(...)
|
|||||||
local file = io.open(path, "r")
|
local file = io.open(path, "r")
|
||||||
local content = file:read("*a")
|
local content = file:read("*a")
|
||||||
file.close()
|
file.close()
|
||||||
|
-- replace some display plugins
|
||||||
|
content = pre_process_md(content, self)
|
||||||
|
|
||||||
self.template:setView("index", "index")
|
self.template:setView("index", "index")
|
||||||
self.template:set("data", content)
|
self.template:set("data", content)
|
||||||
else
|
else
|
||||||
@ -145,7 +166,9 @@ function DocController:search(...)
|
|||||||
end
|
end
|
||||||
local content = line:gsub("^[^:]*:", ""):lower()
|
local content = line:gsub("^[^:]*:", ""):lower()
|
||||||
for k, p in ipairs(patterns) do
|
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
|
end
|
||||||
table.insert(result[file], content)
|
table.insert(result[file], content)
|
||||||
end
|
end
|
||||||
@ -165,15 +188,32 @@ function DocController:search(...)
|
|||||||
return true
|
return true
|
||||||
end
|
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(...)
|
function DocController:api(...)
|
||||||
local args = {...}
|
local args = {...}
|
||||||
if not self.path_map.api_path then
|
if not self.path_map.api_path then
|
||||||
return self:actionnotfound(table.unpack(args))
|
return self:actionnotfound(table.unpack(args))
|
||||||
end
|
end
|
||||||
local rpath = "index.html"
|
local rpath = "index.html"
|
||||||
if #args ~= 0 then
|
if #args ~= 0 then rpath = implode(args, "/") end
|
||||||
rpath = implode(args,"/")
|
|
||||||
end
|
|
||||||
local path = self.path_map.api_path .. "/" .. rpath
|
local path = self.path_map.api_path .. "/" .. rpath
|
||||||
|
|
||||||
if ulib.exists(path) then
|
if ulib.exists(path) then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user