You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.0 KiB
74 lines
2.0 KiB
#!/usr/bin/env lua
|
|
local sitelib = require "sitelib"
|
|
local fs = require "lfs"
|
|
local tags = {}
|
|
|
|
if not fs.attributes(sitelib.outpath.."/tag") then
|
|
fs.mkdir(sitelib.outpath.."/tag")
|
|
end
|
|
|
|
print("Building list of markdown files")
|
|
local mdfiles = {}
|
|
local dqueue = {sitelib.srcpath}
|
|
for k,path in pairs(dqueue) do
|
|
for file in fs.dir(path) do
|
|
if file:sub(1,1) ~= "." then
|
|
local attr = fs.attributes(path.."/"..file)
|
|
if attr.mode == "directory" then
|
|
dqueue[#dqueue+1] = path.."/"..file
|
|
elseif file:sub(-3) == ".md" then
|
|
mdfiles[#mdfiles+1] = path.."/"..file
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
print("Reading tags...")
|
|
for k,infile in pairs(mdfiles) do
|
|
local f = io.open(infile,"rb")
|
|
local c = f:read("*a")
|
|
f:close()
|
|
local page = sitelib.parsepage(c)
|
|
if page.tags then
|
|
print((infile:sub(sitelib.srcpath:len()+1)):sub(1,-4)..".html")
|
|
for w in page.tags:gmatch("%S+") do
|
|
tags[w] = tags[w] or {}
|
|
table.insert(tags[w],{(infile:sub(sitelib.srcpath:len()+1)):sub(1,-4)..".html",page.title,page.md:match("\n\n(.-)\n")})
|
|
end
|
|
end
|
|
end
|
|
|
|
print("Writing individual tag indexes...")
|
|
for tag,v in pairs(tags) do
|
|
local f = io.open(sitelib.outpath.."/tag/"..tag..".html","wb")
|
|
f:write("<html><head><title>Tag: "..tag.."</title>\n")
|
|
f:write(sitelib.header)
|
|
f:write("<h1>Tag: "..tag.."</h1>\n")
|
|
for l,m in pairs(v) do
|
|
f:write("<h3><a href=\""..m[1].."\">"..m[2].."</a></h3>\n")
|
|
local fline = m[3]:gsub("\"","\\\"")
|
|
f:write(io.popen("echo \""..fline.."\" | markdown -"):read("*a"))
|
|
end
|
|
f:write(sitelib.footer)
|
|
f:close()
|
|
end
|
|
|
|
print("Writing overall tag index...")
|
|
local ti = {}
|
|
for tag, v in pairs(tags) do
|
|
ti[#ti+1] = tag
|
|
end
|
|
table.sort(ti)
|
|
local f = io.open(sitelib.outpath.."/tag/index.html","wb")
|
|
f:write("<html><head><title>Tag Index</title>\n")
|
|
f:write(sitelib.header)
|
|
f:write("<h1>Tag index</h1>\n")
|
|
for k,v in pairs(ti) do
|
|
if #tags[v] > 1 then
|
|
f:write("<h3><a href=\""..v..".html\">"..v.."</a> ("..#tags[v].." entries)</h3>\n")
|
|
else
|
|
f:write("<h3><a href=\""..v..".html\">"..v.."</a> ("..#tags[v].." entry)</h3>\n")
|
|
end
|
|
end
|
|
f:write(sitelib.footer)
|
|
f:close()
|
|
|