From 0eeae23c9efe8c286943cf843c9ea3e1aec68b1c Mon Sep 17 00:00:00 2001 From: frosty Date: Sat, 19 Sep 2026 22:42:45 -0400 Subject: feat: add html.find_by_class --- examples/site/build.lua | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'examples/site/build.lua') diff --git a/examples/site/build.lua b/examples/site/build.lua index 4d0939a..f3b07e1 100644 --- a/examples/site/build.lua +++ b/examples/site/build.lua @@ -1,17 +1,5 @@ -- External scripts are resolved relative to the HTML file that includes them :) -local function find_by_class(node, wanted) - if type(node) ~= "table" then return nil end - local classes = node.attributes and node.attributes.class or "" - if (" " .. classes .. " "):find(" " .. wanted .. " ", 1, true) then - return node - end - for _, child in ipairs(node.children or {}) do - local match = find_by_class(child, wanted) - if match then return match end - end -end - local features = { "inline Lua", "external Lua", @@ -21,7 +9,7 @@ local features = { "mixed content" } -local feature_list = assert(find_by_class(page, "feature-list")) +local feature_list = assert(html.find_by_class(page, "feature-list")) for _, feature in ipairs(features) do table.insert(feature_list.children, html.element("li", nil, { feature })) end @@ -32,10 +20,10 @@ for entry in fs.walk(".") do end table.sort(entries, function(left, right) return left.path < right.path end) -local summary = assert(find_by_class(page, "file-summary")) +local summary = assert(html.find_by_class(page, "file-summary")) summary.text = tostring(#entries) .. " entries" -local file_list = assert(find_by_class(page, "file-list")) +local file_list = assert(html.find_by_class(page, "file-list")) for _, entry in ipairs(entries) do table.insert(file_list.children, html.element("li", nil, { html.element("code", nil, { entry.path }), @@ -43,10 +31,10 @@ for _, entry in ipairs(entries) do })) end -local build_summary = assert(find_by_class(page, "build-summary")) +local build_summary = assert(html.find_by_class(page, "build-summary")) build_summary.text = "Built with " .. site.name .. " " .. site.version -local mixed = assert(find_by_class(page, "mixed-content")) +local mixed = assert(html.find_by_class(page, "mixed-content")) mixed.children = { { kind = "comment", text = "generated by Lua" }, "Text with ", -- cgit v1.3