1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-19 18:08:21 +01:00

first antdoc version

This commit is contained in:
lxsang 2020-06-24 19:00:41 +02:00
parent 44f50f3a52
commit c36ca7b8fb
9 changed files with 388 additions and 36 deletions

View File

@ -2,7 +2,7 @@ html,body{
margin: 0;
padding: 0;
font-family: "Ubuntu";
font-size: 15px;
font-size: 13px;
line-height: 1.5;
width: 100%;
height: 100%;

View File

@ -2,7 +2,7 @@ html,body{
margin: 0;
padding: 0;
font-family: "Ubuntu";
font-size: 15px;
font-size: 13px;
line-height: 1.5;
width: 100%;
height: 100%;
@ -31,7 +31,8 @@ html,body{
}
#cover{
height: calc(100% - 80px);
height: calc(100% - 50px);
overflow-x: hidden;
overflow-y: auto;
}
#navbar{
@ -125,6 +126,10 @@ div.doc-toc ul.nested {
list-style-type: none;
}
div.doc-toc li.selected > a {
font-weight: bold;
}
div.doc-toc .caret {
cursor: pointer;
user-select: none; /* Prevent text selection */
@ -151,14 +156,110 @@ div.doc-toc .active {
padding-left: 20px;
}
div.doc-content {
display: block;
width: calc(100% - 320px);
float: right;
div.doc-toc a.highlight {
color: #333f67;
}
div.doc-content {
display: block;
width: calc(100% - 300px);
float: right;
padding-left: 10px;
}
div.pagenav {
display: flex;
justify-content:flex-end;
flex-direction: row;
width: 100%;
}
div.pagenav a.go_next, div.pagenav a.go_prev {
display: block;
flex: 1;
text-decoration: none;
color: #333f67;
/* font-weight: bold; */
border: 1px solid #dadddd;
background-color: #eef1f1;
padding-top: 3px;
padding-bottom: 3px;
margin-bottom: 10px;
}
div.pagenav a.go_next:hover, div.pagenav a.go_prev:hover
{
background-color: #e6e8e8;
}
div.pagenav a.go_next
{
padding-right: 5px;
text-align: center;
}
div.pagenav a.go_prev {
border-right: 0;
padding-left: 5px;
text-align: center;
}
div.pagenav a.go_prev::before {
content: "\f137";
color: #333f67;
display: inline-block;
font-family: "FontAwesome";
}
div.pagenav a.go_next::after {
content: "\f138";
color: #333f67;
display: inline-block;
font-family: "FontAwesome";
}
div.md-content {
padding-left: 15px;
}
div.md-content p.result-header a {
color: #333f67;
font-weight: bold;
}
div.md-content p.result-header {
padding: 0;
margin: 0;
margin-top: 10px;
font-size: 15;
}
div.md-content p.result-content {
padding: 3px;
margin: 0;
margin-left: 20px;
border-bottom: 1px solid #dadddd;
margin-bottom: 5px;
}
div.md-content p.result-content span.pattern {
background-color: chocolate;
color: white;
padding-left: 3px;
padding-right: 3px;
border-radius: 2px;
}
div.md-content p.result-header a::before{
content: "\f002";
color: #333f67;
display: inline-block;
font-family: "FontAwesome";
}
/* for block of code */
/* #container .blogentry .hljs-ln td.hljs-ln-code {
padding-left: 10px;
} */
img {max-width:100%}
img {max-width:100%}
a {
color: #333f67;
text-decoration: none;
}
a:hover{
text-decoration: underline;
}
form.search-form {
display: contents;
}

View File

@ -16,7 +16,8 @@ function DocController:loadTOC()
result.data = {
name = bmeta.name,
path = self.path_map.vfs_path.."/INTRO.md",
entries = {}
entries = {},
parent = nil
}
-- read all the entries
for kc,vc in pairs(bmeta.entries) do
@ -27,7 +28,10 @@ function DocController:loadTOC()
local chapter = {
name = cmeta.name,
path = vc.path.."/INTRO.md",
entries = {}
tpath = vc.path,
entries = {},
parent = result.data,
id = kc
}
-- read all sections
for ks,vs in pairs(cmeta.entries) do
@ -37,7 +41,10 @@ function DocController:loadTOC()
local section = {
name = smeta.name,
path = vs.path.."/INTRO.md",
entries = {}
tpath = vs.path,
entries = {},
parent = chapter,
id = ks
}
-- read all files
for kf,vf in pairs(smeta.entries) do
@ -50,7 +57,10 @@ function DocController:loadTOC()
if line then
local file = {
name = std.trim(std.trim(line, "#"), " "),
path = vf.path
path = vf.path,
tpath = vf.path,
parent = section,
id = kf
}
table.insert( section.entries, file)
end
@ -83,10 +93,12 @@ function DocController:index(...)
if b64text then
local p = bytes.__tostring(std.b64decode(b64text .. "=="))
if p then
toc.cpath = p
path = getpath(p, self)
end
end
else
toc.cpath = self.path_map.vfs_path
path = self.path_map.local_path.."/INTRO.md"
end
if path and ulib.exists(path) then
@ -101,6 +113,55 @@ function DocController:index(...)
return true
end
function DocController:search(...)
local args = {...}
local query = REQUEST.q
if query then
local cmd = "grep -ri --include=\\*.md "
local arr = explode(query, " ")
local patterns = {}
for k,v in ipairs(arr) do
local world = std.trim(v, " ")
if v and v ~= "" then
cmd = cmd.." -e '"..v.."' "
table.insert( patterns,v:lower())
end
end
if #patterns > 0 then
local toc = self:loadTOC()
toc.controller = self.name
self.template:set("toc", toc)
self.template:setView("search", "index")
cmd = cmd..self.path_map.local_path
local handle = io.popen(cmd)
local result = {}
for line in handle:lines() do
file = line:match("^[^:]*")
if file then
if not result[file] then
result[file] = {}
end
local content = line:gsub("^[^:]*:",""):lower()
for k,p in ipairs(patterns) do
content = content:gsub(p, "<span class='pattern'>"..p.."</span>")
end
table.insert(result[file],content)
end
end
handle:close()
-- process the result
self.template:set("data", result)
self.template:set("controller", self.name)
self.template:set("map", self.path_map)
else
return self:actionnotfound(table.unpack(args))
end
else
return self:actionnotfound(table.unpack(args))
end
return true
end
function DocController:actionnotfound(...)
local args = {...}
return self:index(table.unpack(args))

View File

@ -1,4 +1,120 @@
<?lua
echo(data)
?>
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">
</div>
<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>
<script>
window.addEventListener('load', (event) => {
var markdown = `<?=std.b64encode(data)?>`;
var converter = new showdown.Converter();
var html = converter.makeHtml(atob(markdown));
document.getElementById("renderer").innerHTML = html;
// highlight and math display
renderMathInElement(document.getElementById("renderer"));
document.querySelectorAll("pre code").forEach(element => {
hljs.highlightBlock(element);
hljs.lineNumbersBlock(element);
});
});
</script>

View File

@ -0,0 +1,26 @@
<div class = "md-content">
<?lua
if data then
for file,arr in pairs(data) do
local f = io.open(file, "r")
io.input(f)
local title = io.read()
io.close()
file = file:gsub(map.local_path, map.vfs_path)
title = std.trim(std.trim(title, "#"), " ")
echo("<div>")
echo("<p class= 'result-header'><a href='"..HTTP_ROOT..'/'..controller..'/'..std.b64encode(file):gsub("=","")..'/'..title:gsub(" ", "_")..".md'>")
echo(title)
echo("</a></p>")
for i,content in ipairs(arr) do
echo("<p class= 'result-content'>")
echo("..."..content.."...")
echo("</p>")
end
echo("</div>")
end
else
echo("<p>No search result found</p>")
end
?>
</div>

View File

@ -4,10 +4,30 @@ local tocdata = __main__:get("toc")
<!DOCTYPE html>
<html>
<head>
<link
rel="stylesheet"
type="text/css"
href="<?=HTTP_ROOT?>/rst/hljs/github.css" />
<link
rel="stylesheet"
type="text/css"
href="<?=HTTP_ROOT?>/rst/katex/katex.min.css" />
<script
type="text/javascript"
src="<?=HTTP_ROOT?>/rst/gscripts/showdown.min.js"
></script>
<script
src="<?=HTTP_ROOT?>/rst/hljs/highlight.pack.js"
></script>
<script
src="<?=HTTP_ROOT?>/rst/hljs/highlightjs-line-numbers.min.js"
></script>
<script
src="<?=HTTP_ROOT?>/rst/katex/katex.min.js"
></script>
<script
src="<?=HTTP_ROOT?>/rst/katex/auto-render.min.js"
></script>
<link
rel="stylesheet"
type="text/css"
@ -40,7 +60,9 @@ local tocdata = __main__:get("toc")
</a>
<?lua end ?>
</div>
<input type = "text" class = "search-box"></input>
<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>
</div>
</div>
@ -69,14 +91,7 @@ local tocdata = __main__:get("toc")
Powered by antd server, (c) 2019 - <?=os.date("*t").year?> Xuan Sang LE
</div>
<script>
window.onload = function () {
var els = document.getElementsByClassName("doc-content");
var converter = new showdown.Converter();
for (var i in els) {
var text = els[i].innerHTML;
var html = converter.makeHtml(text);
els[i].innerHTML = html;
}
window.addEventListener('load', (event) => {
// tree view events
var toggler = document.getElementsByClassName("caret");
var i;
@ -86,8 +101,16 @@ local tocdata = __main__:get("toc")
this.classList.toggle("caret-down");
});
}
// TODO math display
};
var input = document.getElementById("search_box");
var form = document.getElementById("search_form");
form.onsubmit = function()
{
var val = input.value.trim();
console.log(val);
if( val === "" || val == "\n") return false;
return true;
}
});
</script>
</body>
</html>

View File

@ -1,5 +1,6 @@
<?lua
gentree = function(data, controller)
local gentree
gentree = function(data, controller, cpath)
if not data then
return ""
end
@ -7,11 +8,23 @@ gentree = function(data, controller)
if data.entries then
caret = '<span class = "caret"></span>'
end
local markup = '<li>'..caret..'<a href="'..HTTP_ROOT..'/'..controller..'/'..std.b64encode(data.path):gsub("=","")..'/'..data.name:gsub(" ", "_")..'.md">'..data.name.."</a>"
local active = ""
local selected = ""
local highlight = ""
if data.tpath and cpath then
if cpath:match("^"..data.tpath) then
active = "active"
highlight = "class = 'highlight'"
end
if data.path == cpath then
selected = "class = 'selected'"
end
end
local markup = '<li '..selected..'>'..caret..'<a '..highlight..' href="'..HTTP_ROOT..'/'..controller..'/'..std.b64encode(data.path):gsub("=","")..'/'..data.name:gsub(" ", "_")..'.md">'..data.name.."</a>"
if data.entries then
markup = markup.."<ul class='nested'>"
markup = markup.."<ul class='nested "..active.."'>"
for k,v in pairs(data.entries) do
markup = markup..gentree(v, controller)
markup = markup..gentree(v, controller, cpath)
end
markup = markup.."</ul>"
end
@ -22,10 +35,10 @@ end
<ul id = "toc">
<?lua
if data.error then
return echo("Unable to read toc")
return echo("<li>Unable to read TOC</li>")
end
for k,v in pairs(data.data.entries) do
echo(gentree(v, data.controller))
echo(gentree(v, data.controller, data.cpath))
end
?>
</ul>

View File

@ -1,5 +1,6 @@
/**
* GitHub Gist Theme
* Author : Anthony Attard - https://github.com/AnthonyAttard
* Author : Louis Barranqueiro - https://github.com/LouisBarranqueiro
*/
@ -16,7 +17,6 @@
color: #969896;
}
.hljs-string,
.hljs-variable,
.hljs-template-variable,
.hljs-strong,
@ -28,7 +28,7 @@
.hljs-keyword,
.hljs-selector-tag,
.hljs-type {
color: #a71d5d;
color: #d73a49;
}
.hljs-literal,
@ -53,7 +53,7 @@
.hljs-selector-class,
.hljs-selector-attr,
.hljs-selector-pseudo {
color: #795da3;
color: #6f42c1;
}
.hljs-addition {
@ -69,3 +69,11 @@
.hljs-link {
text-decoration: underline;
}
.hljs-number {
color: #005cc5;
}
.hljs-string {
color: #032f62;
}

File diff suppressed because one or more lines are too long