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_configandon_post_buildevents.
Installation
pip install mkdocs-build-cache-plugin
Usage
-
Configure MkDocs: In your
mkdocs.yml, add the plugin to your plugins list:plugins: - search - build-cache
-
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 aBuildCacheAbortexception to skip the build. - Otherwise, it sets the
build_cache_idin the configuration.
- If a cache file (
-
on_post_build: After a successful build, the plugin writes the computed hash to
build_cache.jsonfor future comparisons.
Development and Testing
The project uses pytest for testing. To run the tests:
-
Install the development dependencies:
pip install -r requirements/dev.txt
-
Run the tests:
pytest
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/my-new-feature). - Commit your changes (
git commit -am 'Add new feature'). - Push to the branch (
git push origin feature/my-new-feature). - 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
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_build_cache_plugin-0.1.0.tar.gz.
File metadata
- Download URL: mkdocs_build_cache_plugin-0.1.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a993a3275ae76bb3f83d5584e43f821f9214cb7d61260b93c4d68ecd7a151368
|
|
| MD5 |
82c30b95fbf0cf8753d8416beb64c282
|
|
| BLAKE2b-256 |
55822b72a176d86de6dd7c49fa8dcdd2cfdbf2aac85c366427c0638a6b01eb1c
|
File details
Details for the file mkdocs_build_cache_plugin-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mkdocs_build_cache_plugin-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7504f2c14d2570050469ea70ca8f92bb4638013c548019014db14666a80a8b89
|
|
| MD5 |
b8122eb97cd17e5ae8f4d9a701c2388e
|
|
| BLAKE2b-256 |
27aec57bb72675896c1e939a8d521f87a4223f099e9ca4ad1c849b40cb3af4eb
|