commit 918eb2b7e806e852ad876c17168015794eda63b8
parent 3d06e1b9a1b5e8236362fbacd5f41b24f88523b6
Author: Dan Callaghan <djc@djc.id.au>
Date: Tue, 31 Mar 2026 22:31:23 +1100
add a Jekyll plugin to invoke stagit
Diffstat:
1 file changed, 39 insertions(+), 0 deletions(-)
diff --git a/_plugins/stagit.rb b/_plugins/stagit.rb
@@ -0,0 +1,39 @@
+require 'fileutils'
+require 'nokogiri'
+
+Jekyll::Hooks.register :site, :post_write do |site|
+ header = File.read "#{site.source}/_includes/header.html"
+ %w[sup sup-colors sup-website].each do |repo|
+ dest = "#{site.dest}/git/#{repo}"
+ Jekyll.logger.info "Stagit:", "Processing #{repo}"
+ FileUtils.mkdir_p dest
+ system "cd #{dest} && stagit -u https://supmua.dev/git/#{repo}/ /home/dan/src/#{repo}" or raise "stagit failed"
+ ## Munge stagit generate files to fit the rest of the site
+ Dir.glob "#{dest}/**/*.html", File::FNM_DOTMATCH do |path|
+ next if path.include? "/raw/"
+ doc = Nokogiri::HTML(File.read(path))
+ body = doc.at("body")
+ h = doc.at("h1")
+ h.name = "h2"
+ h.content = "# #{h.content}.git"
+ nav_section = doc.create_element "section", class: "container wide git" do |e|
+ e.add_child h
+ e.add_child doc.at(".url")
+ e.add_child doc.at("nav")
+ end
+ main_section = doc.create_element "main", class: "container wide git" do |e|
+ e.add_child doc.at("main").children
+ e.css("h2").each { |h| h.name = "h3" }
+ end
+ body.children.remove
+ body.add_child header
+ body.add_child nav_section
+ body.add_child main_section
+ stylesheet = doc.at_css('link[rel="stylesheet"]')
+ stylesheet["href"] = "/stylesheets/stylesheet.css"
+ stylesheet["media"] = "screen"
+ doc.at("head").add_child '<link rel="icon" href="data:image/png;base64,iVBORw0KGgo=">'
+ File.write(path, doc.to_html)
+ end
+ end
+end