Skip to content

Commit

Permalink
Respect http-equiv refresh headers in swup.js, closes #2094
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Mar 5, 2025
1 parent 8a5217e commit b3a77d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions assets/js/swup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ const emitExdocLoaded = () => {
window.dispatchEvent(new Event('exdoc:loaded'))
}

const maybeMetaRedirect = (visit, {page}) => {
const match = page.html.match(/<meta\s+http-equiv\s*=\s*["']refresh["']\s+content\s*=\s*["']\d+\s*;\s*url\s*=\s*([^"']+)["']/i)

if (match && match[1]) {
visit.abort()
window.location.href = match[1]
}
}

window.addEventListener('DOMContentLoaded', emitExdocLoaded)

if (!isEmbedded && window.location.protocol !== 'file:') {
Expand All @@ -23,6 +32,7 @@ if (!isEmbedded && window.location.protocol !== 'file:') {
},
linkSelector: 'a[href]:not([href^="/"]):not([href^="http"])',
hooks: {
'page:load': maybeMetaRedirect,
'page:view': emitExdocLoaded
},
plugins: [new SwupA11yPlugin(), new SwupProgressPlugin({delay: 500})]
Expand Down
Loading

0 comments on commit b3a77d8

Please sign in to comment.