Quick start¶
Nefertiti for Sphinx can be setup and running in a blink of an eye. Follow this quick start guide to go through the minimal steps to use it with your project.
Note
This page assumes that you want to try Nefertiti on an already existing Sphinx project.
In a blink of an eye¶
Install the package from PyPI:
pip install sphinx-nefertiti
Edit the conf.py file in your documentation directory and change your html_theme setting:
html_theme = "sphinx_nefertiti"
Now rebuild the docs and serve them to get a first glimpse of your site made up with Nefertiti.
Within the directory of your conf.py file:
make clean
make html
python -m http.server -d build/html
Visit http://localhost:8000.
Customize the theme¶
The following features of Nefertiti for Sphinx can be customized:
Fonts.
Color set: blue, indigo, purple, pink, red, …
Pygments styles for light and dark color schemes.
Repository name and URL to display it in the header.
Project version dropdown selector.
Footer links.
1. Fonts¶
There are 5 options related to font face customization and 2 options related to font size.
The font face options are:
sans_serif_font: Default site font, defaults to Nunito.monospace_font: Default monospace font, for code blocks, defaults to Red Hat Mono.project_name_font: The font for the Project’s name.sans_serif_fontotherwise.documentation_font: reStructuredText and Markdown content.sans_serif_fontotherwise.doc_headers_font: To render documentation headers.documentation_fontotherwise.
And the font size options:
monospace_font_size: The CSSfont-sizefor themonospace_font. ie:"1rem".documentation_font_size: The CSSfont-sizefor thedocumentation_font. ie:"1.1rem".
Edit your conf.py file and add or modify your html_theme_options setting with the following content. By the way, the fonts referred to in this example are part of the Nefertiti for Sphinx distribution. If you want to use other Open Source licensed fonts read the section “How to add more fonts” to include them with your project.
html_theme_options = {
"sans_serif_font": "Mulish",
"monospace_font": "Ubuntu Mono",
"monospace_font_size": "1.1rem",
"project_name_font": "Montserrat",
"documentation_font": "Assistant",
"documentation_font_size": "1.1rem",
"doc_headers_font": "Georgia",
}
2. Color sets¶
Another customizable feature of the theme is the color set. In the header of this documentation you can see a dropdown with a palette icon. The colors listed in the dropdown represent the available color sets. Try them to apply the selected color set to this documentation.
To customize the color set in your project add an entry style to the html_theme_options setting in your conf.py module:
html_theme_options = {
# ... other options ...
"style": "pink",
}
When style is not given the theme defaults to cyan.
3. Pygments styles¶
Pygments is the package in charge of rendering code blocks. Sphinx supports two settings related with pygments:
pygments_style, applied when browser’sprefers-color-schemereturns light.pygments_dark_style, applied when browser’sprefers-color-schemereturns dark.
Nefertiti for Sphinx extends the use of these settings in a way that their styling is applied when the user selects the scheme in the light/dark dropdown, at the right side of the header.
If your Sphinx project has code-blocks, try changing the pygments style settings and see how they are applied when switching between light and dark schemes in the header. Update your conf.py module:
pygments_style = "solarized-light"
pygments_dark_style = "solarized-dark"
See more code blocks rendered with Pygments in the Code blocks document in Nefertiti User’s Guide.
4. Repository data¶
If your Sphinx project is about a source code product, and it resides in a Git repository, in GitHub or GitLab, Nefertiti can display information relative to your repository in the header.
Just add the repository_name and repository_url keys to your html_theme_options setting:
html_theme_options = {
# ... other options ...
"repository_name": "danirus/sphinx-nefertiti",
"repository_url": "https://github.com/danirus/sphinx-nefertiti",
}
5. Version dropdown¶
If your project is available in different versions Nefertiti for Sphinx can display a dropdown in the header to switch between them.
If you host different versions in different URLs, like:
Version |
URL |
|---|---|
v2.9.9 |
|
v2.8.5 |
|
v2.7.2 |
Enable the version dropdown by adding the versions key to your html_theme_options setting:
html_theme_options = {
# ... other options ...
"versions": [
("v2.9.9", "https://sample-project.readthedocs.io/en/latest/"),
("v2.8.5", "https://sample-project.readthedocs.io/en/2.8.5/"),
("v2.7.2", "https://sample-project.readthedocs.io/en/2.7.2/"),
]
}
The versions key in your html_theme_options is ignored if you use readthedocs to host your project (the template version-dropdown.html renders differently depending on whether the project is hosted in readthedocs or not).
Rebuild the theme¶
With all the previous changes in place, save the content, clean up the build directory, build it and serve it again:
$ make clean
$ make html
$ python -m http.server -d build/html
Visit http://localhost:8000 to take a look at the changes.