From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by bl2.djc.id.au (Postfix, from userid 1000) id 0914329ECCB; Wed, 21 Oct 2026 21:06:52 +1100 (AEDT) Date: Wed, 21 Oct 2026 21:06:53 +1100 To: sup-commits@supmua.dev Subject: [sup-website.git] 02/02: responsive screenshots with optimised half and quarter size versions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Reply-To: Dan Callaghan In-Reply-To: <179257721178.417880.13737775410477211911@bl2.djc.id.au> References: <179257721178.417880.13737775410477211911@bl2.djc.id.au> Thread-Index: AQAAEjRWGj50uPQ4SoevgjWA75zGhQ== 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: 1238c539ae7734ea55e2602f31285f5a467a8c0a X-Git-NotificationType: diff X-Git-Multimail-Version: 1.7.dev Auto-Submitted: auto-generated Message-Id: <20261021100652.0914329ECCB@bl2.djc.id.au> From: Dan Callaghan List-Id: New commit on branch master: https://supmua.dev/git/sup-website/commit/1238c539ae7734ea55e2602f31285f5a467a8c0a.html commit 1238c539ae7734ea55e2602f31285f5a467a8c0a Author: Dan Callaghan 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")) + "" + 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. - +{% responsive_img screenshots/1.4/inbox.png %} ## 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 ---
- + {% responsive_img 1.4/inbox.png lazy %}
Sup starts in inbox-mode: a list of threads tagged inbox.
- + {% responsive_img 1.4/search-results.png lazy %}
Search your mail and Sup displays a list of matching threads in search-results-mode.
- + {% responsive_img 1.4/thread-view.png lazy %}
In thread-view-mode, read messages are collapsed to a single line by default.
- + {% responsive_img 1.4/reply.png lazy %}
When replying to a message, reply-mode is pre-populated with quoted text. Press Enter to edit the reply in your preferred editor.
- + {% responsive_img 1.4/help.png lazy %}
Press ? in any mode to see the key bindings for the current mode.
- + {% responsive_img 1.4/log.png lazy %}
The log-mode buffer shows Sup’s internal log messages for debugging purposes.
- + {% responsive_img 1.4/console.png lazy %}
Sup has a built-in interactive Ruby console. It can access Sup internal Ruby objects.