MkDocs
MkDocs is a fast, simple, and downright gorgeous static site generator that's geared towards building project documentation with Markdown. It converts a directory of Markdown files and a YAML configuration into a static website. The current version is 1.6.1, and it maintains an active release cadence with several patch and minor releases per year to address bugs and introduce new features.
Warnings
- breaking The `config.extra_javascript` option in `mkdocs.yml` changed behavior in version 1.5.0. It is no longer strictly a list of strings but can now contain mappings with keys like `type`, `async`, and `defer`. Plugins or themes directly manipulating this list must adapt.
- breaking In version 1.6.0, the `exclude_docs` configuration option no longer provides 'drafts' functionality during `mkdocs serve`. Files specified under `exclude_docs` are now *always* excluded. A new option, `draft_docs`, was introduced for files that should appear during `serve` but not `build`.
- gotcha As of version 1.5.0, `mkdocs serve` no longer exits immediately after detecting re-build errors (e.g., in configuration or plugins). Instead, it freezes the server, waiting for the user to fix the issue. Initial build errors, however, still cause an exit.
- gotcha The `site_url` configuration option is now effectively required for correct deployment, especially for features like sitemap generation and canonical URLs. Failing to set it, particularly when deploying to a subdirectory, can lead to broken links or incorrect metadata.
Install
-
pip install mkdocs -
pip install mkdocs[i18n]
Imports
- plugins
import mkdocs.plugins
- config
from mkdocs import config
Quickstart
import os
# Create a new MkDocs project
os.system("mkdocs new my-docs-project")
# Change into the project directory
os.chdir("my-docs-project")
# Start the development server (runs in the background for this example)
# In a real scenario, you'd run this from your terminal and visit http://127.0.0.1:8000
print("Run 'mkdocs serve' in your terminal in the 'my-docs-project' directory to preview your site.")
print("To open in browser automatically: 'mkdocs serve --open'")