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
|
#!/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
}
})
|