From ae5057f2239aa32040c3a6b5c534d033d80a8713 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sat, 7 Feb 2026 18:39:54 -0800 Subject: [PATCH] Preserve absolute stylesheet URLs --- lib/views/layout.rb | 8 +++++++- spec/views/layout_spec.rb | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/views/layout.rb b/lib/views/layout.rb index c643d1d..bfc5f5c 100644 --- a/lib/views/layout.rb +++ b/lib/views/layout.rb @@ -88,7 +88,7 @@ module Pressa link(rel: "dns-prefetch", href: "https://gist.github.com") all_styles.each do |style| - link(rel: "stylesheet", type: "text/css", href: absolute_asset(style.href)) + link(rel: "stylesheet", type: "text/css", href: style_href(style.href)) end end @@ -191,6 +191,12 @@ module Pressa absolute_asset(src) end + def style_href(href) + return href if href.start_with?("http://", "https://") + + absolute_asset(href) + end + def absolute_asset(path) normalized = path.start_with?("/") ? path : "/#{path}" site.url_for(normalized) diff --git a/spec/views/layout_spec.rb b/spec/views/layout_spec.rb index d6417b6..741722f 100644 --- a/spec/views/layout_spec.rb +++ b/spec/views/layout_spec.rb @@ -44,4 +44,23 @@ RSpec.describe Pressa::Views::Layout do expect(html).to include("samhuri.net: <img src=x onerror=alert(1)>") end + + it "preserves absolute stylesheet URLs" do + cdn_site = Pressa::Site.new( + author: "Sami Samhuri", + email: "sami@samhuri.net", + title: "samhuri.net", + description: "blog", + url: "https://samhuri.net", + styles: [Pressa::Stylesheet.new(href: "https://cdn.example.com/site.css")] + ) + + html = described_class.new( + site: cdn_site, + canonical_url: "https://samhuri.net/posts/", + content: test_content_view + ).call + + expect(html).to include(%()) + end end