commit 5bed89b
myu be you
·
2026-11-20 17:41:33 +0000 UTC
parent d23f04f
lovely looking READABILITY
1 files changed,
+18,
-21
+18,
-21
1@@ -1,9 +1,7 @@
2 #!/usr/bin/env lua
3
4 local sDir = (function()
5- local src = debug.getinfo(1, "S").source
6- src = src:sub(2)
7- local d = src:match("^(.*)/[^/]+$")
8+ local d = debug.getinfo(1, "S").source:sub(2):match("^(.*)/[^/]+$")
9 if d and d ~= "" then return d .. "/" end
10 return "./"
11 end)()
12@@ -42,12 +40,11 @@ end
13 local mDir = function(path)
14 path = path:gsub("/+$", "")
15 if path == "" then return end
16- local pfx = ""
17+ local cur = ""
18 if path:sub(1, 1) == "/" then
19- pfx = "/"
20+ cur = "/"
21 path = path:sub(2)
22 end
23- local cur = pfx
24 for p in path:gmatch("[^/]+") do
25 cur = cur .. p .. "/"
26 if lfs.attributes(cur, "mode") ~= "directory" then lfs.mkdir(cur) end
27@@ -270,6 +267,14 @@ local mn = function()
28 local full
29 if path:sub(1, 1) == "/" then full = path else full = cfg.INPUT .. "/" .. path end
30 local c = rFile(full)
31+
32+ if not c and path:match("%.html$") then
33+ c = rFile(full:gsub("%.html$", ".md"))
34+ if c then c = mk(c) end
35+ elseif c and path:match("%.md$") then
36+ c = mk(c)
37+ end
38+
39 if c then return tRender(c, vars) end
40 return ""
41 end)
42@@ -307,9 +312,7 @@ local mn = function()
43 local mode = attrGet(itm, "mode")
44 if mode == "file" and name:match("%.md$") then
45 if name ~= "index.md" then
46- local rel = itm:sub(#cfg.INPUT + 2):gsub("%.md$", ".html")
47- local ttl = name:gsub("%.md$", ""):gsub("-", " ")
48- table.insert(out, '<li>' .. fLabel(rel, ttl) .. '</li>')
49+ table.insert(out, '<li>' .. fLabel(itm:sub(#cfg.INPUT + 2):gsub("%.md$", ".html"), name:gsub("%.md$", ""):gsub("-", " ")) .. '</li>')
50 end
51 elseif mode == "directory" then
52 local sub = pDir(itm)
53@@ -338,8 +341,7 @@ local mn = function()
54 local dst = cfg.OUTPUT .. "/" .. rel
55 exp[dst] = true
56
57- local srcM = lfs.attributes(f, "modification") or 0
58- local maxM = srcM
59+ local maxM = lfs.attributes(f, "modification") or 0
60 if cfgM > maxM then maxM = cfgM end
61 if mdM > maxM then maxM = mdM end
62 if tplM > maxM then maxM = tplM end
63@@ -348,25 +350,21 @@ local mn = function()
64 local dstM = lfs.attributes(dst, "modification") or 0
65
66 if stale or not (dstM > 0 and dstM >= maxM) then
67- local raw = rFile(f) or ""
68- local html = mk(raw)
69+ local html = mk(rFile(f) or "")
70
71 local cur = "/" .. rel
72 local base = name:gsub("%.md$", "")
73 local pVars = { CURR = base }
74- local pTitle = sub(cfg.TITLE, pVars)
75 local pFooter = sub(cfg.FOOTER, pVars)
76
77 local pLinks = function(txt)
78 return txt:gsub("<a(.-)>(.-)</a>", function(attrs, inner)
79 if inner:find("<img", 1, true) or inner == "" then return "<a" .. attrs .. ">" .. inner .. "</a>" end
80 local href = attrs:match("href=['\"](.-)['\"]") or ""
81- local isCur = (href == cur) or ("/" .. href == cur)
82 local l
83- if isCur then
84+ if (href == cur) or ("/" .. href == cur) then
85 if cfg.LINKCURR:find("{CURR}", 1, true) then l = cfg.LINKCURR:gsub("{CURR}", function() return inner end) else l = cfg.LINKCURR .. inner end
86- local nAttrs = attrs:gsub('class=["\'][^"\']*["\']', "") .. ' class="aPage"'
87- return '<a' .. nAttrs .. '><span class="aIndicator">' .. l .. '</span></a>'
88+ return '<a' .. attrs:gsub('class=["\'][^"\']*["\']', "") .. ' class="aPage"><span class="aIndicator">' .. l .. '</span></a>'
89 end
90 if cfg.LINK:find("{CURR}", 1, true) then l = cfg.LINK:gsub("{CURR}", function() return inner end) else l = cfg.LINK .. inner end
91 return '<a' .. attrs .. '>' .. l .. '</a>'
92@@ -376,14 +374,13 @@ local mn = function()
93 html = pLinks(html)
94 pFooter = pLinks(pFooter)
95
96- local nav = "<ul>\n" .. bNav(cur) .. "\n</ul>"
97 local vars = { CURR = base }
98 for k, v in pairs(cfg) do
99 if type(v) == "string" then vars[k] = sub(v, pVars)
100 elseif type(v) == "number" then vars[k] = tostring(v) end
101 end
102- vars.TITLE = pTitle
103- vars.NAV = nav
104+ vars.TITLE = sub(cfg.TITLE, pVars)
105+ vars.NAV = "<ul>\n" .. bNav(cur) .. "\n</ul>"
106 vars.CONTENT = html
107 vars.FOOTER = pFooter
108 local out = tRender(tpl, vars)