diff options
| author | frosty <gabriel@bwaaa.monster> | 2026-09-16 16:32:06 -0400 |
|---|---|---|
| committer | frosty <gabriel@bwaaa.monster> | 2026-09-16 16:32:06 -0400 |
| commit | 4c8d764d171ec77ff626cec273c44ec7e7a995fc (patch) | |
| tree | dc36193e611ece53c8f7e74d1dea71f8d9e7004e /examples/site | |
| download | yapssg-master.tar.gz | |
Diffstat (limited to 'examples/site')
| -rw-r--r-- | examples/site/build.lua | 69 | ||||
| -rw-r--r-- | examples/site/index.html | 42 | ||||
| -rw-r--r-- | examples/site/nested/child.txt | 1 |
3 files changed, 112 insertions, 0 deletions
diff --git a/examples/site/build.lua b/examples/site/build.lua new file mode 100644 index 0000000..0b9e67a --- /dev/null +++ b/examples/site/build.lua @@ -0,0 +1,69 @@ +-- External scripts are resolved relative to the HTML file that includes them :) + +local function element(tag, attributes, children) + return { tag = tag, attributes = attributes or {}, children = children or {} } +end + +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", + "DOM updates", + "directory walking", + "logging", + "mixed content" +} + +local feature_list = assert(find_by_class(page, "feature-list")) +for _, feature in ipairs(features) do + table.insert(feature_list.children, element("li", {}, { feature })) +end + +local entries = {} +for entry in fs.walk(".") do + table.insert(entries, entry) +end +table.sort(entries, function(left, right) return left.path < right.path end) + +local summary = assert(find_by_class(page, "file-summary")) +summary.text = tostring(#entries) .. " entries" + +local file_list = assert(find_by_class(page, "file-list")) +for _, entry in ipairs(entries) do + table.insert(file_list.children, element("li", {}, { + element("code", {}, { entry.path }), + " (", entry.type, ")" + })) +end + +local build_summary = assert(find_by_class(page, "build-summary")) +build_summary.text = "Built with " .. site.name .. " " .. site.version + +local mixed = assert(find_by_class(page, "mixed-content")) +mixed.children = { + { kind = "comment", text = "generated by Lua" }, + "Text with ", + element("strong", {}, { "an element" }), + "." +} + +table.insert(page.head.children, 1, { + kind = "processing_instruction", + target = "yapssg", + text = "generated" +}) + +page.attributes["data-entry-count"] = tostring(#entries) +log.info("generated", #features, "feature items") +log.debug("walked", #entries, "entries") diff --git a/examples/site/index.html b/examples/site/index.html new file mode 100644 index 0000000..39dd21f --- /dev/null +++ b/examples/site/index.html @@ -0,0 +1,42 @@ +<!doctype html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>yapssg feature tour</title> + </head> + <body> + <header> + <h1>yapssg feature tour</h1> + <p class="build-summary">Building…</p> + </header> + + <main> + <section> + <h2>Features</h2> + <ul class="feature-list"></ul> + </section> + + <section> + <h2>Files</h2> + <p class="file-summary"></p> + <ul class="file-list"></ul> + </section> + + <section> + <h2>Mixed content</h2> + <p class="mixed-content"></p> + </section> + </main> + + <footer> + <p>Generated with yapssg.</p> + </footer> + + <lua> + site = { name = "yapssg", version = yapssg.version } + page.attributes["data-generated"] = "true" + </lua> + <lua src="build.lua"></lua> + </body> +</html> diff --git a/examples/site/nested/child.txt b/examples/site/nested/child.txt new file mode 100644 index 0000000..b14df64 --- /dev/null +++ b/examples/site/nested/child.txt @@ -0,0 +1 @@ +Hi |
