lua - now we have a plugin manager which works relativley cool!

This commit is contained in:
2025-10-01 12:25:27 +02:00
parent f50d8f9d69
commit f1bda77ce2
9 changed files with 1742 additions and 10 deletions

View File

@@ -0,0 +1 @@
write_markdown("output.md", "# Generated Document\n\nContent here...")

View File

@@ -0,0 +1,6 @@
-- hello.lua
add_route("/lua/hello", function(req)
log("hello.lua handling request for " .. (req.path or "unknown"))
-- return (status, headers_table, body_string)
return 200, {["Content-Type"] = "text/html"}, "<h1>Hello from Lua plugin!</h1>"
end)

View File

@@ -0,0 +1,9 @@
register_hook("pre_template", function(md_path, html_body)
-- Check if the current markdown path is for test.md
if md_path and md_path:match("test%.md$") then
local banner = "<div class='plugin-banner' style='padding:10px;background:white;border:1px solid #f99;margin-bottom:12px;color:black;'>Note: served via Lua plugin banner</div>"
return banner .. html_body
end
-- For other pages, return the original HTML body unchanged
return html_body
end)

View File

@@ -0,0 +1,41 @@
-- Simple working endpoint using existing utilities
add_route("/admin/html-files", function(req)
-- Get files and convert to proper Lua table
local files = list_html_files()
local html = [[
<!DOCTYPE html>
<html>
<head>
<title>HTML Files</title>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
.file-item { padding: 8px; border-bottom: 1px solid #eee; }
</style>
</head>
<body>
<h1>HTML Files</h1>
<div style="background: #f5f5f5; padding: 20px; border-radius: 5px;">
]]
-- Safe iteration using a counter
local count = 0
for i = 1, 100 do -- Safe upper limit
local success, file = pcall(function() return files[i] end)
if not success or file == nil then
break
end
html = html .. "<div class='file-item'>" .. file .. "</div>"
count = count + 1
end
html = html .. [[
</div>
<p>Total files: ]] .. count .. [[</p>
<a href="/">Back</a>
</body>
</html>
]]
return html
end)