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: responsive screenshots with optimised half and quarter size versions
Date: Wed, 21 Oct 2026 21:06:53 +1100	[thread overview]
Message-ID: <20261021100652.0914329ECCB@bl2.djc.id.au> (raw)
In-Reply-To: <179257721178.417880.13737775410477211911@bl2.djc.id.au>

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

commit 1238c539ae7734ea55e2602f31285f5a467a8c0a
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Wed Oct 21 21:00:32 2026 +1100

    responsive screenshots with optimised half and quarter size versions
---
 _plugins/responsive_images.rb | 75 +++++++++++++++++++++++++++++++++++++++++++
 index.md                      |  2 +-
 screenshots/index.md          | 14 ++++----
 3 files changed, 83 insertions(+), 8 deletions(-)

diff --git a/_plugins/responsive_images.rb b/_plugins/responsive_images.rb
new file mode 100644
index 0000000..94410ea
--- /dev/null
+++ b/_plugins/responsive_images.rb
@@ -0,0 +1,75 @@
+require 'open3'
+
+def run_command *args
+  out, err, status = Open3.capture3 *args
+  raise "#{args.first} failed: #{err}" unless status.success?
+  out
+end
+
+class ResizedImage < Jekyll::StaticFile
+  def initialize site, dir, name, source, width
+    super site, site.source, dir, name
+    @source = source
+    @width = width
+  end
+
+  def path
+    @source
+  end
+
+  def write dest
+    dest_path = destination dest
+    Jekyll.logger.info "Resizing:", dest_path
+    FileUtils.mkdir_p File.dirname(dest_path)
+    run_command "magick", @source, "-resize", "#{@width}x", dest_path
+    run_command "pngquant", "--nofs", "--strip", "--force", "--output", dest_path, "32", dest_path
+    run_command "oxipng", "--quiet", "--opt", "2", "--strip", "all", dest_path
+    true
+  end
+end
+
+$responsive_images = {}
+Jekyll::Hooks.register :site, :after_reset do |site|
+  $responsive_images = {}
+end
+
+class ResponsiveImageTag < Liquid::Tag
+  def initialize tag_name, markup, tokens
+    super
+    @src, *options = markup.split
+    @lazy = options.include? "lazy"
+  end
+
+  def render context
+    site = context.registers[:site]
+    page = context.registers[:page]
+    site_path = @src.start_with?("/") ? @src : File.join(page["dir"], @src)
+    image = $responsive_images[site_path] ||= add_image site, site_path
+
+    ext = File.extname @src
+    base = @src.delete_suffix ext
+    srcset = image[:widths].map { |w| "#{base}-#{w}w#{ext} #{w}w" }
+    srcset << "#{@src} #{image[:width]}w"
+    attrs = %(src="#{@src}" width="#{image[:width]}" height="#{image[:height]}" srcset="#{srcset.join(", ")}")
+    attrs << (@lazy ? %( loading="lazy" sizes="auto, 100vw") : %( sizes="100vw"))
+    "<img #{attrs}>"
+  end
+
+  private
+
+  def add_image site, site_path
+    source = File.join site.source, site_path
+    raise "responsive_img: #{source} not found" unless File.exist? source
+    width, height = run_command("magick", "identify", "-format", "%w %h", source).split.map(&:to_i)
+    dir = File.dirname site_path
+    ext = File.extname site_path
+    basename = File.basename site_path, ext
+    widths = [2, 4].map { |d| width / d }
+    widths.each do |w|
+      site.static_files << ResizedImage.new(site, dir, "#{basename}-#{w}w#{ext}", source, w)
+    end
+    { width: width, height: height, widths: widths }
+  end
+end
+
+Liquid::Template.register_tag("responsive_img", ResponsiveImageTag)
diff --git a/index.md b/index.md
index 0b6a592..86b3ff7 100644
--- a/index.md
+++ b/index.md
@@ -9,7 +9,7 @@ It supports a very fast full-text search, automatic contact-list management, cus
 
 If you're the type of person who treats email as an extension of your long-term memory, Sup is for you.
 
-<a href="screenshots/1.4/inbox.png"><img src="screenshots/1.4/inbox.png" width="1920" height="1148"></a>
+<a href="screenshots/1.4/inbox.png">{% responsive_img screenshots/1.4/inbox.png %}</a>
 
 ## Installation
 Install the sup rubygem and run the sup-config utility to build a configuration:
diff --git a/screenshots/index.md b/screenshots/index.md
index a03761b..c638389 100644
--- a/screenshots/index.md
+++ b/screenshots/index.md
@@ -3,45 +3,45 @@ title: sup screenshots
 layout: gallery
 ---
 <figure>
-  <a href="1.4/inbox.png"><img src="1.4/inbox.png" width="1920" height="1148"></a>
+  <a href="1.4/inbox.png">{% responsive_img 1.4/inbox.png lazy %}</a>
   <figcaption>
     Sup starts in inbox-mode: a list of threads tagged <tt class="code">inbox</tt>.
   </figcaption>
 </figure>
 <figure>
-  <a href="1.4/search-results.png"><img src="1.4/search-results.png" width="1920" height="1148"></a>
+  <a href="1.4/search-results.png">{% responsive_img 1.4/search-results.png lazy %}</a>
   <figcaption>
     <a href="https://github.com/sup-heliotrope/sup/wiki/Searching-Your-Mail">Search your mail</a>
     and Sup displays a list of matching threads in search-results-mode.
   </figcaption>
 </figure>
 <figure>
-  <a href="1.4/thread-view.png"><img src="1.4/thread-view.png" width="1920" height="1148"></a>
+  <a href="1.4/thread-view.png">{% responsive_img 1.4/thread-view.png lazy %}</a>
   <figcaption>
     In thread-view-mode, read messages are collapsed to a single line by default.
   </figcaption>
 </figure>
 <figure>
-  <a href="1.4/reply.png"><img src="1.4/reply.png" width="1920" height="1148"></a>
+  <a href="1.4/reply.png">{% responsive_img 1.4/reply.png lazy %}</a>
   <figcaption>
     When replying to a message, reply-mode is pre-populated with quoted text.
     Press <tt class="code">Enter</tt> to edit the reply in your preferred editor.
   </figcaption>
 </figure>
 <figure>
-  <a href="1.4/help.png"><img src="1.4/help.png" width="1920" height="1148"></a>
+  <a href="1.4/help.png">{% responsive_img 1.4/help.png lazy %}</a>
   <figcaption>
     Press <tt class="code">?</tt> in any mode to see the key bindings for the current mode.
   </figcaption>
 </figure>
 <figure>
-  <a href="1.4/log.png"><img src="1.4/log.png" width="1920" height="1148"></a>
+  <a href="1.4/log.png">{% responsive_img 1.4/log.png lazy %}</a>
   <figcaption>
     The log-mode buffer shows Sup’s internal log messages for debugging purposes.
   </figcaption>
 </figure>
 <figure>
-  <a href="1.4/console.png"><img src="1.4/console.png" width="1920" height="1148"></a>
+  <a href="1.4/console.png">{% responsive_img 1.4/console.png lazy %}</a>
   <figcaption>
     Sup has a built-in interactive Ruby console.
     It can access Sup internal Ruby objects.

      parent reply	other threads:[~2026-10-21 10:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 10:06 [sup-website.git] branch master updated (78e88eb -> 1238c53) Dan Callaghan
2026-10-21 10:06 ` [sup-website.git] 01/02: update screenshots after running oxipng -o 2 Dan Callaghan
2026-10-21 10:06 ` 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=20261021100652.0914329ECCB@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