Skip to main content

mkdocs plugin to control the base_url, for use with mike (for multiple versions) and i18n.

Project description

mkdocs-modify-base-url

This mkdocs plugin is meant to be used with:

The code in mkdocs-material that renders the version selection dropdown in the header dynamically requests versions.json relative to the page's base_url. This works well normally, but when you try to add multiple languages, things start to get a bit tricky.

I've set up my project documentation inside my repo like this:

.
├─ config/
│    ├─ en/
│    │  └─ mkdocs.yml
│    ├─ nl/
│    │  └─ mkdocs.yml
│    ├─ .../
│
├─ content/
│    ├─ en/
│    │   ├─ index.md 
│    │   └─ ...
│    └─ nl/
│        ├─ index.md 
│        └─ ,,,
│
├─ generated/
│    ├─ branch
│    │  ├─ en/
│    │  └─ nl/
│    └─ index.html
│
└─ ...

Each language has its own mkdocs.yml. Each is configured like this (only showing relevant parts, using en as an example):

docs_dir: '../../content/en'
site_dir: '../../generated/branch/en'
theme:
  language: en
extra:
  version:
    provider: mike
  alternate:
  - name: English
    link: en
    lang: en

plugins:
- modify-base-url:
    prefix: '../'

All languages are individually generated into docs/generated/branch/$LANGUAGE

There is a separate mkdocs.yml for mike to support versioning. There is really only one key, required setting, that tells mike to use what we previously generated:

docs_dir: generated/branch

When you run mike deploy VERSION from within the docs directory, it combines all the generated documentation for all the languages into a single version. There is also a static index.html file in docs/generated/branch that redirects initial requests to a default language.

Given a URL such as docs.kcp.io/kcp/main/en, when visiting index.html, its base_url is normally . because we told mkdocs to generate directly into the en directory. What's unique about this situation is that mkdocs thinks that one level up from en should be where versions.json lives. But it's actually up one more level, at docs.kcp.io/kcp/versions.json because of our configuration.

And this is why this plugin exists. We need to adjust the base_url to move it up one more level, so instead of it being . for docs.kcp.io/kcp/main/en/index.html, it's actually ... Now, when mkdocs-material requests base_url/../versions.json, that becomes ../../versions.json, which is really docs.kcp.io/kcp/versions.json.

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-modify-base-url-0.0.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

mkdocs_modify_base_url-0.0.2-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs-modify-base-url-0.0.2.tar.gz.

File metadata

  • Download URL: mkdocs-modify-base-url-0.0.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for mkdocs-modify-base-url-0.0.2.tar.gz
Algorithm Hash digest
SHA256 5980cb3d5c4197a551b2c4c9f068c10c60b01a850f7be7391565a047a2fb6f2a
MD5 2dcdcdc35a36494c2416345ba76123dd
BLAKE2b-256 bd0c34ea2ec1bf63867ac2ecd190c3d57ac20321db979a644e38c1a38bc1007d

See more details on using hashes here.

File details

Details for the file mkdocs_modify_base_url-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_modify_base_url-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0df1d860a047f2a023debab4414db53ead377c8c1742592f8f77c7b9b00381e2
MD5 1e853a74787bb2410cff4ed701098f45
BLAKE2b-256 7b903d47cdca99af8be3d5810ac86fb3f2aa65b18fc1e2da30e9a5fde04831eb

See more details on using hashes here.

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