Skip to main content

MkDocs plugin to strip numeric prefixes from page URLs while keeping them in source files

Project description

vexy-mkdocs-strip-number-prefix

PyPI version CI codecov License: MIT Python versions

A lightweight MkDocs plugin that strips numeric prefixes from page URLs while preserving them in source filenames for natural sorting.

Features

  • Clean URLs: Remove numeric prefixes from generated URLs
  • Natural Sorting: Keep prefixes in source files for predictable ordering
  • Collision Detection: Prevent duplicate URLs with configurable strictness
  • Link Rewriting: Automatically update internal markdown links
  • Flexible Patterns: Customize prefix matching with regex patterns
  • Debug Support: Verbose logging for troubleshooting

Installation

Install from PyPI:

uv pip install --system --upgrade vexy-mkdocs-strip-number-prefix

or from source:

pip install git+https://github.com/vexyart/vexy-mkdocs-strip-number-prefix

Quick Start

Add the plugin to your mkdocs.yml:

plugins:
  - search
  - strip-number-prefix

Name your files with numeric prefixes:

docs/
├── 010--introduction.md
├── 020--getting-started.md
├── 030--configuration.md
└── 999--faq.md

Build your site:

mkdocs build

Generated URLs will be clean:

  • /introduction/
  • /getting-started/
  • /configuration/
  • /faq/

Configuration

All configuration options with their defaults:

plugins:
  - strip-number-prefix:
      pattern: '^\\d+--'     # Regex pattern for prefix (default: '^\\d+--')
      verbose: false         # Enable debug logging (default: false)
      strict: true           # Fail on slug collisions (default: true)
      strip_links: false     # Strip prefixes from markdown links (default: false)

Pattern Examples

Pattern Matches Example
^\\d+-- Any digits + -- 123--file.md
^\\d{3}-- Exactly 3 digits + -- 001--file.md
^\\d+- Any digits + - 42-file.md
^\\d+\\. Any digits + . 1.file.md

Collision Handling

When multiple files would generate the same URL after prefix removal:

plugins:
  - strip-number-prefix:
      strict: true   # Fail build (recommended)
      # strict: false  # Log warning and continue

Link Rewriting

Automatically update internal markdown links:

plugins:
  - strip-number-prefix:
      strip_links: true

Before:

[Setup Guide](020--setup.md)

After:

[Setup Guide](setup.md)

Examples

Basic Usage

# mkdocs.yml
site_name: My Documentation
plugins:
  - strip-number-prefix

With Material Theme

# mkdocs.yml
site_name: My Documentation
theme:
  name: material
  features:
    - navigation.instant
    - navigation.sections

plugins:
  - search
  - strip-number-prefix:
      pattern: '^\\d{3}--'
      verbose: true

With Awesome Nav

# mkdocs.yml
site_name: My Documentation
plugins:
  - search
  - awesome-nav
  - strip-number-prefix:
      pattern: '^\\d+--'
      strip_links: true

Custom Pattern

# mkdocs.yml
plugins:
  - strip-number-prefix:
      pattern: '^\\d{2}\\.'  # Matches: 01.file.md, 99.file.md
      strict: false

File Organization Strategies

Sequential Numbering

docs/
├── 010--introduction.md
├── 020--installation.md
├── 030--configuration.md
├── 040--advanced.md
└── 999--troubleshooting.md

Hierarchical Numbering

docs/
├── 100--getting-started.md
├── 110--installation.md
├── 120--first-steps.md
├── 200--configuration.md
├── 210--basic-config.md
├── 220--advanced-config.md
└── 900--appendix.md

Category Prefixes

docs/
├── 01--intro/
│   ├── 010--overview.md
│   └── 020--quickstart.md
├── 02--guides/
│   ├── 010--setup.md
│   └── 020--deployment.md
└── 99--reference/
    └── 010--api.md

Compatibility

Troubleshooting

Duplicate URLs

ERROR: Multiple files would map to 'intro.md': 010--intro.md, 020--intro.md

Solution: Use unique base names:

  • 010--intro-basics.md
  • 020--intro-advanced.md

Broken Links

When strip_links: false (default), use clean slugs in links:

✅ [Next page](configuration.md)
❌ [Next page](030--configuration.md)

When strip_links: true, both forms work:

✅ [Next page](configuration.md)
✅ [Next page](030--configuration.md)  # Auto-converted

Debug Mode

Enable verbose logging:

plugins:
  - strip-number-prefix:
      verbose: true

This shows:

  • File transformations
  • URL mappings
  • Collision warnings
  • Link rewriting

Development

Setup

git clone https://github.com/yourusername/vexy-mkdocs-strip-number-prefix
cd vexy-mkdocs-strip-number-prefix
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -e .[dev]
pre-commit install

Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=mkdocs_strip_number_prefix --cov-report=html

# Run specific test
pytest tests/test_plugin.py::TestStripNumberPrefixPlugin::test_default_pattern

Code Quality

# Format and lint
black src tests
ruff check --fix src tests
mypy src

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Support

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

vexy_mkdocs_strip_number_prefix-1.0.1.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file vexy_mkdocs_strip_number_prefix-1.0.1.tar.gz.

File metadata

File hashes

Hashes for vexy_mkdocs_strip_number_prefix-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c5e0c9f4ccce3bb71748d357bd28e6eaa8fa8e5f6ea159e32d5bba06946676af
MD5 b2eaed164d70efcd59c0c489b75d4c43
BLAKE2b-256 0b3c911584437cc5c1236d5628c8b6f7e80bf0f7cfae0f71e40b7a7496d049c4

See more details on using hashes here.

File details

Details for the file vexy_mkdocs_strip_number_prefix-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for vexy_mkdocs_strip_number_prefix-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eaa8ba97a3ecf1ea5c6e56a271d699cf0b9863c09672edd145ed1f91200dddbb
MD5 818513e127dfc5b693f5fec32a41344d
BLAKE2b-256 ffaa9cd48cc202754bacc6578c7748a52b5b2ed87b6e6b8bdac201d639774d13

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