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.3.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.3.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for mkdocs_build_cache_plugin-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7bb3ef55d5939197cb83ea7252d3b2412fe7ee0ff85dc825823b1b014cb1be84
MD5 51ccabfdfb65e0e91cf4c21084382912
BLAKE2b-256 d2df683d555a901f4b97d3b621362e7f54e9fa9d085326a1e5dba3e406c50203

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mkdocs_build_cache_plugin-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e6994b594ab394ceb27b0f18a85b38fbb82d8818492a72f6218f7c8bb882599
MD5 78ca7231a4a40de99f82e9fc7395ca38
BLAKE2b-256 679958297a2ea252169a27aa37d67de76695f932881c7ee96a9eaf53e06dee45

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