A MkDocs plugin that adds support for site-relative URLs
Project description
MkDocs Site URLs Plugin
A MkDocs plugin that adds support for site-relative site: URLs.
Example:
| URL | site_url | resulting URL |
|---|---|---|
site:images/foo.png |
https://example.com/ |
/images/foo.png |
site:images/foo.png |
https://example.com/path/ |
/path/images/foo.png |
site:images/foo.png |
unset/empty | /images/foo.png |
Please note: This plugin requires MkDocs 1.5 or higher.
Getting Started
- Install the plugin from PyPI
pip install mkdocs-site-urls
- Add the
site-urlsplugin to yourmkdocs.ymlplugins section:plugins: - site-urls
- Start using site-relative URLs in your Markdown files by prefixing them with
site::[Link to another page](site:another-page/relative/to/the/site/root) 
Configuration
By default the plugin will replace URLs in href, src and data attributes. You can configure the attributes to replace
by setting the attributes option in your mkdocs.yml, e.g.:
plugins:
- site-urls:
attributes:
- href
- src
- data
- data-url
Be advised that in case of any customization on your part you need to include the default attributes as well if you want to keep them, as the default list will not be included automatically anymore.
If site: as the prefix does not work for you for any reason, you can also configure that,
e.g.
plugins:
- site-urls:
prefix: "relative:"
This can also be used to interpret absolute URLs like /example/file.png as relative,
by setting the prefix to /.
The plugin will extract the path prefix to use from the site_url.
configured in your mkdocs.yaml. If no site_url is configured, it will default to using the root path /.
How it works
The plugin hooks into the on_page_content event
and replaces all URLs in the configured attributes (by default href, src or data) in the rendered HTML with the corresponding site-relative URLs.
Development
- Create a venv & activate it, e.g.
python -m venv venv && source venv/bin/activate - Install the dev requirements:
pip install -r requirements-dev.txt - Install the
pre-commithooks:pre-commit install
You can run the tests with pytest.
To build the docs, install their dependencies as well (pip install -r requirements-docs.txt),
then run mkdocs build.
License
This project is licensed under the MIT license, see the LICENSE file for details.
Project details
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_site_urls-0.3.1.tar.gz.
File metadata
- Download URL: mkdocs_site_urls-0.3.1.tar.gz
- Upload date:
- Size: 5.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 |
6c39b4aca9d0d29d747513bb679f5cc4e5957e37895ea5a12589e139ed1af3a9
|
|
| MD5 |
7a3fdccba4ea6d0e9572db94753da3d9
|
|
| BLAKE2b-256 |
3f9cd02d2e089b128e9d84c46fb757738ae56bffce33b5ad90dec4f280d03436
|
Provenance
The following attestation bundles were made for mkdocs_site_urls-0.3.1.tar.gz:
Publisher:
build.yml on OctoPrint/mkdocs-site-urls
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_site_urls-0.3.1.tar.gz -
Subject digest:
6c39b4aca9d0d29d747513bb679f5cc4e5957e37895ea5a12589e139ed1af3a9 - Sigstore transparency entry: 468829120
- Sigstore integration time:
-
Permalink:
OctoPrint/mkdocs-site-urls@aa57181d674e852e9fb1a3d83ef32b32fd114d5a -
Branch / Tag:
refs/tags/0.3.1 - Owner: https://github.com/OctoPrint
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@aa57181d674e852e9fb1a3d83ef32b32fd114d5a -
Trigger Event:
release
-
Statement type:
File details
Details for the file mkdocs_site_urls-0.3.1-py3-none-any.whl.
File metadata
- Download URL: mkdocs_site_urls-0.3.1-py3-none-any.whl
- Upload date:
- Size: 6.4 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 |
e13f606e3de0fe52bfa7c152940a32fb0445a4a0e452b0387062a2ffe70e1662
|
|
| MD5 |
35fd1bd0c710a35653637523ba31d9a8
|
|
| BLAKE2b-256 |
c3d34e93e993e3558fe70dc6ecda0e65694389b523dcebfa267515958cf99984
|
Provenance
The following attestation bundles were made for mkdocs_site_urls-0.3.1-py3-none-any.whl:
Publisher:
build.yml on OctoPrint/mkdocs-site-urls
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_site_urls-0.3.1-py3-none-any.whl -
Subject digest:
e13f606e3de0fe52bfa7c152940a32fb0445a4a0e452b0387062a2ffe70e1662 - Sigstore transparency entry: 468829127
- Sigstore integration time:
-
Permalink:
OctoPrint/mkdocs-site-urls@aa57181d674e852e9fb1a3d83ef32b32fd114d5a -
Branch / Tag:
refs/tags/0.3.1 - Owner: https://github.com/OctoPrint
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@aa57181d674e852e9fb1a3d83ef32b32fd114d5a -
Trigger Event:
release
-
Statement type: