Commit notifications for all Sup repositories
 help / color / mirror / Atom feed
From: Dan Callaghan <dan@bl2.djc.id.au>
To: sup-commits@supmua.dev
Subject: [sup-website.git] 02/02: page speed improvements for web fonts
Date: Tue, 20 Oct 2026 22:12:29 +1100	[thread overview]
Message-ID: <20261020111227.4AB8C29E562@bl2.djc.id.au> (raw)
In-Reply-To: <179249474702.410425.13909296270284011709@bl2.djc.id.au>

New commit on branch master:
https://supmua.dev/git/sup-website/commit/78e88eb6513df2b734d072c74485d4403593f687.html

commit 78e88eb6513df2b734d072c74485d4403593f687
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Tue Oct 20 22:03:37 2026 +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.
---
 _plugins/webfonts.rb         | 38 ++++++++++++++++++++++++++++----------
 fonts/.htaccess              |  1 +
 stylesheets/public-inbox.css |  5 +++--
 stylesheets/stylesheet.css   |  5 +++--
 4 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/_plugins/webfonts.rb b/_plugins/webfonts.rb
index 85277e7..092cd2f 100644
--- 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
new file mode 100644
index 0000000..d600afd
--- /dev/null
+++ 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
index 2015385..174e851 100644
--- 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
index 0a22b15..81464ea 100644
--- 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;

      parent reply	other threads:[~2026-10-20 11:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 11:12 [sup-website.git] branch master updated (b791e6e -> 78e88eb) Dan Callaghan
2026-10-20 11:12 ` [sup-website.git] 01/02: set img width and height Dan Callaghan
2026-10-20 11:12 ` Dan Callaghan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261020111227.4AB8C29E562@bl2.djc.id.au \
    --to=dan@bl2.djc.id.au \
    --cc=djc@djc.id.au \
    --cc=sup-commits@supmua.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox