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 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>`_.
- In general, Markdown syntax is less cumbersome than RsT's.
For example:
- Works with Backstage TechDocs.
- Easier configuration in
mkdocs.ymlvs.docs/conf.py - Extensible with many plugins including macros
which I use here to substitute the
view_uriin references.
Con¶
RsT markup in Python docstrings will have to be refactored to Markdown.- Also extensible via plugins and with any Python code you care to add to
conf.py. - Alternatives to
apidocare not great. The closes seems to bemkdocstringswhichfails to work with some DRF components.
Converting this project to MkDocs¶
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_uribased 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.ymladd the document hierarchy that is indocs/index.rst.
Viewing MkDocs-generated content locally¶
This is easily accomplished:
1 | |
Note
The default port for mkdocs serve is 8000 which is also what we use for our django app.
Publishing to RTD¶
Readthedocs easily supports both Sphinx and MkDocs through
a configuration file. Changing this project over 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 22 23 24 | |