commit f98a703

myu be you  ·  2026-12-02 16:17:23 +0000 UTC
parent 8e711c6
inline lua; can also include lua; per-file operations; how the fuck do i explain this bullshit
7 files changed,  +74, -33
+65, -29
  1@@ -2,7 +2,7 @@
  2 
  3 local sDir = (function()
  4   local d = debug.getinfo(1, "S").source:sub(2):match("^(.*)/[^/]+$")
  5-  if d and d ~= "" then return d .. "/" end
  6+  if d then return d .. "/" end
  7   return "./"
  8 end)()
  9 
 10@@ -30,16 +30,29 @@ local ePath = function(p)
 11 end
 12 
 13 local sub = function(s, vars)
 14-  if type(s) ~= "string" then return s end
 15   return s:gsub("{(%u+)}", function(k)
 16     if vars[k] ~= nil then return tostring(vars[k]) end
 17     return "{" .. k .. "}"
 18   end)
 19 end
 20 
 21+local gSex = function(expr, env)
 22+  local cunt = "return " .. expr
 23+  local fn
 24+  if setfenv and loadstring then
 25+    fn = loadstring(cunt)
 26+    if fn then setfenv(fn, env or {}) end
 27+  else
 28+    fn = load(cunt, "expr", "t", env or {})
 29+  end
 30+  if not fn then return nil end
 31+  local ok, res = pcall(fn)
 32+  if ok and res ~= nil then return tostring(res) end
 33+  return nil
 34+end
 35+
 36 local mDir = function(path)
 37   path = path:gsub("/+$", "")
 38-  if path == "" then return end
 39   local cur = ""
 40   if path:sub(1, 1) == "/" then
 41     cur = "/"
 42@@ -59,14 +72,9 @@ local rFile = function(path)
 43   return cnt
 44 end
 45 
 46-local sCheck = function(path, cnt, srcPath)
 47+local sCheck = function(path, cnt)
 48   local sz = lfs.attributes(path, "size")
 49-  if not sz or sz ~= #cnt then return false end
 50-  if srcPath then
 51-    local srcM = lfs.attributes(srcPath, "modification")
 52-    local dstM = lfs.attributes(path, "modification")
 53-    if srcM and dstM and dstM >= srcM then return true end
 54-  end
 55+  if sz ~= #cnt then return false end
 56   local f = io.open(path, "rb")
 57   if not f then return false end
 58   local existing = f:read("*a")
 59@@ -101,9 +109,7 @@ local mn = function()
 60       local nSeen = {}
 61       for k in pairs(seen) do nSeen[k] = true end
 62       nSeen[name] = true
 63-      local r = rsv(v, nSeen)
 64-      if type(r) == "string" then return r end
 65-      return tostring(r)
 66+      return tostring(rsv(v, nSeen))
 67     end)
 68   end
 69   for k, v in pairs(cfg) do cfg[k] = rsv(v, {}) end
 70@@ -123,7 +129,7 @@ local mn = function()
 71 
 72   local tpl = rFile(cfg.INPUT .. "/template.html")
 73   local cfgM = lfs.attributes(cPath, "modification") or 0
 74-  local mdM = lfs.attributes(sDir .. "lib/markdown.lua", "modification") or 0
 75+  local mdM = lfs.attributes(sDir .. "/lib/markdown.lua", "modification") or 0
 76   local tplM = lfs.attributes(cfg.INPUT .. "/template.html", "modification") or 0
 77   local incM = 0
 78   for incPath in tpl:gmatch('{{%s*include%s+"([^"]+)"%s*}}') do
 79@@ -171,7 +177,7 @@ local mn = function()
 80 
 81   local attrCache = {}
 82   local attrGet = function(path, mode)
 83-    local key = path .. "\0" .. (mode or "mode")
 84+    local key = path .. "\0" .. mode
 85     local v = attrCache[key]
 86     if v == nil then
 87       v = lfs.attributes(path, mode)
 88@@ -185,6 +191,7 @@ local mn = function()
 89   mDir(cfg.OUTPUT)
 90 
 91   lg(":: copying el files from " .. cfg.INPUT)
 92+  local tRender
 93   local cFiles
 94   cFiles = function(dir)
 95     for name in lfs.dir(dir) do
 96@@ -198,9 +205,14 @@ local mn = function()
 97             local rel = f:sub(#cfg.INPUT + 2)
 98             local dst = cfg.OUTPUT .. "/" .. rel
 99             exp[dst] = true
100-            if wFile(dst, rFile(f), f) then
101+            local cnt = rFile(f)
102+            if name:match("%.html$") then
103+              local srcM = lfs.attributes(f, "modification") or 0
104+              cnt = tRender(cnt, { MTIME = srcM })
105+            end
106+            if wFile(dst, cnt) then
107               chg = true
108-              lg(f .. " -> " .. dst)
109+              lg("copied " .. dst)
110             end
111           end
112         end
113@@ -245,7 +257,7 @@ local mn = function()
114       end
115       local tag = s:sub(tStart + 2, tEnd - 1):gsub("^%s+", ""):gsub("%s+$", "")
116       if tag:match("^if%s") then
117-        local cond = tag:match("^if%s+(.+)$") or ""
118+        local cond = tag:match("^if%s+(.+)$")
119         local mStart, mEnd = fEnd(s, tEnd + 2)
120         if not mStart then pos = tEnd + 2
121         else
122@@ -266,7 +278,6 @@ local mn = function()
123     return table.concat(out, "")
124   end
125 
126-  local tRender
127   tRender = function(txt, vars)
128     txt = txt:gsub('{{%s*include%s+"([^"]+)"%s*}}', function(path)
129       local full
130@@ -278,6 +289,12 @@ local mn = function()
131         if c then c = mk(c) end
132       elseif c and path:match("%.md$") then
133         c = mk(c)
134+      elseif c and path:match("%.lua$") then
135+        local env = {}
136+        for k, v in pairs(_G) do env[k] = v end
137+        for k, v in pairs(cfg) do env[k] = v end
138+        for k, v in pairs(vars) do env[k] = v end
139+        c = gSex("(function()\n" .. c .. "\nend)()", env)
140       end
141       
142       if c then return tRender(c, vars) end
143@@ -286,9 +303,15 @@ local mn = function()
144 
145     txt = pCond(txt, vars)
146 
147-    txt = txt:gsub("{{%s*([%w_]+)%s*}}", function(name)
148-      if vars[name] ~= nil then return tostring(vars[name]) end
149-      return ""
150+    local env = {}
151+    for k, v in pairs(_G) do env[k] = v end
152+    for k, v in pairs(cfg) do env[k] = v end
153+    for k, v in pairs(vars) do env[k] = v end
154+
155+    txt = txt:gsub("{{%s*(.-)%s*}}", function(expr)
156+      if vars[expr] ~= nil then return tostring(vars[expr]) end
157+      if cfg[expr] ~= nil then return tostring(cfg[expr]) end
158+      return gSex(expr, env) or ""
159     end)
160 
161     return txt
162@@ -350,7 +373,8 @@ local mn = function()
163           local dst = cfg.OUTPUT .. "/" .. rel
164           exp[dst] = true
165 
166-          local maxM = lfs.attributes(f, "modification") or 0
167+          local srcM = lfs.attributes(f, "modification") or 0
168+          local maxM = srcM
169           if cfgM > maxM then maxM = cfgM end
170           if mdM > maxM then maxM = mdM end
171           if tplM > maxM then maxM = tplM end
172@@ -359,10 +383,24 @@ local mn = function()
173           local dstM = lfs.attributes(dst, "modification") or 0
174 
175           if stale or not (dstM > 0 and dstM >= maxM) then
176-            local html = mk(rFile(f) or "")
177+            local rawr = rFile(f) or ""
178+            local base = name:gsub("%.md$", "")
179+            
180+            local env = {}
181+            for k, v in pairs(_G) do env[k] = v end
182+            for k, v in pairs(cfg) do env[k] = v end
183+            env.CURR = base
184+            env.MTIME = srcM
185+
186+            rawr = rawr:gsub("{{%s*(.-)%s*}}", function(expr)
187+              local inc = expr:match('^include%s+"([^"]+)"$')
188+              if inc then return tRender('{{include "' .. inc .. '"}}', { CURR = base, MTIME = srcM }) end
189+              if cfg[expr] ~= nil then return tostring(cfg[expr]) end
190+              return gSex(expr, env) or ""
191+            end)
192+            local html = mk(rawr)
193 
194             local cur = "/" .. rel
195-            local base = name:gsub("%.md$", "")
196             local pVars = { CURR = base }
197             local pFooter = sub(cfg.FOOTER, pVars)
198             
199@@ -383,7 +421,7 @@ local mn = function()
200             html = pLinks(html)
201             pFooter = pLinks(pFooter)
202 
203-            local vars = { CURR = base }
204+            local vars = { CURR = base, MTIME = srcM }
205             for k, v in pairs(cfg) do
206               if type(v) == "string" then vars[k] = sub(v, pVars)
207               elseif type(v) == "number" then vars[k] = tostring(v) end
208@@ -417,9 +455,7 @@ local mn = function()
209         if not exp[p] then if os.remove(p) then table.insert(rem, p) end end
210       elseif lMode == "directory" then
211         rDel(p)
212-        local cnt = 0
213-        for _ in lfs.dir(p) do cnt = cnt + 1 end
214-        if cnt == 2 then if lfs.rmdir(p) then table.insert(rem, p .. "/") end end
215+        if lfs.rmdir(p) then table.insert(rem, p .. "/") end
216       elseif lMode == "file" then
217         if not exp[p] then if os.remove(p) then table.insert(rem, p) end end
218       end
+0, -1
1@@ -1 +0,0 @@
2-<p>- with love, Myu be You</p>
+1, -0
1@@ -0,0 +1 @@
2+last updated: {{os.date("!%Y-%m-%d %H:%M:%S UTC", MTIME)}}
+2, -0
1@@ -0,0 +1,2 @@
2+local greeting = "you are on " .. CURR
3+return "<p>" .. greeting .. "</p>\n"
+1, -1
1@@ -4,4 +4,4 @@ write your own, because everyone has different needs.
2 > lovely,  
3 > i know.
4 
5-visit <https://xorg.fyi> for an example of css usage.
6+visit <https://x11.fyi> for an example of css usage.
+2, -1
 1@@ -16,7 +16,8 @@
 2       {{CONTENT}}
 3       {{end}}
 4       {{if not HIDDEN}}
 5-      {{include "inc/note.html"}}
 6+      {{include "inc/note.md"}}
 7+      {{include "inc/smth.lua"}}
 8       {{end}}
 9     </main>
10     <footer>{{FOOTER}}</footer>
+3, -1
1@@ -1 +1,3 @@
2-whois who?
3+whois who?  
4+me?  
5+this is blatantly a test.