bashtage / sphinx-material

A material-based, responsive theme inspired by mkdocs-material
Other
317 stars 91 forks source link

Theme not building on readthedocs.io - defaulting to its own theme #94

Closed brybalicious closed 3 years ago

brybalicious commented 3 years ago

Is there any possibility to build this theme and host it on readthedocs without readthedocs defaulting to its own theme?

Some other custom themes provide a snippet in conf.py which apparently achieves this, e.g. this theme. Readthedocs also provides the same snippet in its documentation

if not on_rtd:  # only import and set the theme if we're building docs locally
     import sphinx_material
     # Required theme setup
     html_theme = 'sphinx_material'
     # html_theme_path = [sphinx_material.get_html_theme_path('sphinx_material')]
     html_theme_path = ["_themes/sphinx_material", ]`
# otherwise, readthedocs.org uses their theme by default, so no need to specify it

When I tried to implement this, html_theme_path = [sphinx_material.get_html_theme_path('sphinx_material')] fails with AttributeError: module 'sphinx_material' has no attribute 'get_html_theme_path', so I directly referenced the theme directory.

It's also unclear how the directory should be structured if just incorporating code into another project (i.e. where init.py and the rest of the sphinx_theme directory structure ought to sit relative to conf.py. In my case, I added an _themes directory one level up from the docs. Inside that, are located the __init__.py and _version.py scripts, and a directory sphinx_materials which houses theme.conf, the static directory and the html pages. I deleted everything else. Is this correctly implemented? Thanks

brybalicious commented 3 years ago

Ah.. I realised that some of that is already handled in the __init.py__ setup function. Hence why only this is required:

if not on_rtd:  # only import and set the theme if we're building docs locally
    import sphinx_material
    # Required theme setup
    html_theme = 'sphinx_material'

Then the question still stands... how to get this to build on readthedocs.io?

bashtage commented 3 years ago

You need to add it to your requirements files that is used by RTF's builder. You can then trigger a build using the admin console. I don't there there is anything special about building on RTD.

See this conf.py

https://github.com/WoLpH/django-utils/blob/2bb777071f5d9b55f4e095c59b164360bcbea8d5/docs/conf.py#L130

The produces these docs on RTD:

https://django-utils2.readthedocs.io/en/latest/