Closed benbalter closed 7 years ago
This looks simple, I like it. The redirects.json will always appear in the destination directory, right? Also I think it should regenerate the file even if it exists, to prevent issues with CI caching causing out of date redirects and local tools that may watch the redirect file for changes.
Also I think it should regenerate the file even if it exists, to prevent issues with CI caching causing out of date redirects and local tools that may watch the redirect file for changes.
To clarify, if redirects.json
exists in the source it will respect the user's file, rather than overwrite it. It will continue to work as expected if redirects.json
exists in the destination (just like any other page).
It was bugging me that some of the keys had a leading slash and others didn't. To make things easier for developers to consume the JSON, I updated the PR to normalize the from
metadata with a preceding slash prior to writing in a4fef3e. This is what it looks like now:
{
"/posts/23128432159832/mary-had-a-little-lamb": "http://jekyllrb.com/2014/01/03/redirect-me-plz.html",
"/articles/23128432159832/mary-had-a-little-lamb": "http://jekyllrb.com/articles/redirect-me-plz.html",
"/tags/our projects/": "http://jekyllrb.com/tags/our-projects/",
"/articles/redirect-somewhere-else-plz.html": "http://www.zombo.com",
"/tags/how we work/": "http://jekyllrb.com/tags/how-we-work/",
"/help": "http://jekyllrb.com/multiple_redirect_froms.html",
"/contact": "http://jekyllrb.com/multiple_redirect_froms.html",
"/let-there/be/light-he-said": "http://jekyllrb.com/multiple_redirect_froms.html",
"/geepers/mccreepin": "http://jekyllrb.com/multiple_redirect_froms.html",
"/multiple_redirect_tos.html": "https://www.jekyllrb.com",
"/some/other/path": "http://jekyllrb.com/one_redirect_from.html",
"/one_redirect_to_path.html": "http://jekyllrb.com/foo",
"/one_redirect_to_url.html": "https://www.github.com"
}
@jekyllbot: merge +major.
Since https://github.com/jekyll/jekyll-redirect-from/pull/131, https://github.com/jekyll/jekyll-redirect-from/issues/125 is much easier to implement and this PR does just that.
At build time, if the site source does not have a
redirects.json
file, the the plugin will add aredirects.json
file with a hash in the format offrom_path => to_url
.Here's an example of what the specs look like:
This could theoretically be used for automated testing, or to implement server-side redirects.
Thoughts?