LuxDL / DocumenterVitepress.jl

Documentation with Documenter.jl and VitePress
https://luxdl.github.io/DocumenterVitepress.jl/
MIT License
63 stars 9 forks source link

Add an option to redirect trailing slash urls #74

Open LilithHafner opened 3 months ago

LilithHafner commented 3 months ago

Also

It's still functionally untested.

Fixes #64

LilithHafner commented 3 months ago

The best approach from a website visitor's perspective judged based on web best practices is to serve a 301 redirect. That would be faster, more conventional, and still preserve fragments.

However, for static site hosts that do not support serving custom 301 redirects (e.g. github pages), this is a reasonable alternative. This PR serves a 200 page

shell> curl https://chairmarks.lilithhafner.com/previews/PR80/explanations/#Why-the-name-"Chairmarks.jl"?
<!DOCTYPE html>
<script>
    const u = new URL(window.location.href);
    window.location.replace(u.origin + u.pathname.slice(0,-1) + u.search + u.hash);
</script>
<a href="..explanations">Redirecting to ..explanations</a>
<meta http-equiv="refresh" content="0; URL=../explanations">
<link rel="canonical" href="../explanations">

Which uses javascript to preserve the url fragment. If the javascript fails, then there is both an automatic and manual fallback. Both fallbacks fail to preserve the url fragment.

This PR is tested at https://github.com/LilithHafner/Chairmarks.jl/pull/80

asinghvi17 commented 3 months ago

Thanks! I will add a couple of small tests, and merge this before the next release!

LilithHafner commented 1 month ago

Bump