summaryrefslogtreecommitdiff
path: root/generate-index.lua
diff options
context:
space:
mode:
Diffstat (limited to 'generate-index.lua')
-rwxr-xr-xgenerate-index.lua77
1 files changed, 77 insertions, 0 deletions
diff --git a/generate-index.lua b/generate-index.lua
new file mode 100755
index 0000000..65f7e14
--- /dev/null
+++ b/generate-index.lua
@@ -0,0 +1,77 @@
+#!/usr/bin/env lua
+local pretty = require"pl.pretty"
+local dir = require"pl.dir"
+local gumbo = require"gumbo"
+local months = {
+ "January",
+ "February",
+ "March",
+ "April",
+ "May",
+ "June",
+ "July",
+ "August",
+ "September",
+ "October",
+ "November",
+ "December",
+}
+
+
+local function parse (stamp)
+ local year, month, day = stamp:match"(%d+)-(%d?%d)-(%d?%d)T?"
+ year, month, day = tonumber(year), tonumber(month), tonumber(day)
+ if not year or not month or not day then
+ return nil
+ end
+ return {year=year, month=month, day=day}
+end
+
+
+local function describe (date)
+ return string.format("%d %s", date.day, months[date.month])
+end
+
+
+local pages = dir.getfiles(".", "*.html")
+local takeaways = {
+ ["published-on"] = "published",
+ ["last-modified-on"] = "modified",
+}
+local excludes = {
+ ["index.html"] = true,
+ ["graveyard_of_the_drawings.html"] = true,
+ ["plop.html"] = true,
+}
+local posts = {}
+for _, filename in pairs(pages) do
+ local document = gumbo.parseFile(filename)
+ local metas = document:getElementsByTagName"meta"
+ local properties = {title=document.title, filename=filename:sub(3), published=""}
+ for _, meta in ipairs(metas) do
+ local take = nil
+ for _, attribute in ipairs(meta.attributes) do
+ if attribute.name == "name" then
+ take = takeaways[attribute.value]
+ end
+ if take and attribute.name == "content" then
+ properties[take] = attribute.value
+ end
+ end
+ end
+ if properties.filename:match"^[^_]" and not excludes[properties.filename] then
+ table.insert(posts, properties)
+ end
+end
+table.sort(posts, function (lhs, rhs) return lhs.published > rhs.published end)
+print("<table>")
+local year = nil
+for _, page in pairs(posts) do
+ local date = parse(page.published)
+ if date and year ~= date.year then
+ year = date.year
+ print(string.format("<tr><td><b>%d</b><td><td>", year))
+ end
+ print(string.format([[<tr><td>%s<td class="sep">•<td><a href="%s">%s</a>]], describe(date), page.filename, page.title))
+end
+print("</table>")