Search code examples
pythoncsspython-sphinxread-the-docs

What is an easy way to do a local Sphinx build with the static assets readthedocs.org uses?


Currently, the only way I can find to get current design assets used by readthedocs.org is to install the full theme, and build it, which requires SASS, etc.

I'd like to just get a static set of files that would let me see locally what my build will look like on readthedocs. Is there a way to do this without building the assets myself from the above link? The goal is for it to be easy for novices to contribute to the docs.


Solution

  • You only need to build the theme if you want to contribute/develop for it. You can install the theme using pip install sphinx_rtd_theme. You can then use the theme in your Sphinx conf.py. See: http://read-the-docs.readthedocs.org/en/latest/theme.html

    # on_rtd is whether we are on readthedocs.org
    import os
    on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
    
    if not on_rtd:  # only import and set the theme if we're building docs locally
        import sphinx_rtd_theme
        html_theme = 'sphinx_rtd_theme'
        html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
    
    # otherwise, readthedocs.org uses their theme by default, so no need to specify it