maivi.router:add("/", maivi.mod("pages.index"), {}) ---@diagnostic disable-next-line: global-in-non-module H = require("helpers") ---@class Section ---@field stub string ---@field path string ---@field url string ---@field header boolean ---@field section string ---@field id string ---@field content? string ---@type Section[] maivi.data.sections = {} for file, data in pairs(this.data) do if string.sub(file, 1, 1) == "/" then file = string.sub(file, 2) end assert(string.sub(file, 1, 4) == "data") -- file: data/path/to/00-file.ext -- url: <-------------> local url = H.stripend(string.sub(file, #"data/"), "%.") -- url: /path/to/00-url -- stub: <----> data.stub = H.subafter(url, "/") data.path = file data.url = url data.header = false -- stub: 00--url-- -- section: <-> if string.sub(data.stub, 4, 4) == "-" then data.header = true end -- stub: 00-url -- section: <-> if not data.section then if data.header then data.section = string.sub(data.stub, 5, -3) else data.section = string.sub(data.stub, 4) end ---@diagnostic disable-next-line: cast-type-mismatch ---@cast data.section string data.section = string.gsub(data.section, "%-", " ") end data.id = string.gsub(string.sub(url, 2), "/", "-") if string.sub(data.path, -4) ~= ".txt" then ---@diagnostic disable-next-line: undefined-global local contents = read(data.path) if string.sub(contents, 0, 3) == "+++" then contents = string.gsub(contents, "^+++.*+++", "") end if string.sub(data.path, -4) == ".lua" then local f = loadstring(contents, data.path) if not f then return end _, contents = pcall(f) end data.content = contents end -- maivi.print(data) data.pos = tonumber(string.sub(data.stub, 0, 2)) table.insert(maivi.data.sections, data) end table.sort(maivi.data.sections, function(a, b) if not a.pos or not b.pos then return a.pos ~= nil end return a.pos < b.pos end)