mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +00:00
Preserve absolute stylesheet URLs
This commit is contained in:
parent
c69c12db99
commit
ae5057f223
2 changed files with 26 additions and 1 deletions
|
|
@ -88,7 +88,7 @@ module Pressa
|
||||||
link(rel: "dns-prefetch", href: "https://gist.github.com")
|
link(rel: "dns-prefetch", href: "https://gist.github.com")
|
||||||
|
|
||||||
all_styles.each do |style|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -191,6 +191,12 @@ module Pressa
|
||||||
absolute_asset(src)
|
absolute_asset(src)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def style_href(href)
|
||||||
|
return href if href.start_with?("http://", "https://")
|
||||||
|
|
||||||
|
absolute_asset(href)
|
||||||
|
end
|
||||||
|
|
||||||
def absolute_asset(path)
|
def absolute_asset(path)
|
||||||
normalized = path.start_with?("/") ? path : "/#{path}"
|
normalized = path.start_with?("/") ? path : "/#{path}"
|
||||||
site.url_for(normalized)
|
site.url_for(normalized)
|
||||||
|
|
|
||||||
|
|
@ -44,4 +44,23 @@ RSpec.describe Pressa::Views::Layout do
|
||||||
|
|
||||||
expect(html).to include("<title>samhuri.net: <img src=x onerror=alert(1)></title>")
|
expect(html).to include("<title>samhuri.net: <img src=x onerror=alert(1)></title>")
|
||||||
end
|
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(%(<link rel="stylesheet" type="text/css" href="https://cdn.example.com/site.css">))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue