-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add support for hash fragments #16
Comments
This can be achieved with mkdocs-gen-files instead. # mkdocs.yml
plugins:
- search
- gen-files:
scripts:
- redirects.py # docs/redirects.py
import mkdocs_gen_files
redirect_map = {
"guides/package.md": "../../guide/actions",
"guides/webservice.md": "../../guide/actions",
"guides/update.md": "../../guide/actions/#updating-a-project",
"guides/ides.md": "../../guide/environment/#ide-text-editor",
}
redirect_template = """
<script type="text/javascript">
window.location.href = "{link}";
</script>
<a href="{link}">Redirecting...</a>
"""
for page, link in redirect_map.items():
with mkdocs_gen_files.open(page, "w") as fd:
print(redirect_template.format(link=link), file=fd) Note however that you must use relative links with this solution, not file names. And mkdcs-gen-files is Python 3.7+. |
This was referenced Aug 16, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First of all: this is a very useful plugin, thanks for writing it!
I'm currently in the process of rewriting the docs for Material for MkDocs in squidfunk/mkdocs-material#1735 and, as the overall structure changed a lot, want to redirect some of the pages. However, some pages were merged.
Idea
Allow hash fragments in URL mappings, so that the redirect will jump to the subsection of the page, e.g.:
Actual behavior
When building the site, the plugin prints:
Desired behavior
No error, redirects work.
The text was updated successfully, but these errors were encountered: