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.1.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.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for mkdocs_build_cache_plugin-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2948588d3d550a5633a6b5d6f34f4e91c60f44d0124b2a03f23d58a14ab7dae0
MD5 b739009293d36d58617b51fde0e0e2c4
BLAKE2b-256 14765b99279c55d1651f0558b5b7e44228e359464ed1fd87471257c61208096c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mkdocs_build_cache_plugin-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f7bace06f9965107bea7a3f39ae6837b30ca5c6b4765435625c95cced2401b5a
MD5 80b768288ed9c97c29d386329740cb72
BLAKE2b-256 4f6c3775804771a124222d62b085d766ccd265e609c326a0b559d80767ffea42

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