diff options
| author | delta <darkussdelta@gmail.com> | 2026-07-25 11:42:01 +0200 |
|---|---|---|
| committer | delta <darkussdelta@gmail.com> | 2026-07-25 11:43:48 +0200 |
| commit | 95ceed33d3adec472f4a1b5d3517baf645766e44 (patch) | |
| tree | 94d8779483e49f7afe624a15e9d271e6f8fbe430 /.zs/components/nav | |
| parent | ae36b044f1fc36cd5587b0d3111c2ee72cf0c03f (diff) | |
site rework!!
Diffstat (limited to '.zs/components/nav')
| -rwxr-xr-x | .zs/components/nav | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/.zs/components/nav b/.zs/components/nav index 9ec3453..e2ff283 100755 --- a/.zs/components/nav +++ b/.zs/components/nav @@ -3,24 +3,49 @@ package.path = ".zs/?.lua;" .. package.path local html = require "components.html" +---@alias Set table<any, true> + +---@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" + title = "projects", + inside = set { + "prismite" + } }, { url = "/posts.html", - title = "ramblings" + title = "ramblings", + dir = "blog" + }, + { + url = "/buttons.html", + title = "buttons" }, { url = "/rss.xml", @@ -28,28 +53,37 @@ local links = { } } +---@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_file = get_file_stem(os.getenv("ZS_FILE")) +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 - if current_file == get_file_stem(link.url) or current_file == "index" and link.url == "/" then - title = "[" .. 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 + title, } }) end @@ -59,5 +93,5 @@ print(html { { tag = "ul", acc - } + }, }) |
