summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-08-28 21:59:30 +0200
committerAki <please@ignore.pl>2024-08-28 21:59:30 +0200
commit56cea0dde53544380c8eb48357000b9a272ffbb1 (patch)
tree2adcc4625bf6a89c9ecf1cacff4ee17517fb548f
parent581de1e3c688ef9b4e0e4a13aabe1ad63d5762f0 (diff)
downloadhuh-56cea0dde53544380c8eb48357000b9a272ffbb1.zip
huh-56cea0dde53544380c8eb48357000b9a272ffbb1.tar.gz
huh-56cea0dde53544380c8eb48357000b9a272ffbb1.tar.bz2
Implemented a very specific generate-index script for the blog
-rw-r--r--Makefile15
-rwxr-xr-xgenerate-index.lua77
-rw-r--r--head.html.in5
-rw-r--r--huh.conf1
-rwxr-xr-xhuh.lua21
-rw-r--r--sample.html11
6 files changed, 92 insertions, 38 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..29f04cd
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,15 @@
+DESTDIR=
+PREFIX=/usr/local
+PREFIX_EXEC=$(PREFIX)
+BINDIR=$(PREFIX_EXEC)/bin
+
+all:
+ @echo nothing to do
+
+install:
+ install -m755 -DT generate-index.lua $(DESTDIR)$(BINDIR)/generate-index
+
+uninstall:
+ rm -f $(DESTDIR)$(BINDIR)/generate-index
+
+.PHONY: all install uninstall
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>")
diff --git a/head.html.in b/head.html.in
deleted file mode 100644
index bc713fc..0000000
--- a/head.html.in
+++ /dev/null
@@ -1,5 +0,0 @@
-<meta charset="utf-8">
-<meta name="viewport" content="width=device-width,initial-scale=1">
-<meta name="author" content="aki">
-<link rel="icon" type="image/png" href="favicon.png">
-<link rel="stylesheet" href="style.css">
diff --git a/huh.conf b/huh.conf
deleted file mode 100644
index c9ed62e..0000000
--- a/huh.conf
+++ /dev/null
@@ -1 +0,0 @@
-head = head.html.in
diff --git a/huh.lua b/huh.lua
deleted file mode 100755
index 8f834ab..0000000
--- a/huh.lua
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/env lua
-local gumbo = require "gumbo"
-local config = require "pl.config"
-local args = require "pl.lapp" [[
-Generates an HTML document from another HTML document (huh?).
-
-Options:
- -c, --config (default huh.conf) Configuration file
- -h, --help Prints this help message to standard output
-
-Arguments:
- <input> (optional string) HTML file to process
-]]
-local conf = assert(config.read(args.config))
-local document = assert(gumbo.parseFile(args.input or io.stdin))
-local head = assert(gumbo.parseFile(conf.head, {contextElement="head"}))
-for _, node in pairs(head.documentElement.childNodes) do
- document:adoptNode(node)
- document.head:insertBefore(node, document.head.firstChild)
-end
-document:serialize(io.stdout)
diff --git a/sample.html b/sample.html
deleted file mode 100644
index 016c528..0000000
--- a/sample.html
+++ /dev/null
@@ -1,11 +0,0 @@
-<!doctype html>
-<html>
-<meta name="tags" content="example">
-<title>Sample Article</title>
-<article>
-<p>With just this, you can start typing the article content. The header will be prepended according to the rules
-specified in the template. Anything after <code>&lt;title&gt;</code> is treated as the article content, meaning the
-<code>&lt;article&gt;</code> element is not mandatory at all. Additionally, anything before the
-<code>&lt;title&gt;</code> element is added to the head of the output HTML document.
-<p>I don't think I quite like how this looks like at the moment.
-</article>