summaryrefslogtreecommitdiff
path: root/.zs/components
diff options
context:
space:
mode:
authordelta <darkussdelta@gmail.com>2026-01-27 04:18:15 +0100
committerdelta <darkussdelta@gmail.com>2026-01-27 04:18:15 +0100
commit3026a05a2a2be91aa160de230a838acd5c2b3536 (patch)
tree141ea424f7c4149c27e6749a73fec7dd4fd354ab /.zs/components
parentce0a6c0388b4684d8f15a7ff1049e42e2d8cc63c (diff)
woohoo no more bash componentsHEADmaster
Diffstat (limited to '.zs/components')
-rwxr-xr-x.zs/components/buttons16
-rw-r--r--.zs/components/buttons.jq3
-rwxr-xr-x.zs/components/colors2
-rw-r--r--.zs/components/colors.jq10
-rw-r--r--.zs/components/dl_buttons.jq3
-rwxr-xr-x.zs/components/footer91
-rw-r--r--.zs/components/get_filename.jq1
-rw-r--r--.zs/components/html.lua152
-rwxr-xr-x.zs/components/nav63
-rw-r--r--.zs/components/palette.json132
-rw-r--r--.zs/components/stylua.toml5
11 files changed, 478 insertions, 0 deletions
diff --git a/.zs/components/buttons b/.zs/components/buttons
new file mode 100755
index 0000000..8f4e166
--- /dev/null
+++ b/.zs/components/buttons
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+BUTTONS_DIR="assets/buttons/"
+
+jq -r -f .zs/components/dl_buttons.jq buttons.json | while read url file; do
+ if [ ! -d ".pub/$BUTTONS_DIR" ]; then
+ mkdir ".pub/$BUTTONS_DIR"
+ fi
+ path=".pub/$BUTTONS_DIR/$file"
+ if [ ! -f "$path" ]; then
+ wget -O "$path" "$url"
+ fi
+done
+
+
+jq -r --arg BUTTONS_DIR "$BUTTONS_DIR" -f .zs/components/buttons.jq buttons.json
diff --git a/.zs/components/buttons.jq b/.zs/components/buttons.jq
new file mode 100644
index 0000000..3d52602
--- /dev/null
+++ b/.zs/components/buttons.jq
@@ -0,0 +1,3 @@
+include ".zs/components/get_filename";
+
+map("<a href=\"\(.link)\"><img src=\"\($BUTTONS_DIR + (. | filename))\" alt=\"An 88x31 button. \(.alt)\" title=\"\(.title)\"></a>") | join("\n")
diff --git a/.zs/components/colors b/.zs/components/colors
new file mode 100755
index 0000000..92da42b
--- /dev/null
+++ b/.zs/components/colors
@@ -0,0 +1,2 @@
+#!/bin/sh
+jq -r -f .zs/components/colors.jq .zs/components/palette.json
diff --git a/.zs/components/colors.jq b/.zs/components/colors.jq
new file mode 100644
index 0000000..1b007cd
--- /dev/null
+++ b/.zs/components/colors.jq
@@ -0,0 +1,10 @@
+to_entries |
+map([
+ (.key | gsub("_"; "-")),
+ ("oklch(" + (.value | join(" ")) + ")")
+]) |
+# group_by(.[0] | gsub("-.*"; "")) |
+reduce .[] as $item ([]; .[if ($item[0] | test("fg|bg|border")) then 0 else 1 end] += [$item]) |
+map(reduce .[] as $item ({}; .[$item[0] | gsub("-.*"; "")] += [$item])) |
+map(map(map("<li style=\"background-color: var(--\(.[0]))\"\(if (.[0] | test("bg|border")) then " class=\"fg-light\"" else "" end)><div class=\"color_name\">\(.[0])</div><div class=\"color_value\">\(.[1])</div></li>") | "<ol>" + join("") + "</ol>") | "<div>" + join("") + "</div>" ) |
+join("\n")
diff --git a/.zs/components/dl_buttons.jq b/.zs/components/dl_buttons.jq
new file mode 100644
index 0000000..0aeeca3
--- /dev/null
+++ b/.zs/components/dl_buttons.jq
@@ -0,0 +1,3 @@
+include ".zs/components/get_filename";
+
+map("\(.image) \(. | filename)") | join("\n")
diff --git a/.zs/components/footer b/.zs/components/footer
new file mode 100755
index 0000000..570f714
--- /dev/null
+++ b/.zs/components/footer
@@ -0,0 +1,91 @@
+#!/usr/bin/lua
+
+package.path = ".zs/?.lua;" .. package.path
+local html = require "components.html"
+
+local date = os.date("!%Y-%m-%dT%H:%M:%S%Z")
+
+print(html {
+ tag = "footer",
+ {
+ tag = "div",
+ {
+ tag = "span",
+ {
+ tag = "a",
+ class = "volatile",
+ href = "https://ring.acab.dev/prev/C1NMCp8IXr",
+ title = "go to the previous page in the webring",
+ "[<<]"
+ }
+ },
+ {
+ tag = "span",
+ {
+ tag = "a",
+ class = "volatile",
+ href = "https://ring.acab.dev/prev/C1NMCp8IXr",
+ title = "go to a random page in the webring",
+ "[<<]"
+ }
+ },
+ {
+ tag = "span",
+ {
+ tag = "a",
+ class = "volatile",
+ href = "https://ring.acab.dev",
+ title = "hacker webring",
+ "[⠠⠵ ]"
+ }
+ },
+ {
+ tag = "span",
+ {
+ tag = "a",
+ class = "volatile",
+ href = "https://ring.acab.dev/next/C1NMCp8IXr",
+ title = "go to the next page in the webring",
+ "[>>]"
+ }
+ },
+ },
+ {
+ tag = "div",
+ {
+ tag = "span",
+ "made with ",
+ {
+ tag = "span",
+ style = "color: var(--red)",
+ "<3"
+ },
+ " by darkuss"
+ },
+ {
+ tag = "span",
+ {
+ tag = "a",
+ href = "/credits.html",
+ "credits"
+ }
+ },
+ {
+ tag = "span",
+ {
+ tag = "a",
+ href = "/privacy.html",
+ "privacy"
+ }
+ },
+ {
+ tag = "span",
+ "last modified: ",
+ {
+ tag = "time",
+ datetime = date,
+ date
+ }
+ }
+ }
+})
diff --git a/.zs/components/get_filename.jq b/.zs/components/get_filename.jq
new file mode 100644
index 0000000..9b5754c
--- /dev/null
+++ b/.zs/components/get_filename.jq
@@ -0,0 +1 @@
+def filename: .file + (.image | match("\\.[0-9a-z]+$") | .string);
diff --git a/.zs/components/html.lua b/.zs/components/html.lua
new file mode 100644
index 0000000..1355905
--- /dev/null
+++ b/.zs/components/html.lua
@@ -0,0 +1,152 @@
+-- This is taken from http://lua-users.org/wiki/SortedIteration
+-- This version is stripped of comments and empty lines + some stuff is renamed
+
+local function cmp(op1, op2)
+ local type1, type2 = type(op1), type(op2)
+ if type1 ~= type2 then --cmp by type
+ return type1 < type2
+ elseif type1 == "number" or type1 == "string" then --type2 is equal to type1
+ return op1 < op2 --comp by default
+ elseif type1 == "boolean" then
+ return op1 == true
+ else
+ return tostring(op1) < tostring(op2) --cmp by address
+ end
+end
+
+local function __gen_oindex(t)
+ local oindex = {}
+ for key in pairs(t) do
+ table.insert(oindex, key)
+ end
+ table.sort(oindex, cmp)
+ return oindex
+end
+
+local function onext(t, state)
+ local key = nil
+ if state == nil then
+ t.__oindex = __gen_oindex(t)
+ key = t.__oindex[1]
+ else
+ for i = 1, #t.__oindex do
+ if t.__oindex[i] == state then
+ key = t.__oindex[i + 1]
+ end
+ end
+ end
+ if key then
+ return key, t[key]
+ end
+ t.__oindex = nil
+end
+
+local function opairs(t)
+ return onext, t, nil
+end
+
+local html = {}
+
+---@alias Node { tag: string?, [string|number]: any }
+
+local entities = {
+ { "&", "&amp;" },
+ { "<", "&lt;" },
+ { ">", "&gt;" },
+ { [["]], "&quot;" },
+ { "'", "&#x27;" },
+}
+
+local void_tags = {
+ area = true,
+ base = true,
+ br = true,
+ col = true,
+ embed = true,
+ hr = true,
+ img = true,
+ input = true,
+ link = true,
+ meta = true,
+ source = true,
+ track = true,
+ wbr = true,
+}
+
+local function key_length(t)
+ local n = 0
+ for k in pairs(t) do
+ if type(k) == "string" then
+ n = n + 1
+ end
+ end
+ return n
+end
+
+---@param content string
+function html.sanitize(content)
+ for _, pair in ipairs(entities) do
+ content = content:gsub(pair[1], pair[2])
+ end
+
+ return content
+end
+
+---@param node Node
+function html.render(node)
+ local state = {}
+
+ local function push(value)
+ table.insert(state, tostring(value))
+ end
+
+ if node.tag then
+ push "<"
+ push(node.tag)
+
+ for attr, value in opairs(node) do
+ if type(attr) == "string" and attr ~= "tag" then
+ push " "
+ push(attr)
+ if value ~= "" then
+ push [[="]]
+ push(html.sanitize(type(value) == "string" and value or tostring(value)))
+ push [["]]
+ end
+ end
+ end
+
+ push ">"
+ elseif key_length(node) > 0 then
+ error("cannot set attributes on a list of values", 2)
+ end
+
+ if void_tags[node.tag] and #node > 0 then
+ error("'" .. node.tag .. "' is a void tag and cannot have children", 2)
+ end
+
+ for _, value in ipairs(node) do
+ local type = type(value)
+ if type == "string" then
+ push(html.sanitize(value))
+ elseif type == "table" then
+ push(html.render(value))
+ else
+ push(html.sanitize(tostring(value)))
+ end
+ end
+
+ if not void_tags[node.tag] and node.tag then
+ push "</"
+ push(node.tag)
+ push ">"
+ end
+
+ return table.concat(state, "")
+end
+
+return setmetatable(html, {
+ __call = function(_, ...)
+ return html.render(...)
+ end,
+})
diff --git a/.zs/components/nav b/.zs/components/nav
new file mode 100755
index 0000000..9ec3453
--- /dev/null
+++ b/.zs/components/nav
@@ -0,0 +1,63 @@
+#!/usr/bin/lua
+
+package.path = ".zs/?.lua;" .. package.path
+local html = require "components.html"
+
+---@class Link
+---@field url string
+---@field title string
+---@field index boolean?
+
+---@type Link[]
+local links = {
+ {
+ url = "/",
+ title = "home",
+ },
+ {
+ url = "/projects.html",
+ title = "projects"
+ },
+ {
+ url = "/posts.html",
+ title = "ramblings"
+ },
+ {
+ url = "/rss.xml",
+ title = "rss"
+ }
+}
+
+local function get_file_stem(path)
+ return path
+ :gsub(".[^.]*$", "") -- get rid of ext
+ :gsub(".*/", "") -- get rid of prefix
+end
+
+local current_file = get_file_stem(os.getenv("ZS_FILE"))
+
+local acc = {}
+
+for _, link in ipairs(links) do
+ local title = link.title
+ if current_file == get_file_stem(link.url) or current_file == "index" and link.url == "/" then
+ title = "[" .. title .. "]"
+ end
+
+ table.insert(acc, {
+ tag = "li",
+ {
+ tag = "a",
+ href = link.url,
+ title
+ }
+ })
+end
+
+print(html {
+ tag = "nav",
+ {
+ tag = "ul",
+ acc
+ }
+})
diff --git a/.zs/components/palette.json b/.zs/components/palette.json
new file mode 100644
index 0000000..56b1944
--- /dev/null
+++ b/.zs/components/palette.json
@@ -0,0 +1,132 @@
+{
+ "fg_low": {
+ "l": "75%",
+ "c": "0.01368",
+ "h": "253.09"
+ },
+ "fg": {
+ "l": "85%",
+ "c": "0.01368",
+ "h": "253.09"
+ },
+ "fg_high": {
+ "l": "95%",
+ "c": "0.01368",
+ "h": "253.09"
+ },
+ "bg_lowest": {
+ "l": "15%",
+ "c": "0.01368",
+ "h": "253.09"
+ },
+ "bg_low": {
+ "l": "17.5%",
+ "c": "0.01368",
+ "h": "253.09"
+ },
+ "bg": {
+ "l": "20%",
+ "c": "0.01368",
+ "h": "253.09"
+ },
+ "bg_high": {
+ "l": "22.5%",
+ "c": "0.01368",
+ "h": "253.09"
+ },
+ "bg_highest": {
+ "l": "25%",
+ "c": "0.01368",
+ "h": "253.09"
+ },
+ "border": {
+ "l": "35%",
+ "c": "0.023",
+ "h": "253.09"
+ },
+ "border_variant": {
+ "l": "30%",
+ "c": "0.023",
+ "h": "253.09"
+ },
+ "red": {
+ "l": "80%",
+ "c": "0.15765",
+ "h": "24.728"
+ },
+ "red_bright": {
+ "l": "90%",
+ "c": "0.15765",
+ "h": "24.728"
+ },
+ "orange": {
+ "l": "80%",
+ "c": "0.139",
+ "h": "45.216"
+ },
+ "orange_bright": {
+ "l": "90%",
+ "c": "0.139",
+ "h": "45.216"
+ },
+ "yellow": {
+ "l": "80%",
+ "c": "0.12758",
+ "h": "76.402"
+ },
+ "yellow_bright": {
+ "l": "90%",
+ "c": "0.12758",
+ "h": "76.402"
+ },
+ "green": {
+ "l": "80%",
+ "c": "0.11211",
+ "h": "147.63"
+ },
+ "green_bright": {
+ "l": "90%",
+ "c": "0.11211",
+ "h": "147.63"
+ },
+ "cyan": {
+ "l": "80%",
+ "c": "0.09919",
+ "h": "181.49"
+ },
+ "cyan_bright": {
+ "l": "90%",
+ "c": "0.09919",
+ "h": "181.49"
+ },
+ "blue": {
+ "l": "80%",
+ "c": "0.09994",
+ "h": "249.58"
+ },
+ "blue_bright": {
+ "l": "90%",
+ "c": "0.09994",
+ "h": "249.58"
+ },
+ "purple": {
+ "l": "80%",
+ "c": "0.09923",
+ "h": "296.61"
+ },
+ "purple_bright": {
+ "l": "90%",
+ "c": "0.09923",
+ "h": "296.61"
+ },
+ "pink": {
+ "l": "80%",
+ "c": "0.06662",
+ "h": "9.2146"
+ },
+ "pink_bright": {
+ "l": "90%",
+ "c": "0.06662",
+ "h": "9.2146"
+ }
+}
diff --git a/.zs/components/stylua.toml b/.zs/components/stylua.toml
new file mode 100644
index 0000000..5cc0b69
--- /dev/null
+++ b/.zs/components/stylua.toml
@@ -0,0 +1,5 @@
+call_parentheses = "None"
+indent_type = "Spaces"
+
+[sort_requires]
+enabled = true