commit 1238c539ae7734ea55e2602f31285f5a467a8c0a
parent 4d47db3f52dca188b53c6d1caffc12e99eaf7905
Author: Dan Callaghan <djc@djc.id.au>
Date: Wed, 21 Oct 2026 21:00:32 +1100
responsive screenshots with optimised half and quarter size versions
Diffstat:
3 files changed, 83 insertions(+), 8 deletions(-)
diff --git a/_plugins/responsive_images.rb 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
@@ -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
@@ -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.