Skip to content

Commit b3a77d8

Browse files
committed
Respect http-equiv refresh headers in swup.js, closes #2094
1 parent 8a5217e commit b3a77d8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

assets/js/swup.js

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ const emitExdocLoaded = () => {
1010
window.dispatchEvent(new Event('exdoc:loaded'))
1111
}
1212

13+
const maybeMetaRedirect = (visit, {page}) => {
14+
const match = page.html.match(/<meta\s+http-equiv\s*=\s*["']refresh["']\s+content\s*=\s*["']\d+\s*;\s*url\s*=\s*([^"']+)["']/i)
15+
16+
if (match && match[1]) {
17+
visit.abort()
18+
window.location.href = match[1]
19+
}
20+
}
21+
1322
window.addEventListener('DOMContentLoaded', emitExdocLoaded)
1423

1524
if (!isEmbedded && window.location.protocol !== 'file:') {
@@ -23,6 +32,7 @@ if (!isEmbedded && window.location.protocol !== 'file:') {
2332
},
2433
linkSelector: 'a[href]:not([href^="/"]):not([href^="http"])',
2534
hooks: {
35+
'page:load': maybeMetaRedirect,
2636
'page:view': emitExdocLoaded
2737
},
2838
plugins: [new SwupA11yPlugin(), new SwupProgressPlugin({delay: 500})]

0 commit comments

Comments
 (0)