|
1 | 1 | # pandas-sphinx-theme
|
2 | 2 |
|
3 |
| -This repo holds a temporary copy of the pandas documentation to experiment |
4 |
| -with a new sphinx theme. |
| 3 | +A Bootstrap-based sphinx theme. |
5 | 4 |
|
6 | 5 | Demo site: https://dev.pandas.io/pandas-sphinx-theme/
|
7 | 6 |
|
| 7 | +**Note**: This theme is originally being developed for the pandas docs (hence the name), |
| 8 | +but since there is uptake in other projects, we are working on making this more |
| 9 | +generic and more easily extensible to suit the needs of the different projects |
| 10 | +(and need a rename as well). |
| 11 | + |
| 12 | +Sites that are using this theme: |
| 13 | + |
| 14 | +- Pandas: https://dev.pandas.io/docs/ |
| 15 | +- Bokeh: https://docs.bokeh.org/en/dev/ |
| 16 | + |
| 17 | +This repo holds a temporary (slimmed down) copy of the pandas documentation to |
| 18 | +test the theme with on PRs. The result is hosted at the demo site. |
| 19 | + |
| 20 | +## Installation and usage |
| 21 | + |
| 22 | +This theme is not yet released as a package on PyPI, but you can already install |
| 23 | +and use as follows: |
| 24 | + |
| 25 | +- Install the `pandas-sphinx-theme` in your doc build environment from the git |
| 26 | + repo. You can do this manually with pip: |
| 27 | + |
| 28 | + ``` |
| 29 | + pip install git+https://github.com/pandas-dev/pandas-sphinx-theme.git@master |
| 30 | + ``` |
| 31 | +
|
| 32 | + or in a conda environment yml file, you can add: |
| 33 | +
|
| 34 | + ``` |
| 35 | + - pip: |
| 36 | + - git+https://github.com/pandas-dev/pandas-sphinx-theme.git@master |
| 37 | + ``` |
| 38 | +
|
| 39 | +- Then, in the `conf.py` of your sphinx docs, you update the `html_theme` |
| 40 | + configuration option: |
| 41 | +
|
| 42 | + ``` |
| 43 | + html_theme = "pandas_sphinx_theme" |
| 44 | + ``` |
| 45 | +
|
| 46 | +And that's it! |
| 47 | +
|
| 48 | +Well, in principle at least. In practice, there are might still be a few |
| 49 | +pandas-specific things that are right now hard-coded in the theme. We also need |
| 50 | +to work on better configurability and extensibility. Feedback and contributions |
| 51 | +are very welcome! |
| 52 | +
|
| 53 | +## How is this theme working? |
| 54 | +
|
| 55 | +### The html layout |
| 56 | +
|
| 57 | +The "layout" included in this theme is originally mainly targetted towards |
| 58 | +documentation sites with many pages, and where putting all navigation in a |
| 59 | +single sidebar can therefore get unwieldy. |
| 60 | +
|
| 61 | +The current layout features 3 navigation elements: |
| 62 | +
|
| 63 | +- A top navbar with top-level navigation |
| 64 | +- A left sidebar with subsequent navigation up to single pages |
| 65 | +- A right sidebar with a local "On this page" table of contents |
| 66 | +
|
| 67 | +What is put where is determined by the sphinx "toctree" (and such depending on |
| 68 | +the structure of your sphinx docs). The first level of the toctree is put in the |
| 69 | +top navbar, and the second (and potentially) third level is put in the left |
| 70 | +sidebar. |
| 71 | +
|
| 72 | +It should certainly be possible to make the exact used levels of the sphinx |
| 73 | +toctree configurable. |
| 74 | +
|
| 75 | +### Implementation details |
| 76 | +
|
| 77 | +A second aspect of the design of this theme is that we are trying to make good |
| 78 | +use of Bootstrap features and use as much as possible actual (templated) html |
| 79 | +and css to define the theme, instead of relying on sphinx to do custom |
| 80 | +formatting. This should make the theming and layouts more flexible to customize. |
| 81 | +
|
| 82 | +To this end, this package includes: |
| 83 | +
|
| 84 | +- A [`BootstrapHTML5Translator`](./pandas_sphinx_theme/bootstrap_html_translator.py), |
| 85 | + subclassing sphinx' translator, but overriding certain elements to generate |
| 86 | + Bootstrap-compatible html. Currently, this includes: converting admonitions to |
| 87 | + Bootstrap "alert" classes, and updating the classes used for html tables. |
| 88 | +- A [sphinx "monkeypatch"](./pandas_sphinx_theme/__init__.py) to add toctree |
| 89 | + objects into the html context which is available in the html (jinja2) |
| 90 | + templates. This allows to put the structure of the navigation elements in the |
| 91 | + actual layout, instead of having to rely on the hard-coded formatting of |
| 92 | + sphinx (this is inspired on the navigation objects of mkdocs: |
| 93 | + https://www.mkdocs.org/user-guide/custom-themes/#nav). We would love to see |
| 94 | + this added to sphinx itself (instead of needing to monkeypatch), but for not |
| 95 | + did not yet get any reaction from the sphinx developers. |
| 96 | +
|
| 97 | +Those items also avoid writing javascript functions to "fix up" the html |
| 98 | +generated by sphinx to make it suitable for theming. |
| 99 | +
|
| 100 | +### What's the difference with bootstrap-sphinx-theme ? |
| 101 | +
|
| 102 | +There is already a sphinx Bootstrap theme used by some project in the community: |
| 103 | +https://github.com/ryan-roemer/sphinx-bootstrap-theme/ |
| 104 | +
|
| 105 | +Currently, the main difference is that this theme is using Bootstrap 4 instead |
| 106 | +of 3 and provides a different default layout. At some point, it would be good to |
| 107 | +contribute changes to that package (or at least the parts that deal with |
| 108 | +Bootstrap and sphinx that could be shared). |
0 commit comments