Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect fails with translation plugin #33

Open
MAGICCC opened this issue Feb 5, 2022 · 10 comments
Open

Redirect fails with translation plugin #33

MAGICCC opened this issue Feb 5, 2022 · 10 comments

Comments

@MAGICCC
Copy link

MAGICCC commented Feb 5, 2022

Hello,

Now I want to use mkdocs-redirects to redirect from a old layout to a new docs layout including subfolders and translated pages using https://github.com/ultrabug/mkdocs-static-i18n
But I have a small problem:
Lets assume following redirection:
'old_foo.md': 'bar/foo.en.md'
Normally it should redirect to bar/foo/ but it builds a redirection to bar/foo.en/ and this pages doesn't exist.

Not sure if this can be fixed, since files can be named xx.en but maybe you guys have a solution for me.

@hhslepicka
Copy link

I am with the same problem as the one reported here. I am using the mkdocs-static-i18n and I can't get the redirects to work. Any update?

@oprypin
Copy link
Contributor

oprypin commented Sep 3, 2022

Please provide a mkdocs website source (mkdocs.yml and necessary sources) that exhibits this issue.

@hhslepicka
Copy link

@oprypin working on that.

@hhslepicka
Copy link

@oprypin here they are:

Steps to Reproduce

  1. Access the website at https://hhslepicka.github.io/mkdocs-redirect-issue-i18n/
  2. Click on the Old link on the home page.
  3. You will receive a 404 error
  4. Go back into the home page
  5. Click on the New link
  6. It will open the new page properly

As @MAGICCC reported, this plugin ends up generating a old.en folder with the index.html file inside of it (https://github.com/hhslepicka/mkdocs-redirect-issue-i18n/tree/gh-pages).

Also, the page is not generated for the multiple supported languages or even for the language indicated on the redirects area, it just adds it to the root.

@MAGICCC
Copy link
Author

MAGICCC commented Sep 3, 2022

I did a quickfix on my end some days after I created the issue.
Basicly a script which will change the index.html in the redirect folders

#/bin/bash
find ./site/ -maxdepth 2 -mindepth 2 -type f -name 'index.html' -not -path './site/de/*' -not -path './site/en/*' | while read f; do
	echo "Fixing redirect '$f'..."
	sed -i -E 's/\.en\/"/\/"/' $f
done

And I am speaking about this repo, https://github.com/mailcow/mailcow-dockerized-docs

@oprypin
Copy link
Contributor

oprypin commented Sep 18, 2022

It seems that #45 is taking us closer to a solution, but it's still really tough.

Out of these two redirects, the 1st one will start working, but not 2nd:

        "en/old.md": "new.en.md"
        "pt/old.md": "new.pt.md"

Somehow the pt one is not reported to be in the files collection.

@hhslepicka
Copy link

@oprypin I appreciate you looking into that. Thank you very much.

@kamilkrzyskow
Copy link

kamilkrzyskow commented Mar 2, 2023

The i18n plugin simulates the subsequent builds on the fly modifying the configuration to change the language of the theme and correctly save new.en.md under en/new/index.html. I doubt this is an issue to be dealt with in the redirects plugin.
https://github.com/kamilkrzyskow/i18n/tree/redirects-plugin-support I made changes to i18n plugin, didn't create a PR yet, but it's been working OK for the past few days.

@eXpl0it3r
Copy link

Just ran into this issue. Is there as solution/workaround to this?

@kamilkrzyskow
Copy link

Hi @eXpl0it3r,
you can adjust the patch hook we're using in GMC:
https://github.com/Gothic-Modding-Community/gmc/blob/674ee2bac41a0d71b15ffc7744b66e928c1bdd22/overrides/.hooks/all_plugin_patch.py#L157

Note that we're generating redirects based on Git with another hook, therefore we clear redirects_map between mkdocs serve runs, looking at the code now, I would make more changes to optimize it, but it worked last time I checked a few months back ✌️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants