I would like to include one of my files in my Sphinx TOC only when a certain tag is set, however the obvious approach fails:
.. toctree::
:maxdepth: 5
index
core
utils
oec
plotting
install
news
glossary
.. only:: private_version
todo
Is there a simple way to accomplish this?
In a past I had a need to be able to compile two documentations from the same source file: a public and a private.
To succeed I had to write my own plugin (that you can find here).
When I have a file to be only on private documentation I just add this following directive on the top of the file (mandatory)
.. meta::
:scope: private_version
public-sample.rst (nothing special)
Title
=====
A public content
private-sample.rst
.. meta::
:scope: private_version
Title
=====
A private content
index.rst
.. toctree::
:maxdepth: 3
public-sample.rst
private-sample.rst
As you can see on toctree
there is the both reference, but the plugin will remove the private-sample.rst during compilation if you'r not building with tag private
So using
sphinx-build ... -t private_version ...
Will generate toctree
like:
but if you build with
sphinx-build ... -t other ...
or
sphinx-build ...
the toctree
will look like
My plugin is not 100% perfect but I just a small piece of code a easy to understand so you can edit like you want :)
Know limitations:
limitation:
meta
directive docutils.sourceforge.net/docs/ref/rst/directives.html#metaIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With