mkdocs / mkdocs-redirects

Open source plugin for Mkdocs page redirects
MIT License
176 stars 25 forks source link

Option to override use_directory_urls for redirect sources #59

Closed andgineer closed 3 weeks ago

andgineer commented 5 months ago

Now mkdocs-redirect create both source and target redirect URLs based on mkdocs option use_directory_urls But if we had a legacy site with file-style URLs and now we need redirects from that old legacy to new shiny site with fancy URL redirects we are out of luck :(

So I end with that hack: https://github.com/andgineer/TRegExpr/blob/master/docs/fix_folder_redirects.py

To fix that for example we can have mkdocs-redict option use different use_directory_urls for the redirect sources.

Also we could specify that for each redirect.

feasgal commented 4 weeks ago

I'm looking for almost the same thing. It would probably end up being covered by the same update to mkdocs-redirects.

I have a legacy site with file-style URLs, because we used to deliver the docs with our SDK as well as online. Now our docs are online-only and we want to set use_directory_urls: true, but we aren't re-organizing the documentation. I need our customers' bookmarks and links that currently go to path/to/file.html to redirect to path/to/file/ or path/to/file/index.html after I make the switch. I can't find a currently-handled syntax that will accomplish this.

pawamoy commented 3 weeks ago

Possible workaround:

plugins:
- redirects:
    redirect_maps:
      old/url.html.md: new/page.md

What's fun is that it will create a directory URL named old/url.html/, and since the trailing slash is automatically appended (with a redirect), it means you can actually go to old/url.html, which will redirect you to old/url.html/, which will redirect you to new/page/ :rofl:

I have successfully used this technique for my blog in the past :slightly_smiling_face:

plugins:
  - search
  - redirects:
      redirect_maps:
        2018/02/01/docker-compose-django-postgres-nginx.html.md: posts/docker-compose-django-postgres-nginx.md
        2017/05/31/python-static-code-analysis-tools.html.md: posts/python-static-code-analysis-tools.md
        2016/12/07/documentation-in-your-shell-scripts-using-shellman.html.md: posts/documentation-in-your-shell-scripts-using-shellman.md
        2016/12/07/write-and-use-a-tox-plugin-from-inside-your-package.html.md: posts/write-and-use-a-tox-plugin-from-inside-your-package.md
        2016/04/06/django-dashboard-with-suit-and-highcharts.html.md: posts/django-dashboard-with-suit-and-highcharts.md
feasgal commented 3 weeks ago

That's a really interesting proposition. I'll have to try it. So far everything I've tried has ended up with an infinite redirect loop because the directory structure isn't changing, just that one use_directory_urls config setting.

feasgal commented 3 weeks ago

It works! Now as long as that workaround isn't a bug that gets 'fixed'...

feasgal commented 3 weeks ago

For what it's worth, the 'right' way to do what I was doing is to write a server-side redirect for that URL pattern. And that is exactly what my colleague just did because I hadn't told him I was pursuing it from the docs config side, so we're going with that solution since he's already done it.

But this workaround did work! Thank you for it!

pawamoy commented 3 weeks ago

I'd be happy to confirm that this behavior is not a bug and therefore will not be "fixed", but I'm just a passing-by maintainer :slightly_smiling_face: I'll close anyway! If the original authors, other maintainers, or impacted users disagree, we'll reopen.