Mkdocs Documentation¶
About MkDocs¶
MkDocs is a general-purpose tool for generating project documentation using Markdown files.
MkDocs vs. Sphinx¶
Sphinx is the initial tool I decided to use for documenting this project. I've since been experimenting with the Backstage developer portal which currently uses MkDocs for their TechDocs tool so I figured I'd experiment with MkDocs.
A few pros and cons of MkDocs with the mkdocstrings plugin over Sphinx with the autodoc extension:
Pro¶
- Only uses Markdown. No more RsT, which is Python-specific, and kind of ugly.
* In general, Markdown syntax is less cumbersome than RsT's. For example:
[sitename](url)
vs.`sitename <url>`_
. - Works with Backstage TechDocs.
- Easier configuration in
mkdocs.yml
vs.docs/conf.py
- Extensible with many plugins including macros
which I use here to substitute the
view_uri
in references.
Con¶
- RsT markup in Python docstrings will have to be refactored to Markdown. Maybe this is a Pro.
- Docstrings will have to be refactored from RsT to Google-style.
*
#:
comments before members →""" docstrings """
after them (which is also supported by Sphinx autodoc) * Intersphinx references like:py:class:`~django.db.models.Model`
→[django.db.models.Model](https://docs.djangoproject.com/en/3.0/ref/models/instances/#django.db.models.Model)
* URL refs from`sitename <url>`_
→[sitename](url)
. TODO: move this down. - Also extensible via plugins and with any Python code you care to add to
conf.py
. - Alternatives to
apidoc
are not great. The closes seems to bemkdocstrings
which fails to work with some DRF components.
Converting this project to MkDocs¶
Since my docs are already in Markdown, converting from Sphinx was easy and can mostly coexist. Here's a summary of changes I made:
See docs/requirements-mkdocs.txt
.
1 2 3 4 5 6 7 8 |
|
- Use backstage.io's techdocs-core plugin which brings in several others.
- Use macros plugin as described above, including
this custom code which:
defines
view_uri
based on the git repo configuration.This requires adding{{view_uri}}
in URL references in the various markdown files which previously didn't have any links. You can also use macros like{{git.date}}
to show the repo date.
- Mkdocstrings for automated API documentation.
- In
mkdocs.yml
add the document hierarchy that is indocs/index.rst
.
Viewing MkDocs-generate content locally¶
This is easily accomplished. Simply use:
1 |
|
Publishing to RTD¶
Readthedocs easily supports both Sphinx and MkDocs through
a configuration file. Changing this project over simply required adding
.readthedocs.yaml
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|