Hooks¶
MkDocs hooks let you run Python code at specific points in the build process.
Creating a hook¶
Create a hooks.py file in your project root:
# hooks.py
def on_page_markdown(markdown, page, config, files):
"""Called for each page before Markdown is converted to HTML."""
return markdown
def on_post_build(config):
"""Called after the full site has been built."""
print("Build complete!")
Register it in mkdocs.yml:
hooks:
- hooks.py
Common use cases¶
- Inject custom variables into page content
- Post-process generated HTML
- Copy additional files to the
site/directory after build - Send a webhook notification when the build completes