Skip to content

Commit 66e12c5

Browse files
prodStuartcmbuckley
committed
Co-authored-by: Stuart <[email protected]> Co-authored-by: Chris Buckley <[email protected]>
1 parent 6a751b2 commit 66e12c5

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed
+37-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
11
<!DOCTYPE html>
22
<html lang="en-US">
3-
<meta charset="utf-8">
4-
<title>Redirecting&hellip;</title>
5-
<link rel="canonical" href="{{ page.redirect.to }}">
6-
<script>location="{{ page.redirect.to }}"</script>
7-
<meta http-equiv="refresh" content="0; url={{ page.redirect.to }}">
8-
<meta name="robots" content="noindex">
9-
<h1>Redirecting&hellip;</h1>
10-
<a href="{{ page.redirect.to }}">Click here if you are not redirected.</a>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Redirecting&hellip;</title>
6+
<link rel="canonical" href="{{ page.redirect.to }}" />
7+
<script>
8+
const urlSuffix =
9+
"" +
10+
(location.hash ? location.hash : "") +
11+
(location.search ? location.search : "");
12+
location = "{{ page.redirect.to }}" + urlSuffix;
13+
</script>
14+
<meta
15+
id="refresh-meta"
16+
http-equiv="refresh"
17+
content="0; url={{ page.redirect.to }}"
18+
/>
19+
<meta name="robots" content="noindex" />
20+
</head>
21+
<body>
22+
<h1>Redirecting&hellip;</h1>
23+
<a id="redirect-link" href="{{ page.redirect.to }}"
24+
>Click here if you are not redirected.</a
25+
>
26+
<script>
27+
// Add hash and search to meta redirect and manual link, in case script above did not work
28+
const urlSuffix2 =
29+
"" +
30+
(location.hash ? location.hash : "") +
31+
(location.search ? location.search : "");
32+
let refreshMeta = document.getElementById("refresh-meta");
33+
const newContentStr = refreshMeta.getAttribute("content") + urlSuffix2;
34+
refreshMeta.setAttribute("content", newContentStr);
35+
let redirectLink = document.getElementById("redirect-link");
36+
const newHrefUrl = redirectLink.getAttribute("href") + urlSuffix2;
37+
redirectLink.setAttribute("href", newHrefUrl);
38+
</script>
39+
</body>
1140
</html>

spec/jekyll_redirect_from/redirect_page_spec.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,15 @@
4949
end
5050

5151
it "contains the meta refresh tag" do
52-
expect(output).to match("<meta http-equiv=\"refresh\" content=\"0; url=#{site_url}#{to}\">")
53-
end
54-
55-
it "contains the javascript redirect" do
56-
expect(output).to match("<script>location=\"#{site_url}#{to}\"</script>")
52+
expect(output).to match("<meta id=\"refresh-meta\" http-equiv=\"refresh\" content=\"0; url=#{site_url}#{to}\">")
5753
end
5854

5955
it "contains canonical link in header" do
6056
expect(output).to match("<link rel=\"canonical\" href=\"#{site_url}#{to}\">")
6157
end
6258

6359
it "contains the clickable link" do
64-
expect(output).to match("<a href=\"#{site_url}#{to}\">Click here if you are not redirected.</a>")
60+
expect(output).to match("<a id=\"redirect-link\" href=\"#{site_url}#{to}\">Click here if you are not redirected.</a>")
6561
end
6662
end
6763
end

0 commit comments

Comments
 (0)