mirror of
https://github.com/lxsang/antd-web-apps
synced 2025-04-17 09:16:44 +02:00
Add support for
- local media file - add jarvis book
This commit is contained in:
parent
cc7ae835ad
commit
a45b1ef9f0
@ -296,4 +296,10 @@ td.hljs-ln-numbers {
|
|||||||
/* for block of code */
|
/* for block of code */
|
||||||
.hljs-ln td.hljs-ln-code {
|
.hljs-ln td.hljs-ln-code {
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
model-viewer{
|
||||||
|
/*border: 1px solid #333f67;*/
|
||||||
|
width: 100%;
|
||||||
|
height: 350px;
|
||||||
}
|
}
|
@ -7,10 +7,12 @@ end
|
|||||||
|
|
||||||
local pre_process_md = function(str, obj)
|
local pre_process_md = function(str, obj)
|
||||||
local content = str
|
local content = str
|
||||||
for capture in str:gmatch("(%[%[@book:image:.*%]%])") do
|
for capture in str:gmatch("(%[%[@book:image:[^\n%]]*%]%])") do
|
||||||
local apath = capture:match("%[%[@book:image:(.*)%]%]")
|
local apath = capture:match("%[%[@book:image:([^\n%]]*)%]%]")
|
||||||
local pattern = capture:gsub("%[", "%%["):gsub("%]", "%%]")
|
local pattern = capture:gsub("%[", "%%["):gsub("%]", "%%]")
|
||||||
if apath then
|
if apath then
|
||||||
|
apath = apath:gsub(" ", "%%%%20")
|
||||||
|
print(apath)
|
||||||
content = str:gsub(pattern,
|
content = str:gsub(pattern,
|
||||||
"")
|
"/asset/" .. apath .. ")")
|
||||||
@ -19,6 +21,24 @@ local pre_process_md = function(str, obj)
|
|||||||
return content
|
return content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local post_process_md = function(str, obj)
|
||||||
|
local content = str
|
||||||
|
local has_model = false
|
||||||
|
for capture in str:gmatch("(%[%[@book:3dmodel:[^\n%]]*%]%])") do
|
||||||
|
local apath = capture:match("%[%[@book:3dmodel:([^\n%]]*)%]%]")
|
||||||
|
local pattern = capture:gsub("%[", "%%["):gsub("%]", "%%]")
|
||||||
|
if apath then
|
||||||
|
--apath = utils.urlencode(apath):gsub("%%", "%%%%")
|
||||||
|
apath = apath:gsub(" ", "%%20")
|
||||||
|
content = str:gsub(pattern,
|
||||||
|
"<model-viewer src=\"" .. HTTP_ROOT .. "/" ..
|
||||||
|
obj.name .. "/asset/" .. apath ..
|
||||||
|
"\" auto-rotate camera-controls></model-viewer>")
|
||||||
|
has_model = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return content, has_model
|
||||||
|
end
|
||||||
function DocController:loadTOC()
|
function DocController:loadTOC()
|
||||||
local path = self.path_map.local_path .. "/meta.json"
|
local path = self.path_map.local_path .. "/meta.json"
|
||||||
local result = {error = false}
|
local result = {error = false}
|
||||||
@ -122,19 +142,19 @@ function DocController:index(...)
|
|||||||
path = self.path_map.local_path .. "/INTRO.md"
|
path = self.path_map.local_path .. "/INTRO.md"
|
||||||
end
|
end
|
||||||
if path and ulib.exists(path) then
|
if path and ulib.exists(path) then
|
||||||
|
local has_3d = false
|
||||||
local file = io.open(path, "r")
|
local file = io.open(path, "r")
|
||||||
local content = ""
|
local content = ""
|
||||||
local md = require("md")
|
local md = require("md")
|
||||||
local callback = function(s)
|
local callback = function(s) content = content .. s end
|
||||||
content = content..s
|
md.to_html(pre_process_md(file:read("*a"), self), callback)
|
||||||
end
|
|
||||||
md.to_html(file:read("*a"), callback)
|
|
||||||
file.close()
|
file.close()
|
||||||
|
content, has_3d = post_process_md(content, self)
|
||||||
-- replace some display plugins
|
-- 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)
|
||||||
|
self.template:set("has_3d", has_3d)
|
||||||
else
|
else
|
||||||
self.template:setView("notfound", "index")
|
self.template:setView("notfound", "index")
|
||||||
end
|
end
|
||||||
|
@ -22,6 +22,8 @@ POST_LIMIT = 10
|
|||||||
-- require needed library
|
-- require needed library
|
||||||
require(BASE_FRW.."silk.api")
|
require(BASE_FRW.."silk.api")
|
||||||
|
|
||||||
|
POLICY.mimes["model/gltf-binary"] = true
|
||||||
|
|
||||||
if REQUEST.r then
|
if REQUEST.r then
|
||||||
REQUEST.r = REQUEST.r:gsub("%:", "/")
|
REQUEST.r = REQUEST.r:gsub("%:", "/")
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?lua
|
<?lua
|
||||||
local tocdata = __main__:get("toc")
|
local tocdata = __main__:get("toc")
|
||||||
local elinks = __main__:get("elinks")
|
local elinks = __main__:get("elinks")
|
||||||
|
local has_3d = __main__:get("has_3d")
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
@ -13,10 +14,14 @@ local elinks = __main__:get("elinks")
|
|||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
type="text/css"
|
type="text/css"
|
||||||
href="<?=HTTP_ROOT?>/rst/katex/katex.min.css" />
|
href="<?=HTTP_ROOT?>/rst/katex/katex.min.css" />
|
||||||
<!--script
|
<?lua
|
||||||
type="text/javascript"
|
if has_3d then
|
||||||
src="<?=HTTP_ROOT?>/rst/gscripts/showdown.min.js"
|
?>
|
||||||
></script-->
|
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
|
||||||
|
<script nomodule src="https://unpkg.com/@google/model-viewer/dist/model-viewer-legacy.js"></script>
|
||||||
|
<?lua
|
||||||
|
end
|
||||||
|
?>
|
||||||
<script
|
<script
|
||||||
src="<?=HTTP_ROOT?>/rst/hljs/highlight.pack.js"
|
src="<?=HTTP_ROOT?>/rst/hljs/highlight.pack.js"
|
||||||
></script>
|
></script>
|
||||||
|
@ -19,5 +19,9 @@
|
|||||||
"wasm": {
|
"wasm": {
|
||||||
"mime": "application/wasm",
|
"mime": "application/wasm",
|
||||||
"binary": true
|
"binary": true
|
||||||
|
},
|
||||||
|
"glb": {
|
||||||
|
"mime": "model/gltf-binary",
|
||||||
|
"binary": true
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user