jekyll / jekyll-redirect-from

:twisted_rightwards_arrows: Seamlessly specify multiple redirections URLs for your pages and posts.
MIT License
780 stars 112 forks source link

Pass parameters and anchors in URL to redirected page #229

Open swheaton opened 3 years ago

swheaton commented 3 years ago

Summary

This change allows anchors (#heading) and parameters (?q=a) in a URL to be passed along to the redirected page. The use case for this would be when linking readers to a specific section of a page, and wanting the link to work for either the permalink page or the redirected page. I don't have a use case for query parameters, but it's the same idea so I don't see why not.

Current

If oldPath/index.html redirects to http://jekyllrb.com/2014/01/03/redirect-me-plz.html

Then any link containing anchors or parameters is broken, such as the following: http://jekyllrb.com/oldPath#important-subsection?question=answer Will redirect to the base page, stripping off the extras: http://jekyllrb.com/2014/01/03/redirect-me-plz.html

Proposed

I propose that the link: http://jekyllrb.com/oldPath#important-subsection Should redirect to http://jekyllrb.com/2014/01/03/redirect-me-plz.html#important-subsection?question=answer

Technical Details

  1. The first script now appends location.hash and location.search to the jump location.
  2. The backup redirect solutions - the refresh meta tag and manual redirect links - are edited in a secondary script to append location.hash and location.search.
  3. If JavaScript is turned off, it will redirect to the base URL without anchors or parameters
  4. I don't think location.hash or location.search can be null or undefined, but just in case, there are null/undefined checks to make them explicitly be "".
swheaton commented 3 years ago

Bump

swheaton commented 3 years ago

Bump2. Anyone checking this repo?

cmcl commented 3 years ago

Hello, this addition is rather useful. Can we get someone to merge it in?

swheaton commented 3 years ago

maybe @ashmaroli , @DirtyF , @parkr ?

dylanirlbeck commented 2 years ago

Can we bump this? @DirtyF I'll just tag you since it seems you've contributed recently.

ashmaroli commented 2 years ago

Hello everyone, I've taken a look at this. The patch introduces a significant amount of JS code without test coverage. That is not acceptable. Why not handle the computation in Ruby itself instead of JS?

swheaton commented 2 years ago

Thank you for taking a look @ashmaroli.

This was months ago but if I remember right, it's because you want to be able to redirect to specific anchors on the permanent page, which happens dynamically. I don't think you can do it in Ruby (which runs at site build time) unless along with registering the redirect you somehow also registered all anchor and parameter possibilities.

At least, I cannot think of a way. But I am no Ruby expert by far. If you have an idea, please let me know and I will be happy to try my hand at an alternative solution.

If not, how do you propose increasing test coverage? The current test framework can only test Ruby code if I'm not mistaken.

ashmaroli commented 2 years ago

to be able to redirect to specific anchors on the permanent page, which happens dynamically..

Oh right. There's no easy way to this before hand. We sure are in a sticky situation here..

eregon commented 2 years ago

Ref: https://github.com/jekyll/jekyll-redirect-from/issues/219