summaryrefslogtreecommitdiff
path: root/.zs/components/nav
diff options
context:
space:
mode:
Diffstat (limited to '.zs/components/nav')
-rwxr-xr-x.zs/components/nav48
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
- }
+ },
})