sup

A curses threads-with-tags style email client

sup-website.git

git clone https://supmua.dev/git/sup-website/
commit 78e88eb6513df2b734d072c74485d4403593f687
parent 3a421b62231db4c4ddc590b51ee9078fc46914bc
Author: Dan Callaghan <djc@djc.id.au>
Date:   Tue, 20 Oct 2026 22:03:37 +1100

page speed improvements for web fonts

Avoid CSS @import which requires extra critical path HTTP requests. Make
the Jekyll plugin inline it into the stylesheet instead.

Put WOFF files under a cache-busting URL named after the nix derivation
hash and give it infinite cache lifetime.

Diffstat:
M _plugins/webfonts.rb | 38 ++++++++++++++++++++++++++++----------
A fonts/.htaccess | 1 +
M stylesheets/public-inbox.css | 5 +++--
M stylesheets/stylesheet.css | 5 +++--
4 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/_plugins/webfonts.rb b/_plugins/webfonts.rb
@@ -1,13 +1,31 @@
-require 'fileutils'
 require 'open3'
 
-Jekyll::Hooks.register :site, :post_write do |site|
-  Jekyll.logger.info "Fonts:", "Building"
-  out, err, status = Open3.capture3 "nix-build", "_plugins/webfonts.nix", "--no-out-link"
-  raise "nix-build failed: #{err}" unless status.success?
-  result = out.strip
-  FileUtils.mkdir_p "#{site.dest}/fonts"
-  Dir["#{result}/*.css"].each { |f| FileUtils.cp f, "#{site.dest}/fonts" }
-  FileUtils.mkdir_p "#{site.dest}/fonts/WOFF2"
-  Dir["#{result}/WOFF2/*"].each { |f| FileUtils.cp f, "#{site.dest}/fonts/WOFF2" }
+# A static file copied from outside the site source (the Nix store)
+class WebfontFile < Jekyll::StaticFile
+  def initialize(site, source, dir)
+    super(site, site.source, dir, File.basename(source))
+    @source = source
+  end
+
+  def path
+    @source
+  end
+end
+
+class WebfontsGenerator < Jekyll::Generator
+  def generate(site)
+    Jekyll.logger.info "Fonts:", "Building"
+    out, err, status = Open3.capture3 "nix-build", "_plugins/webfonts.nix", "--no-out-link"
+    raise "nix-build failed: #{err}" unless status.success?
+    result = out.strip
+    # Serve fonts under the store path hash so their URLs can be cached forever
+    dir = "fonts/#{File.basename(result).split("-").first}"
+    Dir["#{result}/WOFF2/*"].each do |f|
+      site.static_files << WebfontFile.new(site, f, dir)
+    end
+    # Font CSS for stylesheets/stylesheet.css to include
+    site.data["webfonts_css"] = Dir["#{result}/*.css"].sort.map do |f|
+      File.read(f).gsub("url('WOFF2/", "url('../#{dir}/")
+    end.join
+  end
 end
diff --git a/fonts/.htaccess b/fonts/.htaccess
@@ -0,0 +1 @@
+Header set Cache-Control "public, max-age=31536000, immutable"
diff --git a/stylesheets/public-inbox.css b/stylesheets/public-inbox.css
@@ -1,5 +1,6 @@
-@import "../fonts/Iosevka.css";
-@import "../fonts/IosevkaAile.css";
+---
+---
+{{ site.data.webfonts_css }}
 body {
   background: #151515 url("/images/bkg.png") 0 0;
   color: #eaeaea;
diff --git a/stylesheets/stylesheet.css b/stylesheets/stylesheet.css
@@ -1,5 +1,6 @@
-@import "../fonts/Iosevka.css";
-@import "../fonts/IosevkaAile.css";
+---
+---
+{{ site.data.webfonts_css }}
 
 body {
   margin: 0;