Skip to main content

A MkDocs plugin that adds support for site-relative URLs

Project description

MkDocs Site URLs Plugin

GitHub release PyPI Build status Code of Conduct Code style: black Imports: isort pre-commit

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

  1. Install the plugin from PyPI
    pip install mkdocs-site-urls
    
  2. Add the site-urls plugin to your mkdocs.yml plugins section:
    plugins:
      - site-urls
    
  3. 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)
    
    ![Image](site:images/foo.png)
    

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

  1. Create a venv & activate it, e.g. python -m venv venv && source venv/bin/activate
  2. Install the dev requirements: pip install -r requirements-dev.txt
  3. Install the pre-commit hooks: 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

mkdocs_site_urls-0.3.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_site_urls-0.3.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

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

Hashes for mkdocs_site_urls-0.3.1.tar.gz
Algorithm Hash digest
SHA256 6c39b4aca9d0d29d747513bb679f5cc4e5957e37895ea5a12589e139ed1af3a9
MD5 7a3fdccba4ea6d0e9572db94753da3d9
BLAKE2b-256 3f9cd02d2e089b128e9d84c46fb757738ae56bffce33b5ad90dec4f280d03436

See more details on using hashes here.

Provenance

The following attestation bundles were made for mkdocs_site_urls-0.3.1.tar.gz:

Publisher: build.yml on OctoPrint/mkdocs-site-urls

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mkdocs_site_urls-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_site_urls-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e13f606e3de0fe52bfa7c152940a32fb0445a4a0e452b0387062a2ffe70e1662
MD5 35fd1bd0c710a35653637523ba31d9a8
BLAKE2b-256 c3d34e93e993e3558fe70dc6ecda0e65694389b523dcebfa267515958cf99984

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page