summaryrefslogtreecommitdiff
path: root/.zs
diff options
context:
space:
mode:
Diffstat (limited to '.zs')
-rwxr-xr-x.zs/buttons2
-rw-r--r--.zs/buttons.jq1
-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.jq (renamed from .zs/generate_colors.jq)2
-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.json (renamed from .zs/palette.json)0
-rw-r--r--.zs/components/stylua.toml5
-rwxr-xr-x.zs/current_date3
-rwxr-xr-x.zs/generate_colors2
-rwxr-xr-x.zs/generate_nav28
-rw-r--r--.zs/layout.html18
-rwxr-xr-x.zs/posthook.highlight45
18 files changed, 385 insertions, 52 deletions
diff --git a/.zs/buttons b/.zs/buttons
deleted file mode 100755
index 9ea9460..0000000
--- a/.zs/buttons
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-cat buttons.json | jq -r -f .zs/buttons.jq
diff --git a/.zs/buttons.jq b/.zs/buttons.jq
deleted file mode 100644
index 833971a..0000000
--- a/.zs/buttons.jq
+++ /dev/null
@@ -1 +0,0 @@
-map("<a href=\"\(.link)\"><img src=\"\(.image)\" alt=\"An 88x31 button. \(.alt)\" title=\"\(.title)\"></a>") | join("\n")
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/generate_colors.jq b/.zs/components/colors.jq
index d61686a..1b007cd 100644
--- a/.zs/generate_colors.jq
+++ b/.zs/components/colors.jq
@@ -6,5 +6,5 @@ map([
# 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("<div 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></div>") | "<div>" + join("") + "</div>") | "<div>" + join("") + "</div>" ) |
+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/palette.json b/.zs/components/palette.json
index 56b1944..56b1944 100644
--- a/.zs/palette.json
+++ b/.zs/components/palette.json
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
diff --git a/.zs/current_date b/.zs/current_date
deleted file mode 100755
index 9b6fbbb..0000000
--- a/.zs/current_date
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-printf %s "$(date -u +%Y-%m-%dT%H:%M:%S%Z)"
diff --git a/.zs/generate_colors b/.zs/generate_colors
deleted file mode 100755
index 7ade457..0000000
--- a/.zs/generate_colors
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-cat .zs/palette.json | jq -r -f .zs/generate_colors.jq
diff --git a/.zs/generate_nav b/.zs/generate_nav
deleted file mode 100755
index 0859a42..0000000
--- a/.zs/generate_nav
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/sh
-
-echo "/:home /projects.html:projects /posts.html:ramblings" | awk '
-function normalize(file) {
- sub(".[^.]*$", "", file)
- sub(".*/", "", file)
- return file
-}
-
-{
- for (i=1; i<=NF; i++) {
- match($i, /:.+/)
- name = substr($i, RSTART+1, RLENGTH)
-
- match($i, /.+:/)
- file = substr($i, RSTART, RLENGTH-1)
-
- parsed_file = ENVIRON["ZS_FILE"]
-
- if (normalize(file) == normalize(parsed_file) || (normalize(parsed_file) == "index" && file == "/")) {
- name = sprintf("[%s]", name)
- }
-
- printf "<li><a href=\"%s\">%s</a></li>", file, name
- if (i<NF) print ""
- }
- printf "<li><a href=\"/rss.xml\">[rss]</a></li>", file, name
-}'
diff --git a/.zs/layout.html b/.zs/layout.html
index fe8910e..21ccc0b 100644
--- a/.zs/layout.html
+++ b/.zs/layout.html
@@ -28,23 +28,11 @@
<div id="rainbow"></div>
<div id="triangles"></div>
</div>
- <div id="upper">
- <nav>
- <ul>
- {{ generate_nav }}
- </ul>
- </nav>
+ <div id="upper" role="presentation">
+ {{ .zs/components/nav }}
<div>
<main><div>{{ content }}</div></main>
- <footer class="subtle">
- <div>
- <span><a class="volatile" href="https://ring.acab.dev/prev/C1NMCp8IXr">[<<]</a></span><span><a class="volatile" href="https://ring.acab.dev/rand/C1NMCp8IXr">[random]</a></span><span><a href="https://ring.acab.dev">[⠠⠵ ]</a></span><span><a class="volatile" href="https://ring.acab.dev/next/C1NMCp8IXr">[>>]</a></span>
- </div>
- <div>
- <span>made with <span style="color: var(--red)">&lt;3</span> by darkuss</span><span><a href="/credits.html">credits</a></span
- ><span>last modified: <time datetime="{{ current_date }}">{{ current_date }}</time></span>
- </div>
- </footer>
+ {{ .zs/components/footer }}
</div>
</div>
</body>
diff --git a/.zs/posthook.highlight b/.zs/posthook.highlight
new file mode 100755
index 0000000..f1f2b74
--- /dev/null
+++ b/.zs/posthook.highlight
@@ -0,0 +1,45 @@
+#!/usr/bin/env lua
+
+-- local yah_bin = io.open("yah/target/release/yah", "r")
+-- if yah_bin then
+-- yah_bin:close()
+-- else
+-- os.execute("cd yah && cargo build --release")
+-- end
+--
+-- local _handle = assert(io.popen("find '" .. os.getenv("ZS_OUTDIR") .. "' -type f -name '*.html' -print0"))
+-- ---@type string
+-- local _files = _handle:read("*a")
+-- _handle:close()
+--
+-- local tmp = os.tmpname()
+-- for file in _files:gmatch("(.-)\0") do
+-- local handle = assert(io.open(file, "r+"))
+-- ---@type string
+-- local content = handle:read("*a")
+-- content:gsub([[<pre><code class="language%-(.-)">(.-)</code></pre>]], function(lang, code)
+--
+-- local tmp_handle = assert(io.open(tmp, "w+"))
+-- tmp_handle:write(code):close()
+--
+-- local yah, err = io.popen([[yah/target/release/yah "]] .. lang .. [[" "]] .. tmp .. [["]], "r")
+-- if err then
+-- return [[<div class="yah_error">FAILED TO PARSE FILE, (ERR: ]] .. err .. [[)</div>]]
+-- end
+-- assert(yah)
+--
+-- ---@type string
+-- local out = yah:read("*a")
+-- print(lang, tmp)
+-- print(out)
+--
+-- yah:close()
+--
+-- return [[<pre><code data-lang="]] .. lang .. [[">]] .. out .. [[</code></pre>]]
+-- end)
+-- -- print(content)
+-- handle:close()
+-- -- handle:seek("set")
+-- -- handle:write(content):close()
+-- end
+-- -- os.remove(tmp)