Modifying content width of the Sphinx theme 'Read the Docs'

前端 未结 9 863
小鲜肉
小鲜肉 2020-12-13 18:04

I am using \'Read the Docs\' Sphinx theme for my documentation. In the original theme, given below

http://read-the-docs.readthedocs.org/en/latest/theme.html

9条回答
  •  悲哀的现实
    2020-12-13 18:28

    The solutions here are somewhat hackish. If you want to include the style, and have a css override and have it work on RTD you will want something like this.

    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()]
      html_style = 'css/custom.css'
    else:
      html_context = { 
        'css_files': [
            'https://media.readthedocs.org/css/sphinx_rtd_theme.css',
            'https://media.readthedocs.org/css/readthedocs-doc-embed.css',
            '_static/css/custom.css',
        ],  
      }   
    

    I have tested this myself and it appears to work locally and on RTD. Largely plagiarized from https://blog.deimos.fr/2014/10/02/sphinxdoc-and-readthedocs-theme-tricks-2/

提交回复
热议问题