Stable internal linking and durable external URLs for MkDocs via a page ID system
Project description
mkdocs-stablelinks-plugin
Stable internal linking and durable external URLs for Material for MkDocs via a page ID system.
Authors declare a stable id in page front matter. Internal links use id: syntax resolved at build time. External durable links use /go/<id>/ redirect pages that update automatically when pages move.
Installation
pip install mkdocs-stablelinks-plugin
Requires Python 3.10+.
Quick start
Add the plugin to mkdocs.yml:
plugins:
- search
- stablelinks
Declare an ID in any page's front matter:
---
id: install-windows
---
Link to that page from anywhere in the site using the id: syntax:
[Install on Windows](id:install-windows)
[Install on Windows](id:install-windows#prerequisites)
At build time, id: links are rewritten to standard relative URLs. If the page moves, only its front matter path changes — all links continue to work.
Configuration
plugins:
- stablelinks:
redirect_path: go # URL prefix for redirect pages (default: go)
redirect_mechanism: both # html | netlify | both (default: both)
index_page: true # generate /go/ index listing (default: true)
on_unresolved: warn # warn | error (default: warn)
All options are optional. The minimal installation works with no configuration at all.
| Option | Default | Accepted values | Description |
|---|---|---|---|
redirect_path |
go |
Any valid URL segment | URL prefix used for all redirect pages and the index page. A page with id: install-windows produces a redirect at /<redirect_path>/install-windows/. Changing this value after publishing will break any external links that used the old path. |
redirect_mechanism |
both |
html, netlify, both |
Which redirect format(s) to generate. html writes a meta-refresh page for each ID under <site>/<redirect_path>/. netlify appends 301 rules to _redirects at the site root. both does both. Use netlify alone if you deploy to Netlify and want server-side redirects without the extra HTML files. |
index_page |
true |
true, false |
When enabled, generates a page at /<redirect_path>/ listing all registered IDs, their titles, and current URLs. The page inherits the site theme and is excluded from search results. Shares the same path as redirect_path. |
on_unresolved |
warn |
warn, error |
What to do when an id: link references an ID that no page declares. warn logs a warning and preserves the original id: syntax in the output. error fails the build. |
ID format
---
id: install-windows
---
IDs must:
- Contain only lowercase letters, numbers, and hyphens
- Be unique across the entire site
Pages without an id are unaffected by the plugin.
Link syntax
[link text](id:page-id)
[link text](id:page-id#anchor)
Anchor fragments are passed through as-is. The plugin does not validate that an anchor exists on the target page.
Redirect pages
For each page with an id, the plugin can generate one or both of the following redirect mechanisms (controlled by redirect_mechanism):
HTML meta refresh
A file is written to <site>/<redirect_path>/<id>/index.html:
<meta http-equiv="refresh" content="0; url=/install/windows/">
<link rel="canonical" href="/install/windows/">
Share /go/install-windows/ as a durable external link. When the page moves, regenerate the site — the redirect updates automatically.
Netlify _redirects
Rules are appended to _redirects at the site root:
# mkdocs-stablelinks — auto-generated, do not edit below this line
/go/install-windows/ /install/windows/ 301
Existing _redirects content is preserved.
ID index page
When index_page: true, a page listing all registered IDs is generated at /<redirect_path>/. It shows each ID, its title, and its current URL.
mkdocs-macros-plugin compatibility
If you use mkdocs-macros-plugin with snippets, list it before stablelinks:
plugins:
- search
- macros
- stablelinks
If macros is listed after stablelinks, the plugin emits a warning at build time.
Error conditions
| Condition | Severity |
|---|---|
Duplicate id across pages |
Error (always) |
Unresolved id: link |
Configurable (warn or error) |
Invalid id format |
Warning |
redirect_path collides with docs content |
Warning |
| macros listed after stablelinks | Warning |
Unresolved id: links are preserved in output rather than generating broken HTML.
Limitations
- Anchor fragments in
id:links are not validated against the target page's headings. - Requires Material for MkDocs. Other themes are not supported.
redirect_mechanism: netlifygenerates a plain_redirectsfile; no other server-side redirect formats are supported.
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_stablelinks_plugin-0.1.0.tar.gz.
File metadata
- Download URL: mkdocs_stablelinks_plugin-0.1.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d78164aa6239ad0c3e188501d3ff2504bbc97977e0f8f37bccdf1641172fccdc
|
|
| MD5 |
a67d9a4a3fbef1da5ef867638d0ccfb2
|
|
| BLAKE2b-256 |
d0ed6e37fa0a63c0b98bd2178b4c10fba89b5679e3307b37b0e60dfe1d6a7267
|
Provenance
The following attestation bundles were made for mkdocs_stablelinks_plugin-0.1.0.tar.gz:
Publisher:
publish.yml on dsferg/mkdocs-stablelinks-plugin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_stablelinks_plugin-0.1.0.tar.gz -
Subject digest:
d78164aa6239ad0c3e188501d3ff2504bbc97977e0f8f37bccdf1641172fccdc - Sigstore transparency entry: 1222778106
- Sigstore integration time:
-
Permalink:
dsferg/mkdocs-stablelinks-plugin@96113c711b5c1e5eefcdbe4ab2916d47dca34db0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dsferg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@96113c711b5c1e5eefcdbe4ab2916d47dca34db0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mkdocs_stablelinks_plugin-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mkdocs_stablelinks_plugin-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35556d75ef7044056b8acd850745c107bf099c679d89fe63e08778333e243738
|
|
| MD5 |
b424603abdf5fd9e7c5e7d5b0e7d8513
|
|
| BLAKE2b-256 |
841c4d13484e7e67cc24683d883a514b29d8be9edae1481af3e6843c4b82f8c9
|
Provenance
The following attestation bundles were made for mkdocs_stablelinks_plugin-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on dsferg/mkdocs-stablelinks-plugin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_stablelinks_plugin-0.1.0-py3-none-any.whl -
Subject digest:
35556d75ef7044056b8acd850745c107bf099c679d89fe63e08778333e243738 - Sigstore transparency entry: 1222778275
- Sigstore integration time:
-
Permalink:
dsferg/mkdocs-stablelinks-plugin@96113c711b5c1e5eefcdbe4ab2916d47dca34db0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dsferg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@96113c711b5c1e5eefcdbe4ab2916d47dca34db0 -
Trigger Event:
release
-
Statement type: