jbake-org / jbake

Java based open source static site/blog generator for developers & designers.
http://jbake.org
MIT License
1.12k stars 326 forks source link

RFE: Support for redirections #506

Open OndraZizka opened 6 years ago

OndraZizka commented 6 years ago

Sometimes, the content structure has to be changed. In such case, the old URLs should still work. This is quite a challenge with a static website.

User could keep the old file with a link to the new location. He could add a metadata to the header and render a redirect <meta> element in the template.

However, it would be very nice if JBake could handle this and relieve the user from the burden:

Let's say we're moving pages from content/beer to content/drinking/beer (because we also started drinking wine and rums :) ).
content/beer/jbake.redirect would contain:

newLocation=../drinking/beer/
~~~~~~~~~~~
reviews/budweiser-budvar.md
reviews/starobrno.md
...

JBake would generate pages with <meta> redirects:

content/beer/reviews/budweiser-budvar.html
content/beer/reviews/starobrno.html

With the redirects going to ${newLocation}${oldPath}

This is an idea I have now after reorganizing my site while it's still new. However, doing that to an existing site can sink it down in search engines for quite a long time, break potential dead links around the web etc. So it's quite an important role of the static site generator.

Sounds good?

Edit: Looks like Jekyll has something similar, although doesn't seem like it relieves much work.

OndraZizka commented 6 years ago

The page could be

<!DOCTYPE html>
<html>
  <head>
    <meta charset=utf-8>
    <title>Redirecting from ${oldPath}...</title>
    <link rel=canonical href="${...}">
    <meta http-equiv=refresh content="1; url=http://${site.host}${newLocation}${oldPath}">
  </head>
  <body>
    <h1>Redirecting...</h1>
    <a href="${site.host}">Click here if you are not redirected.</a>
    <script> document.location = "${...}";</script>
  </body>
</html>
ancho commented 6 years ago

Interesting and very useful idea.

jonbullock commented 6 years ago

I like the idea.

Seeing the Jekyll link... could we achieve this by defining the old-url in the metadata header of the newly "moved" file. That way JBake would know how to create the old url file which is is built using a redirect template file. Keeps it simple and ties the old url and new url together.

bmarwell commented 3 years ago

Hey, I would also be interested in this. Will use a redirect template until then.

wessven commented 2 years ago

+1 for me as well.

Redirections can, of course, be set up on the web server, but I do think that redirections is a useful feature for a static site generator.

I primarily author my documents in Asciidoc. I always think to myself, would I be able to take my document as-is, and use it for something else (e.g. generating an epub)? While I don't necessarily mind declaring extra attributes in my adocs, perhaps the individual documents is not the appropriate place for redirections to reside (which is how Jekyll does it). The structure of the website should not be determined by the individual post. A redirect file (as suggested by OP, and which is more in line with how to set up redirections on a web server or CMS) is perhaps more appropriate. Please keep in mind, though, that redirections need to be versatile. It's not necessarily sufficient to "lift-and-shift" the existing directory structure into a new directory. For example, it would be good to be able to support a redirection such as

/node/1234/ -> /content/beer/reviews/starobrno.html

bmarwell commented 2 years ago

Also useful would be if we could create the .htaccess file using freemarker.