From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by bl2.djc.id.au (Postfix, from userid 1000) id 4AB8C29E562; Tue, 20 Oct 2026 22:12:27 +1100 (AEDT) Date: Tue, 20 Oct 2026 22:12:29 +1100 To: sup-commits@supmua.dev Subject: [sup-website.git] 02/02: page speed improvements for web fonts MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Reply-To: Dan Callaghan In-Reply-To: <179249474702.410425.13909296270284011709@bl2.djc.id.au> References: <179249474702.410425.13909296270284011709@bl2.djc.id.au> Thread-Index: AQAAEjRWpjOEr+jNT3OmJP8ajA2dOA== X-Git-Host: bl2.djc.id.au X-Git-Repo: sup-website.git X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: 78e88eb6513df2b734d072c74485d4403593f687 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.7.dev Auto-Submitted: auto-generated Message-Id: <20261020111227.4AB8C29E562@bl2.djc.id.au> From: Dan Callaghan List-Id: New commit on branch master: https://supmua.dev/git/sup-website/commit/78e88eb6513df2b734d072c74485d4403593f687.html commit 78e88eb6513df2b734d072c74485d4403593f687 Author: Dan Callaghan 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;