A MkDocs plugin that lets you exclude/include docs files using globs, regexes and gitignore-style file.
Project description
File exclude/include plugin for MkDocs
mkdocs-file-filter
is a mkdocs plugin that allows you to exclude/include files from your input using Unix-style wildcards (globs), regular expressions (regexes) or .mkdocsignore file (gitignore-style syntax).
Quick start
- Install the plugin using pip.
pip install mkdocs-file-filter-plugin
- In your project, add a plugin configuration to
mkdocs.yml
:
plugins:
- file-filter:
mkdocsignore: true
mkdocsignore_file: 'custom/path/.mkdocsignore' # relative to mkdocs.yml
exclude_glob:
- 'exclude/this/path/*'
- 'exclude/this/file/draft.md'
- '*.tmp'
- '*.gz'
exclude_regex:
- '.*\.(tmp|bin|tar)$'
include_glob:
- 'include/this/path/*'
- 'include/this/file/Code-of-Conduct.md'
- '*.png'
- 'assets/**' # the material theme requires this folder
include_regex:
- '.*\.(js|css)$'
External config file
The plugin supports external files for the plugin configuration. If the external config file is specified, then *_glob:
and *_regex:
are not taken mkdocs.yml
- only config from the external file applies.
plugins:
- file-filter:
# config: !ENV [MY_FILE_FILTER_CONFIG, 'mkdocs.file-filter.yml']
config: mkdocs.file-filter.yml
External plugin config file example.
mkdocsignore: false
exclude_glob:
- 'exclude/this/path/*'
- 'exclude/this/file/draft.md'
- '*.tmp'
- '*.gz'
exclude_regex:
- '.*\.(tmp|bin|tar)$'
include_glob:
- 'include/this/path/*'
- 'include/this/file/Code-of-Conduct.md'
- '*.png'
- 'assets/**' # the material theme requires this folder
include_regex:
- '.*\.(js|css)$'
HINT
For external file config, you can use MkDocs Environment Variables to set the desired file dynamically. A useful case for serving the site with different content based on stage/environment. Works well with CI/CD automation.
.mkdocsignore
Setting mkdocsignore
to true
will exclude the dirs/files specified in the .mkdocsignore
. Use the same syntax as you use for gitignore.
Optionally you can set mkdocsignore_file
parameter with your path to .mkdocsignore
file. By default, the plugin uses .mkdocsignore
from the root of your MkDocs.
You can combine mkdocsignore with globs/regex as well. The patterns from both will apply.
External config for mkdocsignore.
plugins:
- file-filter:
mkdocsignore: true # default: false
mkdocsignore_file: 'custom/path/.myignore' # relative to mkdocs.yml, default: .mkdocsignore
Example .mkdocsignore
file.
# MkDocs
docs/test/**
docs/**/draft-*.md
Conflict behavior
It is possible to exclude and include will have conflict. For example, you could exclude drafts/*
but include *.md
. In that case, include has higher priority over exclude. So all *.md
files from the drafts folder will be included.
Some useful stuff
If you do not provide patterns, everything will stay the same - standard MkDocs behavior.
Because of the YAML syntax specifics, patterns that start with a punctuation mark must be quoted.
The preferred way for quotes is to use single quotes '
rather than double quotes "
- regex backslash escapes are preserved correctly without being doubled up.
License
mkdocs-file-filter-plugin
is distributed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
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
Hashes for mkdocs_file_filter_plugin-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70843a2d8448e366c397c263c38f5b01fb373c9b347c0d807bdc8af06add028a |
|
MD5 | bfd08ab2845f0a8d43947d9d1e5f9877 |
|
BLAKE2b-256 | e2417dae8337b7d01e2ed893404e548a2900ef91311a44588d03f7b8071006cc |
Hashes for mkdocs_file_filter_plugin-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04d2c3270d02bbb45ecd615c09e7c2ed77efa6d128e6afa6ab2bddc7f2207706 |
|
MD5 | 023df02e669e51eaae6484465c268edc |
|
BLAKE2b-256 | 8f56bc468ed1af016c789c287bb4a22016c79810516da45c4d21933cb86517ac |