#!/usr/bin/lua package.path = ".zs/?.lua;" .. package.path local html = require "components.html" ---@alias Set table ---@param t any[] ---@return Set local function set(t) local tmp = {} for _, value in ipairs(t) do tmp[value] = true end return tmp end ---@class Link ---@field url string ---@field title string ---@field index boolean? ---@field dir string? ---@field inside Set? ---@type Link[] local links = { { url = "/", title = "home", inside = set { "index" } }, { url = "/projects.html", title = "projects", inside = set { "prismite" } }, { url = "/posts.html", title = "ramblings", dir = "blog" }, { url = "/buttons.html", title = "buttons" }, { url = "/rss.xml", title = "rss" } } ---@param path string ---@return string, integer local function get_file_stem(path) return path :gsub(".[^.]*$", "") -- get rid of ext :gsub(".*/", "") -- get rid of prefix end local current_path = assert(os.getenv("ZS_FILE")) local current_file = get_file_stem(current_path) local acc = {} for _, link in ipairs(links) do local title = link.title local class = "tab" if current_file == get_file_stem(link.url) or link.inside and link.inside[current_file] or link.dir and current_path:match(link.dir .. "/") ~= nil then class = class .. " active" end table.insert(acc, { tag = "li", class = class, { tag = "a", href = link.url, title, } }) end print(html { tag = "nav", { tag = "ul", acc }, })