From 581de1e3c688ef9b4e0e4a13aabe1ad63d5762f0 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 24 Jan 2023 00:26:41 +0100 Subject: Sketch that appends elements to head --- head.html.in | 5 +++++ huh.conf | 1 + huh.lua | 21 +++++++++++++++++++++ sample.html | 11 +++++++++++ 4 files changed, 38 insertions(+) create mode 100644 head.html.in create mode 100644 huh.conf create mode 100755 huh.lua create mode 100644 sample.html diff --git a/head.html.in b/head.html.in new file mode 100644 index 0000000..bc713fc --- /dev/null +++ b/head.html.in @@ -0,0 +1,5 @@ + + + + + diff --git a/huh.conf b/huh.conf new file mode 100644 index 0000000..c9ed62e --- /dev/null +++ b/huh.conf @@ -0,0 +1 @@ +head = head.html.in diff --git a/huh.lua b/huh.lua new file mode 100755 index 0000000..8f834ab --- /dev/null +++ b/huh.lua @@ -0,0 +1,21 @@ +#!/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: + (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 new file mode 100644 index 0000000..016c528 --- /dev/null +++ b/sample.html @@ -0,0 +1,11 @@ + + + +Sample Article +
+

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 <title> is treated as the article content, meaning the +<article> element is not mandatory at all. Additionally, anything before the +<title> element is added to the head of the output HTML document. +

I don't think I quite like how this looks like at the moment. +

-- cgit v1.1