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.
Header links
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. Header links¶
Add links to the header of your Sphinx project using header links. They can be mere links or dropdown lists. The user will see an underline below the link whenever it corresponds to the page loaded in the browser.
Header links can be displayed in a second row in the header.
The following content will produced the header of the image below:
html_theme_options = {
# ... other options ...
"header_links_in_2nd_row": True,
"header_links": [
{
'text': 'Features',
'link': '/features.html',
},
{
"text": "Learn",
"dropdown": (
{
"text": "Learn",
"link": "/learn/index.html",
}, {
"text": "Python Types Intro",
"link": "/python-types.html",
}, {
"text": "Concurrency and async/await",
"link": "/async.html",
}, {
"divider": True,
}, {
"text": "Tutorial - User Guide",
"link": "/tutorial/index.html",
"match": "^/tutorial/*",
}, {
"text": "Advanced User Guide",
"link": "/advanced/index.html",
"match": "^/advanced/*"
}
)
},
{
'text': 'Release Notes',
'link': '/release-notes.html',
},
{
'text': 'Blog',
'link': 'https://example.com/blog',
},
]
}
Read more about customizing the header links in Header links.¶
3. Colorsets¶
Another customizable feature of the theme is the colorset. 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 default, which is cyan.
Another available setting is style_header_neutral, that when is set to True, makes the header color to adapt to the light or dark color-scheme setting. To test it here, use the colorset dropdown at the top right side of the header.
4. Pygments styles¶
Pygments is the package that renders code blocks. Sphinx supports two settings related with pygments:
pygments_light_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. To customize Pygments in your Sphinx project add both entries, pygments_light_style and pygments_dark_style, to the html_theme_options setting in your conf.py module:
html_theme_options = {
# ... other options ...
'pygments_light_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.
5. 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",
}
6. 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.org/latest/"),
("v2.8.5", "https://sample-project.org/2.8.5/"),
("v2.7.2", "https://sample-project.org/2.7.2/"),
]
}
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.