MkDocs Exclude Plugin
mkdocs-exclude is a plugin for MkDocs that enables users to exclude files or entire directory trees from their documentation builds. It supports exclusion rules based on Unix-style wildcards (globs) or regular expressions (regexes). The current version is 1.0.2, and it is actively maintained as a solution for selective file exclusion in MkDocs projects.
Common errors
-
While parsing a block mapping, did not find expected key. (marked with "---" as the next element)
cause Incorrect YAML indentation for the `glob` or `regex` lists under the `exclude` plugin configuration.fixEnsure that the `glob:` and `regex:` keys are indented correctly under `exclude:`, and that each pattern within those lists starts with a hyphen and a space (`- pattern`). -
expected a single document but found a multi-document source
cause A pattern starting with a punctuation mark (e.g., `*`, `!`) was not quoted in the `mkdocs.yml` file, leading to YAML parsing issues.fixEnclose any patterns that begin with punctuation marks in quotes. For example, change `*.tmp` to `"*.tmp"` in glob patterns, or `'^.*\.bak$'` for regex patterns to preserve backslashes. -
Files are not being excluded from the build, even with patterns configured.
cause The `mkdocs-exclude` plugin might not be correctly enabled in `mkdocs.yml`, or the exclusion patterns themselves are incorrect/not matching the target files.fixVerify that `exclude:` is listed directly under the `plugins:` section in your `mkdocs.yml`. Double-check your `glob` and `regex` patterns against your file structure and test them to ensure they accurately target the files you intend to exclude. Remember glob is Unix-style, and regex is Python's regex flavor.
Warnings
- breaking MkDocs 2.0, currently under development, is a complete rewrite and will introduce backward-incompatible changes. This means all existing plugins, including `mkdocs-exclude`, will cease to function, and no direct upgrade path will be available. Users should be aware of this future incompatibility.
- gotcha YAML syntax for defining exclusion patterns requires careful attention to indentation and quoting. Incorrect indentation for `glob` or `regex` lists, or not quoting patterns that start with punctuation marks (e.g., `*.tmp`), will lead to parsing errors or patterns not being applied correctly.
- gotcha MkDocs versions 1.5 and later include a built-in `exclude_docs` configuration option. This provides similar file exclusion functionality using `.gitignore` pattern format directly within `mkdocs.yml`. Users should understand the differences and consider if the built-in option meets their needs before opting for the `mkdocs-exclude` plugin.
Install
-
pip install mkdocs-exclude
Quickstart
plugins:
- exclude:
glob:
- 'exclude/this/path/*'
- "*.tmp"
- "*.pdf"
- "*.gz"
regex:
- '.*\.(tmp|bin|tar)$'