diff options
| author | frosty <gabriel@bwaaa.monster> | 2026-09-19 22:42:45 -0400 |
|---|---|---|
| committer | frosty <gabriel@bwaaa.monster> | 2026-09-19 22:42:45 -0400 |
| commit | 0eeae23c9efe8c286943cf843c9ea3e1aec68b1c (patch) | |
| tree | 1bd4869b71bd0ab9385298b26a73f85e8424041d /examples/site | |
| parent | 3bff1316d1fc22f81b542d614c4bc90953bfa322 (diff) | |
feat: add html.find_by_class
Diffstat (limited to 'examples/site')
| -rw-r--r-- | examples/site/build.lua | 22 |
1 files changed, 5 insertions, 17 deletions
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 ", |
