Projects#

A project that has its own documentation can be shown under this site without rewriting it. The other project builds its documentation with Sphinx as usual. This site then copies the finished HTML into _build/html/projects/<name>/ at the end of every build, so it is served as part of the same website. This site does it for the Trade Engine project, whose documentation lives in a sibling folder:

projects/                       # parent folder
├── docs/                       # this site
└── trade_engine/
    └── docs/_build/html/       # built separately, then copied into this site

Steps#

  1. Build the other project’s documentation. For Trade Engine, from its own folder and virtual environment:

    cd ..\trade_engine
    sphinx-build -M html docs docs/_build
    
  2. Copy it in when this site is built. A hook at the bottom of source/conf.py runs after the HTML build. If the other project has not been built it only logs a warning, so the rest of the site still builds:

    # Separately built trade_engine docs, published under projects/trade_engine/.
    TRADE_ENGINE_HTML = os.path.abspath(
        os.path.join(os.path.dirname(__file__), '..', '..', 'trade_engine', 'docs', '_build', 'html'))
    
    
    def _copy_trade_engine_docs(app, exception):
        if exception or app.builder.format != 'html':
            return
        if not os.path.isdir(TRADE_ENGINE_HTML):
            from sphinx.util import logging
            logging.getLogger(__name__).warning(
                'trade_engine docs not built: %s', TRADE_ENGINE_HTML)
            return
        shutil.copytree(TRADE_ENGINE_HTML, os.path.join(app.outdir, 'projects', 'trade_engine'),
                        ignore=shutil.ignore_patterns('.doctrees', '.buildinfo'),
                        dirs_exist_ok=True)
    
    
    def setup(app):
        app.connect('build-finished', _copy_trade_engine_docs)
    

    Change the folder name and the target path for your own project. For several projects, loop over a list of (source folder, target name) pairs inside the hook.

  3. Add a page that leads to it. The copied files are not part of this site’s navigation, so source/projects/trade_engine.rst is a small page that appears in the menu and sends the reader on:

    Trade Engine
    ============
    
    .. raw:: html
    
        <meta http-equiv="refresh" content="0; url=trade_engine/index.html">
    
    A short description of the project.
    
    `Open the Trade Engine documentation <trade_engine/index.html>`_
    

    The raw block redirects the browser straight to the copied documentation. The link below it is for readers whose browser does not follow the redirect.

  4. List the page in the toctree of source/projects/index.rst and, if you like, add a card for it on the home page (see Theme and Customisation).

Projects whose documentation does not need to be built separately can simply be a new .rst page, or a folder of pages like this section, listed in the same toctree.