81 lines
1.6 KiB
Lua
81 lines
1.6 KiB
Lua
-- get all the filenames in order
|
|
local handle = assert(io.open("basement.order", "r"))
|
|
local line = handle:read("*line")
|
|
local allfiles = {}
|
|
while line do
|
|
table.insert(allfiles, line)
|
|
line = handle:read("*line")
|
|
end
|
|
handle:close()
|
|
|
|
|
|
-- handle each file
|
|
-- TODO populate this with all docs for manipulation later
|
|
local docs = {}
|
|
for _, value in pairs(allfiles) do
|
|
local matter = {}
|
|
local body = {}
|
|
local sepcount = 0
|
|
local handle = assert(io.open(value, "r"))
|
|
local line = handle:read("*line")
|
|
while line do
|
|
if line == '---' then
|
|
sepcount = sepcount + 1
|
|
-- get frontmatter
|
|
elseif sepcount < 2 then
|
|
for k, v in line:gmatch("(%w+):%s*(%w+)") do
|
|
matter[k] = v
|
|
end
|
|
-- get body
|
|
else
|
|
table.insert(body, line)
|
|
end
|
|
line = handle:read("*line")
|
|
end
|
|
handle:close()
|
|
table.insert(body, "\n")
|
|
|
|
table.insert(docs, { matter = matter, body = body })
|
|
end
|
|
|
|
-- print everything
|
|
for _, doc in ipairs(docs) do
|
|
for k, v in pairs(doc.matter) do
|
|
print(k .. " = " .. v)
|
|
end
|
|
for _, v in ipairs(doc.body) do
|
|
print(v)
|
|
end
|
|
end
|
|
|
|
|
|
-- markdown with spoilers
|
|
for _, doc in ipairs(docs) do
|
|
for _, v in ipairs(doc.body) do
|
|
print(v)
|
|
end
|
|
end
|
|
|
|
|
|
-- markdown spoilers free
|
|
for _, doc in ipairs(docs) do
|
|
if doc.matter.spoilers == "no" then
|
|
for _, v in ipairs(doc.body) do
|
|
print(v)
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
-- only syndicated
|
|
for _, doc in ipairs(docs) do
|
|
if doc.matter.syndicated == "yes" then
|
|
for k, v in pairs(doc.matter) do
|
|
print(k .. " = " .. v)
|
|
end
|
|
for _, v in ipairs(doc.body) do
|
|
print(v)
|
|
end
|
|
end
|
|
end
|