mkdocs-gen-files

0.6.1 · active · verified Sat Apr 11

mkdocs-gen-files is an MkDocs plugin that allows users to programmatically generate documentation pages and modify existing ones during the MkDocs build process. It's particularly useful for creating dynamic content, API documentation from code, or custom navigation structures using Python scripts. The current version is 0.6.1, and releases are often tied to MkDocs compatibility or feature enhancements, without a strict schedule.

Warnings

Install

Imports

Quickstart

To use mkdocs-gen-files, first configure it in your `mkdocs.yml` to specify the Python scripts it should run. Then, create a Python script (e.g., `gen_pages.py`) where you can use `mkdocs_gen_files.open` to write content to new documentation pages. The quickstart demonstrates creating a basic markdown file.

### mkdocs.yml
plugins:
  - gen-files:
      scripts:
        - gen_pages.py

### gen_pages.py
import mkdocs_gen_files

# Generate a simple markdown file
with mkdocs_gen_files.open("generated/example.md", "w") as f:
    f.write("# Hello from mkdocs-gen-files!\n\n")
    f.write("This page was created dynamically at build time.\n")

# Optional: Add to navigation (requires mkdocs-literate-nav)
# from mkdocs_gen_files import nav
# nav["Generated Content/Example"] = "generated/example.md"

print("Successfully generated 'generated/example.md'")

view raw JSON →