mirror of
https://github.com/lxsang/antd-web-apps
synced 2024-11-20 02:18:20 +01:00
add index pages for documentations
This commit is contained in:
parent
489c93dd61
commit
083a2d9a4d
@ -1,10 +1,23 @@
|
||||
BaseController:subclass("IndexController")
|
||||
|
||||
function IndexController:index(...)
|
||||
local file = io.open("/home/mrsang/doc/library.md", "r")
|
||||
if file then
|
||||
local content = ""
|
||||
local md = require("md")
|
||||
local callback = function(s) content = content .. s end
|
||||
md.to_html(file:read("*a"), callback)
|
||||
file.close()
|
||||
self.template:set("data", content)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function IndexController:actionnotfound(...)
|
||||
self.template:setView("index")
|
||||
return self:index(table.unpack({...}))
|
||||
self.template:setView("book")
|
||||
return self:book(table.unpack({...}))
|
||||
end
|
||||
|
||||
function IndexController:book(...)
|
||||
return true
|
||||
end
|
@ -171,7 +171,7 @@ function DocController:index(...)
|
||||
content, has_3d = post_process_md(content, self)
|
||||
-- replace some display plugins
|
||||
|
||||
self.template:setView("index", "index")
|
||||
self.template:setView("book", "index")
|
||||
self.template:set("data", content)
|
||||
self.template:set("has_3d", has_3d)
|
||||
else
|
||||
|
121
doc/views/default/index/book.ls
Normal file
121
doc/views/default/index/book.ls
Normal file
@ -0,0 +1,121 @@
|
||||
|
||||
<?lua
|
||||
local get_next
|
||||
get_next = function(toc, cpath)
|
||||
if toc.path == cpath then
|
||||
if toc.entries and #toc.entries > 0 then return toc.entries[1] end
|
||||
if toc.parent and toc.parent.entries and #toc.parent.entries > 0 then
|
||||
local entries = toc.parent.entries
|
||||
if toc.id == #entries then
|
||||
local p = toc.parent
|
||||
while p and p.parent and p.parent.entries and #p.parent.entries > 0 do
|
||||
entries = p.parent.entries
|
||||
if p.id ~= #entries then
|
||||
return entries[p.id + 1]
|
||||
end
|
||||
p = p.parent
|
||||
end
|
||||
return nil
|
||||
else
|
||||
return entries[toc.id + 1]
|
||||
end
|
||||
else
|
||||
return nil
|
||||
end
|
||||
else
|
||||
if toc.entries then
|
||||
for i,v in pairs(toc.entries) do
|
||||
local ret = get_next(v, cpath)
|
||||
if ret then return ret end
|
||||
end
|
||||
return nil
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local get_prev
|
||||
get_prev = function(toc, cpath)
|
||||
if toc.path == cpath then
|
||||
if toc.id == 1 then
|
||||
return toc.parent
|
||||
end
|
||||
if toc.parent and toc.parent.entries and #toc.parent.entries > 0 then
|
||||
local entries = toc.parent.entries
|
||||
local c = entries[toc.id - 1]
|
||||
while c and c.entries and #c.entries > 0 do
|
||||
if c.entries then
|
||||
c = c.entries[#c.entries]
|
||||
end
|
||||
end
|
||||
return c
|
||||
else
|
||||
return nil
|
||||
end
|
||||
else
|
||||
if toc.entries then
|
||||
for i,v in pairs(toc.entries) do
|
||||
local ret = get_prev(v, cpath)
|
||||
if ret then return ret end
|
||||
end
|
||||
return nil
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
local prev_entry = nil
|
||||
local next_entry = nil
|
||||
if toc then
|
||||
prev_entry = get_prev(toc.data, toc.cpath)
|
||||
next_entry = get_next(toc.data, toc.cpath)
|
||||
end
|
||||
?>
|
||||
<div class = "pagenav">
|
||||
<?lua
|
||||
|
||||
if prev_entry then
|
||||
echo("<a class = 'go_prev' href="..HTTP_ROOT..'/'..toc.controller..'/'..std.b64encode(prev_entry.path):gsub("=","")..'/'..prev_entry.name:gsub(" ", "_")..".md".." >")
|
||||
echo(prev_entry.name)
|
||||
echo("</a>")
|
||||
end
|
||||
if next_entry then
|
||||
echo("<a class = 'go_next' href="..HTTP_ROOT..'/'..toc.controller..'/'..std.b64encode(next_entry.path):gsub("=","")..'/'..next_entry.name:gsub(" ", "_")..".md".." >")
|
||||
echo(next_entry.name)
|
||||
echo("</a>")
|
||||
end
|
||||
?>
|
||||
</div>
|
||||
<div class = "md-content" id = "renderer">
|
||||
<?lua
|
||||
echo(data)
|
||||
?>
|
||||
</div>
|
||||
<?lua
|
||||
if url then
|
||||
?>
|
||||
<div class = "commentsec">
|
||||
<h3 class = "comment-header">Comments</h1>
|
||||
<div>
|
||||
The comment editor supports <b>Markdown</b> syntax. Your email is necessary to notify you of further updates on the discussion. It will be hidden from the public.
|
||||
</div>
|
||||
<div id="quick_talk_comment_thread"></div>
|
||||
</div>
|
||||
<?lua
|
||||
end
|
||||
?>
|
||||
<div class = "pagenav">
|
||||
<?lua
|
||||
if prev_entry then
|
||||
echo("<a class = 'go_prev' href="..HTTP_ROOT..'/'..toc.controller..'/'..std.b64encode(prev_entry.path):gsub("=","")..'/'..prev_entry.name:gsub(" ", "_")..".md".." >")
|
||||
echo(prev_entry.name)
|
||||
echo("</a>")
|
||||
end
|
||||
if next_entry then
|
||||
echo("<a class = 'go_next' href="..HTTP_ROOT..'/'..toc.controller..'/'..std.b64encode(next_entry.path):gsub("=","")..'/'..next_entry.name:gsub(" ", "_")..".md".." >")
|
||||
echo(next_entry.name)
|
||||
echo("</a>")
|
||||
end
|
||||
?>
|
||||
</div>
|
@ -1,121 +1,7 @@
|
||||
|
||||
<?lua
|
||||
local get_next
|
||||
get_next = function(toc, cpath)
|
||||
if toc.path == cpath then
|
||||
if toc.entries and #toc.entries > 0 then return toc.entries[1] end
|
||||
if toc.parent and toc.parent.entries and #toc.parent.entries > 0 then
|
||||
local entries = toc.parent.entries
|
||||
if toc.id == #entries then
|
||||
local p = toc.parent
|
||||
while p and p.parent and p.parent.entries and #p.parent.entries > 0 do
|
||||
entries = p.parent.entries
|
||||
if p.id ~= #entries then
|
||||
return entries[p.id + 1]
|
||||
end
|
||||
p = p.parent
|
||||
end
|
||||
return nil
|
||||
else
|
||||
return entries[toc.id + 1]
|
||||
end
|
||||
else
|
||||
return nil
|
||||
end
|
||||
else
|
||||
if toc.entries then
|
||||
for i,v in pairs(toc.entries) do
|
||||
local ret = get_next(v, cpath)
|
||||
if ret then return ret end
|
||||
end
|
||||
return nil
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local get_prev
|
||||
get_prev = function(toc, cpath)
|
||||
if toc.path == cpath then
|
||||
if toc.id == 1 then
|
||||
return toc.parent
|
||||
end
|
||||
if toc.parent and toc.parent.entries and #toc.parent.entries > 0 then
|
||||
local entries = toc.parent.entries
|
||||
local c = entries[toc.id - 1]
|
||||
while c and c.entries and #c.entries > 0 do
|
||||
if c.entries then
|
||||
c = c.entries[#c.entries]
|
||||
end
|
||||
end
|
||||
return c
|
||||
else
|
||||
return nil
|
||||
end
|
||||
else
|
||||
if toc.entries then
|
||||
for i,v in pairs(toc.entries) do
|
||||
local ret = get_prev(v, cpath)
|
||||
if ret then return ret end
|
||||
end
|
||||
return nil
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
local prev_entry = nil
|
||||
local next_entry = nil
|
||||
if toc then
|
||||
prev_entry = get_prev(toc.data, toc.cpath)
|
||||
next_entry = get_next(toc.data, toc.cpath)
|
||||
end
|
||||
?>
|
||||
<div class = "pagenav">
|
||||
<?lua
|
||||
|
||||
if prev_entry then
|
||||
echo("<a class = 'go_prev' href="..HTTP_ROOT..'/'..toc.controller..'/'..std.b64encode(prev_entry.path):gsub("=","")..'/'..prev_entry.name:gsub(" ", "_")..".md".." >")
|
||||
echo(prev_entry.name)
|
||||
echo("</a>")
|
||||
end
|
||||
if next_entry then
|
||||
echo("<a class = 'go_next' href="..HTTP_ROOT..'/'..toc.controller..'/'..std.b64encode(next_entry.path):gsub("=","")..'/'..next_entry.name:gsub(" ", "_")..".md".." >")
|
||||
echo(next_entry.name)
|
||||
echo("</a>")
|
||||
end
|
||||
?>
|
||||
</div>
|
||||
<div class = "md-content" id = "renderer">
|
||||
<?lua
|
||||
if data then
|
||||
echo(data)
|
||||
?>
|
||||
</div>
|
||||
<?lua
|
||||
if url then
|
||||
?>
|
||||
<div class = "commentsec">
|
||||
<h3 class = "comment-header">Comments</h1>
|
||||
<div>
|
||||
The comment editor supports <b>Markdown</b> syntax. Your email is necessary to notify you of further updates on the discussion. It will be hidden from the public.
|
||||
</div>
|
||||
<div id="quick_talk_comment_thread"></div>
|
||||
</div>
|
||||
<?lua
|
||||
else
|
||||
echo("404 Not found")
|
||||
end
|
||||
?>
|
||||
<div class = "pagenav">
|
||||
<?lua
|
||||
if prev_entry then
|
||||
echo("<a class = 'go_prev' href="..HTTP_ROOT..'/'..toc.controller..'/'..std.b64encode(prev_entry.path):gsub("=","")..'/'..prev_entry.name:gsub(" ", "_")..".md".." >")
|
||||
echo(prev_entry.name)
|
||||
echo("</a>")
|
||||
end
|
||||
if next_entry then
|
||||
echo("<a class = 'go_next' href="..HTTP_ROOT..'/'..toc.controller..'/'..std.b64encode(next_entry.path):gsub("=","")..'/'..next_entry.name:gsub(" ", "_")..".md".." >")
|
||||
echo(next_entry.name)
|
||||
echo("</a>")
|
||||
end
|
||||
?>
|
||||
</div>
|
||||
?>
|
@ -1 +0,0 @@
|
||||
404 not found
|
@ -70,7 +70,7 @@ local url = __main__:get("url")
|
||||
if tocdata then
|
||||
echo(tocdata.data.name)
|
||||
else
|
||||
echo("Untitled")
|
||||
echo("Documentation Hub")
|
||||
end
|
||||
?>
|
||||
</title>
|
||||
@ -94,32 +94,49 @@ local url = __main__:get("url")
|
||||
</a>
|
||||
<?lua
|
||||
end
|
||||
end
|
||||
end
|
||||
if tocdata then
|
||||
?>
|
||||
<form id = "search_form" action="<?=HTTP_ROOT..'/'..tocdata.controller..'/search/'?>" method="get" class="search-form">
|
||||
<input id = "search_box" name="q" type = "text" class = "search-box"></input>
|
||||
</form>
|
||||
<div class= "search-icon"></div>
|
||||
<?lua
|
||||
end
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<div id = "cover">
|
||||
<div id = "book">
|
||||
<div class = "doc-toc">
|
||||
<?lua
|
||||
if toc then
|
||||
toc:set("data", tocdata)
|
||||
toc:render()
|
||||
end
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="doc-content markdown-body">
|
||||
<?lua
|
||||
if __main__ then
|
||||
__main__:render()
|
||||
end
|
||||
?>
|
||||
<?lua
|
||||
if tocdata then
|
||||
?>
|
||||
<div class = "doc-toc">
|
||||
<?lua
|
||||
if toc then
|
||||
toc:set("data", tocdata)
|
||||
toc:render()
|
||||
end
|
||||
?>
|
||||
</div>
|
||||
<div class="doc-content markdown-body">
|
||||
<?lua
|
||||
if __main__ then
|
||||
__main__:render()
|
||||
end
|
||||
?>
|
||||
</div>
|
||||
<?lua
|
||||
else
|
||||
?>
|
||||
<div class="markdown-body">
|
||||
<?lua
|
||||
if __main__ then
|
||||
__main__:render()
|
||||
end
|
||||
?>
|
||||
</div>
|
||||
<?lua end ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -139,12 +156,15 @@ local url = __main__:get("url")
|
||||
}
|
||||
var input = document.getElementById("search_box");
|
||||
var form = document.getElementById("search_form");
|
||||
form.onsubmit = function()
|
||||
if(form)
|
||||
{
|
||||
var val = input.value.trim();
|
||||
console.log(val);
|
||||
if( val === "" || val == "\n") return false;
|
||||
return true;
|
||||
form.onsubmit = function()
|
||||
{
|
||||
var val = input.value.trim();
|
||||
console.log(val);
|
||||
if( val === "" || val == "\n") return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
<?lua
|
||||
if url then
|
||||
|
3
doc/views/default/notfound/index.ls
Normal file
3
doc/views/default/notfound/index.ls
Normal file
@ -0,0 +1,3 @@
|
||||
<h1>
|
||||
404 Not found: no book found
|
||||
</h1>
|
Loading…
Reference in New Issue
Block a user