From c36ca7b8fb053eda4a34fa06cba0a54468a934d4 Mon Sep 17 00:00:00 2001 From: lxsang Date: Wed, 24 Jun 2020 19:00:41 +0200 Subject: [PATCH] first antdoc version --- blog/assets/style.css | 2 +- doc/assets/style.css | 115 ++++++++++++++++++++++++++-- doc/controllers/doccontroller.lua | 69 ++++++++++++++++- doc/views/default/index/index.ls | 120 +++++++++++++++++++++++++++++- doc/views/default/index/search.ls | 26 +++++++ doc/views/default/layout.ls | 45 ++++++++--- doc/views/default/toc/index.ls | 25 +++++-- grs/hljs/github-gist.css | 14 +++- grs/hljs/highlight.pack.js | 8 +- 9 files changed, 388 insertions(+), 36 deletions(-) create mode 100644 doc/views/default/index/search.ls diff --git a/blog/assets/style.css b/blog/assets/style.css index 4519211..32fb127 100644 --- a/blog/assets/style.css +++ b/blog/assets/style.css @@ -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%; diff --git a/doc/assets/style.css b/doc/assets/style.css index 3ae2760..1d72734 100644 --- a/doc/assets/style.css +++ b/doc/assets/style.css @@ -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%} \ No newline at end of file +img {max-width:100%} + +a { + color: #333f67; + text-decoration: none; +} + +a:hover{ + text-decoration: underline; +} + +form.search-form { + display: contents; +} \ No newline at end of file diff --git a/doc/controllers/doccontroller.lua b/doc/controllers/doccontroller.lua index ba9ae11..04877bf 100644 --- a/doc/controllers/doccontroller.lua +++ b/doc/controllers/doccontroller.lua @@ -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, ""..p.."") + 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)) diff --git a/doc/views/default/index/index.ls b/doc/views/default/index/index.ls index a148ed2..8c54fef 100644 --- a/doc/views/default/index/index.ls +++ b/doc/views/default/index/index.ls @@ -1,4 +1,120 @@ \ No newline at end of file + 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 +?> + +
+ +
+ + \ No newline at end of file diff --git a/doc/views/default/index/search.ls b/doc/views/default/index/search.ls new file mode 100644 index 0000000..a250a8d --- /dev/null +++ b/doc/views/default/index/search.ls @@ -0,0 +1,26 @@ +
+") + echo("

") + echo(title) + echo("

") + for i,content in ipairs(arr) do + echo("

") + echo("..."..content.."...") + echo("

") + end + echo("
") + end + else + echo("

No search result found

") + end +?> + \ No newline at end of file diff --git a/doc/views/default/layout.ls b/doc/views/default/layout.ls index 76d5f53..8d7e4b1 100644 --- a/doc/views/default/layout.ls +++ b/doc/views/default/layout.ls @@ -4,10 +4,30 @@ local tocdata = __main__:get("toc") + + + + + + - +
+ +
@@ -69,14 +91,7 @@ local tocdata = __main__:get("toc") Powered by antd server, (c) 2019 - Xuan Sang LE diff --git a/doc/views/default/toc/index.ls b/doc/views/default/toc/index.ls index bd614f0..fddf695 100644 --- a/doc/views/default/toc/index.ls +++ b/doc/views/default/toc/index.ls @@ -1,5 +1,6 @@ ' end - local markup = '
  • '..caret..''..data.name.."" + 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 = '
  • '..caret..''..data.name.."" if data.entries then - markup = markup.."