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

Allow redirect_froms to specify target queries and/or hashes #181

Closed mattconsto closed 5 years ago

mattconsto commented 5 years ago

It would be useful to be able to specify where in a page a redirect_from targets using either a query string or fragment. This would allow the user to redirect different pages to different sections of a larger page, style the page differently using CSS :target, or react to the query string using JavaScript.

The syntax for the end user should be quite simple:


redirect_from:
  - /simple/example.html
  - source: /using/an/object.html
  - source: /and/now/a/target.html
     target: ?querystring#fragment

This would redirect both /simple/example.html and /using/an/object.html to the current page, and redirect /and/now/a/target.html to the current page ?querystring#fragment.

One possible way to implement it would be to modify self.redirect_from in /lib/jekyll-redirect-from/redirect_page.rb roughly as follows. Please forgive the poor ruby code, I have never written ruby before and I failed to install this plugin locally so was unable to test it.

# Creates a new RedirectPage instance from the path to the given doc
def self.redirect_from(doc, path)
  if path.is_a?(Object) and path.key?(:source)
    if path.key?(:target)
      RedirectPage.from_paths(doc.site, path.source, doc.url)
    else
      RedirectPage.from_paths(doc.site, path.source, doc.url + path.target)
    end
  else
    RedirectPage.from_paths(doc.site, path, doc.url)
  end
end

Overall this idea is very similar to the original idea of #28. I am posting it as a new issue since that issue has long since been forgotten and marked stale.

jekyllbot commented 5 years ago

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.

pathawks commented 5 years ago

Couldn't this be done with redirect_to instead? It seems like that would be a lot easier than having multiple redirect_from sources with different targets.

uberfuzzy commented 5 years ago

But doesn't redirect_to only accept absolute URLs?

pathawks commented 5 years ago

But doesn't redirect_to only accept absolute URLs?

I don't see why that would be the case.

uberfuzzy commented 5 years ago

But doesn't redirect_to only accept absolute URLs?

I don't see why that would be the case.

page.redirect.to - the absolute URL (where available) to the target page

jekyllbot commented 5 years ago

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.