Skip to content

Commit

Permalink
Update asset URLs for preload tags
Browse files Browse the repository at this point in the history
This ensures that we also update the URLs for <link rel="preload" />
elements.

Changelog: fixed
  • Loading branch information
yorickpeterse committed Jan 25, 2024
1 parent 3be8aba commit 202a0b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/wobsite.inko
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,11 @@ class UpdateAssetLinks {

fn link(link: mut html.Element) {
match link.attributes.opt('rel') {
case Some('stylesheet' or 'icon') -> match link.attributes.opt('href') {
case Some(url) -> link.attr('href', hashed_url(url))
case _ -> return
case Some('stylesheet' or 'icon' or 'preload') -> {
match link.attributes.opt('href') {
case Some(url) -> link.attr('href', hashed_url(url))
case _ -> return
}
}
case _ -> return
}
Expand Down
2 changes: 2 additions & 0 deletions test/test_wobsite.inko
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ fn pub tests(t: mut Tests) {

let html = html.Document.fragment

html.link.attr('rel', 'preload').attr('href', '/style.css')
html.link.attr('rel', 'stylesheet').attr('href', '/style.css')
html.link.attr('rel', 'stylesheet').attr('href', '../../style.css')
html.link.attr('rel', 'stylesheet').attr('href', '/missing.css')
Expand All @@ -291,6 +292,7 @@ fn pub tests(t: mut Tests) {
t.equal(
html.to_string,
'\
<link rel="preload" href="/style.css?hash=111" />\
<link rel="stylesheet" href="/style.css?hash=111" />\
<link rel="stylesheet" href="../../style.css?hash=111" />\
<link rel="stylesheet" href="/missing.css" />\
Expand Down

0 comments on commit 202a0b2

Please sign in to comment.