1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#!/usr/bin/lua
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?
---@field icon string
---@type Link[]
local links = {
{
url = "/",
title = "home",
inside = set {
"index"
},
icon = "home"
},
{
url = "/projects.html",
title = "projects",
inside = set {
"prismite"
},
icon = "git"
},
{
url = "/posts.html",
title = "ramblings",
dir = "blog",
icon = "notebook"
},
{
url = "/buttons.html",
title = "buttons",
icon = "external"
},
}
---@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,
{
tag = "div",
style = [[mask-image: url("/assets/svg/]] .. link.icon .. [[.svg")]]
},
{
tag = "span",
title
}
}
})
end
print(html {
tag = "nav",
{
tag = "ul",
acc
},
})
|