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

MkDocs Build Cache Plugin is a MkDocs plugin that speeds up your documentation builds by caching the build state. It computes a unique hash based on your configuration, source files, and any additional files you wish to include. If nothing has changed since the last build and your output directory already contains valid content, the plugin can abort the build early, saving valuable time.

Installation

Install the plugin via pip:

pip install mkdocs-build-cache-plugin

Alternatively, add it to your project’s dependencies.

Usage

To enable the plugin, add it to your mkdocs.yml configuration file. You can also pass an optional list of glob patterns to include additional files in the cache hash computation.

site_name: My Docs Site

plugins:
  - search
  - build_cache:
      include:
        - "extras/*.txt"
        - "assets/**/*.css"

How It Works

  1. Cache ID Calculation:
    When MkDocs starts, the plugin calculates a unique cache ID based on:

    • The main configuration file (if available).
    • All files under your docs_dir.
    • Any extra files that match the glob patterns provided in the include option.
  2. Build Skipping:

    • If a cache file exists and its cache ID matches the newly computed one and the output directory (site_dir) exists and is nonempty, the plugin raises an abort exception. This tells MkDocs that the build is up to date, and it can safely skip rebuilding.
    • Otherwise, the build proceeds normally. After a successful build, the plugin updates the cache file with the new cache ID.

Configuration Options

include

  • Type: List[str]

  • Default: []

  • Description:
    A list of glob patterns specifying extra files to be included in the cache hash computation. For example:

    include:
      - "extras/*.txt"
      - "assets/**/*.css"
    

Development

To run tests locally, ensure you have pytest installed and run:

pytest

Logging

This plugin uses the mkdocs.plugins logger namespace. You can control the log output via MkDocs’ verbosity flags (e.g., --verbose or --debug).

Contributing

Contributions, suggestions, and bug reports are welcome! Please open an issue or submit a pull request in the project's repository.

License

This project is licensed under the MIT License.

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.2.0.tar.gz (6.3 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.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for mkdocs_build_cache_plugin-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c158de7eff820b1353e55aa9de986fbef5825c022d0223ab3be485adcd579e5c
MD5 97ca386defa17e10e5329da6cd75d240
BLAKE2b-256 fdd1d2f470d9c1fd4386399274b5b32a4a666e669f6e1cee1917771e5acdde94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mkdocs_build_cache_plugin-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc8d1b6025b406e1fa34e5d68e778df25b29c3446dcd087ae23e7a0311ee86b7
MD5 48c2425bc53d7ac782a6999212e36c2a
BLAKE2b-256 706e414c179ae6ed8fd6cde525c0d1bb23bd083450d3d2d59f872d98d67e4dc3

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