Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass parameters and anchors in URL to redirected page #229

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/jekyll-redirect-from/redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@
<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 }}">
<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">
<h1>Redirecting&hellip;</h1>
<a href="{{ page.redirect.to }}">Click here if you are not redirected.</a>
<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 urlSuffix = "" + (location.hash ? location.hash : "") + (location.search ? location.search : "");
let refreshMeta = document.getElementById("refresh-meta");
const newContentStr = refreshMeta.getAttribute("content") + urlSuffix;
refreshMeta.setAttribute("content", newContentStr);
let redirectLink = document.getElementById("redirect-link");
const newHrefUrl= redirectLink.getAttribute("href") + urlSuffix;
redirectLink.setAttribute("href", newHrefUrl);
</script>
</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
Loading