Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Co-authored-by: Stuart <[email protected]>
Co-authored-by: Chris Buckley <[email protected]>
  • Loading branch information
3 people committed Nov 1, 2023
1 parent 6a751b2 commit 66e12c5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
45 changes: 37 additions & 8 deletions lib/jekyll-redirect-from/redirect.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
<!DOCTYPE html>
<html lang="en-US">
<meta charset="utf-8">
<title>Redirecting&hellip;</title>
<link rel="canonical" href="{{ page.redirect.to }}">
<script>location="{{ page.redirect.to }}"</script>
<meta http-equiv="refresh" content="0; url={{ page.redirect.to }}">
<meta name="robots" content="noindex">
<h1>Redirecting&hellip;</h1>
<a href="{{ page.redirect.to }}">Click here if you are not redirected.</a>
<head>
<meta charset="utf-8" />
<title>Redirecting&hellip;</title>
<link rel="canonical" href="{{ page.redirect.to }}" />
<script>
const urlSuffix =
"" +
(location.hash ? location.hash : "") +
(location.search ? location.search : "");
location = "{{ page.redirect.to }}" + urlSuffix;
</script>
<meta
id="refresh-meta"
http-equiv="refresh"
content="0; url={{ page.redirect.to }}"
/>
<meta name="robots" content="noindex" />
</head>
<body>
<h1>Redirecting&hellip;</h1>
<a id="redirect-link" href="{{ page.redirect.to }}"
>Click here if you are not redirected.</a
>
<script>
// Add hash and search to meta redirect and manual link, in case script above did not work
const urlSuffix2 =
"" +
(location.hash ? location.hash : "") +
(location.search ? location.search : "");
let refreshMeta = document.getElementById("refresh-meta");
const newContentStr = refreshMeta.getAttribute("content") + urlSuffix2;
refreshMeta.setAttribute("content", newContentStr);
let redirectLink = document.getElementById("redirect-link");
const newHrefUrl = redirectLink.getAttribute("href") + urlSuffix2;
redirectLink.setAttribute("href", newHrefUrl);
</script>
</body>
</html>
8 changes: 2 additions & 6 deletions spec/jekyll_redirect_from/redirect_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,15 @@
end

it "contains the meta refresh tag" do
expect(output).to match("<meta http-equiv=\"refresh\" content=\"0; url=#{site_url}#{to}\">")
end

it "contains the javascript redirect" do
expect(output).to match("<script>location=\"#{site_url}#{to}\"</script>")
expect(output).to match("<meta id=\"refresh-meta\" http-equiv=\"refresh\" content=\"0; url=#{site_url}#{to}\">")
end

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

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

0 comments on commit 66e12c5

Please sign in to comment.