Skip to main content

MkDocs plugin to check if a build is necessary by hashing configuration and documentation files.

Project description

MkDocs Build Cache Plugin

A simple MkDocs plugin to cache build outputs and skip rebuilds when nothing has changed. This plugin computes a unique hash based on your MkDocs configuration and source files, and only triggers a rebuild when changes are detected.

Features

  • Build Caching: Saves a cache file (build_cache.json) that stores a hash of the build configuration and source files.
  • Skip Unnecessary Rebuilds: If the computed hash matches the cache file from a previous build, the plugin will skip the rebuild process.
  • Seamless MkDocs Integration: Built as a standard MkDocs plugin that hooks into the on_config and on_post_build events.

Installation

pip install mkdocs-build-cache-plugin

Usage

  1. Configure MkDocs: In your mkdocs.yml, add the plugin to your plugins list:

    plugins:
      - search
      - build-cache
    
  2. Run MkDocs: When you run mkdocs build, the plugin will compute a cache ID based on your configuration and documentation files. If nothing has changed since the last build, the plugin will log a message and skip the rebuild.

How It Works

  • on_config: During the configuration phase, the plugin computes a SHA-256 hash of your MkDocs configuration and the content of all files in the docs_dir.

    • If a cache file (build_cache.json) exists and its stored hash matches the computed hash, the plugin raises a BuildCacheAbort exception to skip the build.
    • Otherwise, it sets the build_cache_id in the configuration.
  • on_post_build: After a successful build, the plugin writes the computed hash to build_cache.json for future comparisons.

Development and Testing

The project uses pytest for testing. To run the tests:

  1. Install the development dependencies:

    pip install -r requirements/dev.txt
    
  2. Run the tests:

    pytest
    

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/my-new-feature).
  3. Commit your changes (git commit -am 'Add new feature').
  4. Push to the branch (git push origin feature/my-new-feature).
  5. Create a new Pull Request.

License

This project is licensed under the MIT License.

Acknowledgments

  • MkDocs for the excellent static site generator.

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_build_cache_plugin-0.1.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

mkdocs_build_cache_plugin-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs_build_cache_plugin-0.1.0.tar.gz.

File metadata

File hashes

Hashes for mkdocs_build_cache_plugin-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a993a3275ae76bb3f83d5584e43f821f9214cb7d61260b93c4d68ecd7a151368
MD5 82c30b95fbf0cf8753d8416beb64c282
BLAKE2b-256 55822b72a176d86de6dd7c49fa8dcdd2cfdbf2aac85c366427c0638a6b01eb1c

See more details on using hashes here.

File details

Details for the file mkdocs_build_cache_plugin-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_build_cache_plugin-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7504f2c14d2570050469ea70ca8f92bb4638013c548019014db14666a80a8b89
MD5 b8122eb97cd17e5ae8f4d9a701c2388e
BLAKE2b-256 27aec57bb72675896c1e939a8d521f87a4223f099e9ca4ad1c849b40cb3af4eb

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