jimporter / mike

Manage multiple versions of your MkDocs-powered documentation via Git
BSD 3-Clause "New" or "Revised" License
551 stars 47 forks source link

Redirection is improper with versioning #57

Closed abhiTronix closed 3 years ago

abhiTronix commented 3 years ago

Hello @jimporter,

I have discovered this annoying bug with versioning that make permalinks useless. Mike drop the hash fragment or any #heading (this is the versioning example) with generated redirect making it impossible to pinpoint any heading in docs.

Actual behavior

Redirected address from latest to some v0.1.2 version drops the #heading fragment from url.

Expected behavior

Must redirect to exact address without dropping #heading fragment.

Steps to reproduce the bug

https://squidfunk.github.io/mkdocs-material-example-versioning/latest/#project-layout is redirected to https://squidfunk.github.io/mkdocs-material-example-versioning/0.2/ instead of https://squidfunk.github.io/mkdocs-material-example-versioning/0.2/#project-layout

Possible fix:

This could be solved with this new logic:

<script>
    window.location.href.replace('/latest/','/<your version>/');
</script>

But I'm not sure. Please look into this.

Related Issue

https://github.com/squidfunk/mkdocs-material/issues/2647

jimporter commented 3 years ago

Good point! Fixed in fd3c089. Between now and when v1.0.1 is released, you can just disable redirects (while will make full copies of the site for each alias) via --no-redirect, or copy the fixed template from mike/templates/redirect.html to a local dir and pass it to mike with --template.

abhiTronix commented 3 years ago

@jimporter Wow, I didn't about this feature. Also Kudos for fixing this bug. 😃

abhiTronix commented 3 years ago

@jimporter Also I have one doubt. Like we have index.html in root directory for redirecting to latest version index page, can't we have 404.html in root too to redirect to latest version 404 page? Currently it shows GitHub's own 404 error page: https://squidfunk.github.io/mkdocs-material-example-versioning/ok

@jimporter Also, additional query. Is this current patch covers behavior for root's index.html too? As it previously redirects to latest version page but not #heading.

jimporter commented 3 years ago

Adding a 404 page is complicated, but I hope to do it for 2.0.

This should work for the root index.html too, provided you run mike set-default again (#52 tracks keeping index.html up-to-date if the redirect template ever changes).

abhiTronix commented 3 years ago

Adding a 404 page is complicated, but I hope to do it for 2.0.

@jimporter Yeah. For temporary solution, I redirect every 404 traffic to latest version's 404 page.

This should work for the root index.html too, provided you run mike set-default again (#52 tracks keeping index.html up-to-date if the redirect template ever changes).

Yes, it is working. I just tested it. Thanks 😃