diff --git a/graph.lua b/graph.lua new file mode 100755 index 0000000..3a03a11 --- /dev/null +++ b/graph.lua @@ -0,0 +1,50 @@ +#!/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 + +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 + +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}) + end + end +end + +local haslabel = {} +print("graph blog {") +for tag,v in pairs(tags) do + for l,m in pairs(v) do + if not haslabel[m[1]:match("(%d+).html")] then + print(m[1]:match("(%d+).html").." [label=\""..m[2]:gsub("\"","").."\"];") + haslabel[m[1]:match("(%d+).html")] = true + end + print(tag:gsub("-","").." -- "..m[1]:match("(%d+).html")..";") + end +end +print("}") diff --git a/tags.lua b/tags.lua new file mode 100755 index 0000000..5cfb55d --- /dev/null +++ b/tags.lua @@ -0,0 +1,54 @@ +#!/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("Tag: "..tag.."\n") + f:write(sitelib.header) + f:write("

Tag: "..tag.."

\n") + for l,m in pairs(v) do + f:write("

"..m[2].."

\n") + local fline = m[3]:gsub("\"","\\\"") + f:write(io.popen("echo \""..fline.."\" | markdown -"):read("*a")) + end + f:write(sitelib.footer) + f:close() +end