A MkDocs plugin for dynamic page redirects to prevent broken links
Project description
mkdocs-redirects
Plugin for mkdocs to create page redirects (e.g. for moved/renamed pages)
Initially developed by DataRobot.
Installing
Install with pip:
pip install mkdocs-redirects
Using
To use this plugin, specify your desired redirects in the plugin's redirect_maps setting in your mkdocs.yml:
plugins:
- redirects:
redirect_maps:
'old.md': 'new.md'
'old/file.md': 'new/file.md'
'some_file.md': 'http://external.url.com/foobar'
Note
Don't forget that specifying thepluginssetting will override the defaults if you didn't already have it set! See this page for more information.
The redirects map should take the form of a key/value pair:
- The key of each redirect is the original markdown doc (relative to the
docs_dirpath).- This plugin will handle the filename resolution during the
mkdocs buildprocess. This should be set to what the original markdown doc's filename was (or what it would be if it existed), not the final HTML file rendered by MkDocs
- This plugin will handle the filename resolution during the
- The value is the redirect target. This can take the following forms:
- Path of the markdown doc you wish to be redirected to (relative to
docs_dir)- This plugin will handle the filename resolution during the
mkdocs buildprocess. This should be set to what the markdown doc's filename is, not the final HTML file rendered by MkDocs
- This plugin will handle the filename resolution during the
- External URL (e.g.
http://example.com)
- Path of the markdown doc you wish to be redirected to (relative to
During the mkdocs build process, this plugin will create .html files in site_dir for each of the "old" file that redirects to the "new" path.
It will produce a warning if any problems are encountered or of the redirect target doesn't actually exist (useful if you have strict: true set).
use_directory_urls
If you have use_directory_urls: true set (which is the default), this plugin will modify the redirect targets to the directory URL, not the actual index.html filename.
However, it will create the index.html file for each target in the correct place so URL resolution works.
For example, a redirect map of 'old/dir/README.md': 'new/dir/README.md' will result in an HTML file created at $site_dir/old/dir/index.html which redirects to ../../new/dir/.
Additionally, a redirect map of 'old/dir/doc_name.md': 'new/dir/doc_name.md' will result in $site_dir/old/dir/doc_name/index.html redirecting to ../../new/dir/doc_name/.
This mimics the behavior of how MkDocs builds the site dir without this plugin.
Developing
Dev dependencies and tasks are managed with Hatch. Tasks run in their own environment, created on the fly if missing, in a separate directory tree.
To run all checks and fixes:
hatch run all
You can learn about individual commands from the output, or by inspecting scripts in pyproject.toml.
Releasing
A release is published to PyPI through GitHub Actions whenever a new tag is pushed.
So, to create a release, run .tools/release.sh x.y.z (which bumps the version in __init__.py, checks the build, creates a commit and a tag vx.y.z, and pushes it to GitHub).
Then fill out a GitHub release with release notes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mkdocs_redirects-1.2.2.tar.gz.
File metadata
- Download URL: mkdocs_redirects-1.2.2.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3094981b42ffab29313c2c1b8ac3969861109f58b2dd58c45fc81cd44bfa0095
|
|
| MD5 |
1080b1ed4b5588413af1394ed99f82cf
|
|
| BLAKE2b-256 |
f1a86d44a6cf07e969c7420cb36ab287b0669da636a2044de38a7d2208d5a758
|
Provenance
The following attestation bundles were made for mkdocs_redirects-1.2.2.tar.gz:
Publisher:
deploy-release.yml on mkdocs/mkdocs-redirects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_redirects-1.2.2.tar.gz -
Subject digest:
3094981b42ffab29313c2c1b8ac3969861109f58b2dd58c45fc81cd44bfa0095 - Sigstore transparency entry: 147318531
- Sigstore integration time:
-
Permalink:
mkdocs/mkdocs-redirects@df6b0a8348b6cf25c405f93f0328eff7ae510121 -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/mkdocs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy-release.yml@df6b0a8348b6cf25c405f93f0328eff7ae510121 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mkdocs_redirects-1.2.2-py3-none-any.whl.
File metadata
- Download URL: mkdocs_redirects-1.2.2-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7dbfa5647b79a3589da4401403d69494bd1f4ad03b9c15136720367e1f340ed5
|
|
| MD5 |
151ddd5405273bacb1b26268069128bc
|
|
| BLAKE2b-256 |
c4ec38443b1f2a3821bbcb24e46cd8ba979154417794d54baf949fefde1c2146
|
Provenance
The following attestation bundles were made for mkdocs_redirects-1.2.2-py3-none-any.whl:
Publisher:
deploy-release.yml on mkdocs/mkdocs-redirects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_redirects-1.2.2-py3-none-any.whl -
Subject digest:
7dbfa5647b79a3589da4401403d69494bd1f4ad03b9c15136720367e1f340ed5 - Sigstore transparency entry: 147318533
- Sigstore integration time:
-
Permalink:
mkdocs/mkdocs-redirects@df6b0a8348b6cf25c405f93f0328eff7ae510121 -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/mkdocs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy-release.yml@df6b0a8348b6cf25c405f93f0328eff7ae510121 -
Trigger Event:
push
-
Statement type: