sup

A curses threads-with-tags style email client

sup-website.git

git clone https://supmua.dev/git/sup-website/
commit 0d4ba05cae90ab6a8fa6c883acfe3649c755be23
parent 918eb2b7e806e852ad876c17168015794eda63b8
Author: Dan Callaghan <djc@djc.id.au>
Date:   Wed,  1 Apr 2026 21:52:23 +1100

linkify issue references in stagit commit message bodies

Diffstat:
M _plugins/stagit.rb | 69 +++++++++++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 45 insertions(+), 24 deletions(-)
diff --git a/_plugins/stagit.rb b/_plugins/stagit.rb
@@ -1,39 +1,60 @@
 require 'fileutils'
 require 'nokogiri'
 
+def wrap_stagit_output path, header
+  doc = Nokogiri::HTML(File.read(path))
+
+  ## Change git repo name from h1 to h2
+  h = doc.at("h1")
+  h.name = "h2"
+  h.content = "# #{h.content}.git"
+
+  ## Put the git repo name, clone URL, and stagit navigation into a container
+  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
+
+  ## Put the stagit main body into another container
+  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 = doc.at("body")
+  body.children.remove
+  body << header << nav_section << main_section
+
+  ## Fix the stylesheet and add dummy favion like _layouts/default.md
+  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=">'
+
+  ## Rewrite commit message issue references to be links
+  doc.xpath("//pre[b[normalize-space()='commit' and not(preceding-sibling::node())]]//text()").each do |text_node|
+    rewritten = text_node.content.gsub(/(?<=^|\s)#(\d+)\b/) do |match|
+      "<a href=\"https://github.com/sup-heliotrope/sup/issues/#{$1}\">#{$&}</a>"
+    end
+    text_node.replace rewritten
+  end
+
+  File.write(path, doc.to_html)
+end
+
 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)
+      wrap_stagit_output path, header unless path.include? "/raw/"
     end
   end
 end