| 1 |
============ |
| 2 |
Header links |
| 3 |
============ |
| 4 |
|
| 5 |
The header navigation bar is at the top of each page and contains top-level navigation across pages in your documentation, as well as extra links and components that you can add. |
| 6 |
These sections cover a few things you can control with the Header Navigation Bar. |
| 7 |
|
| 8 |
Navigation Bar External links |
| 9 |
============================= |
| 10 |
|
| 11 |
You can add external links to your navigation bar. These will show up to the right |
| 12 |
of your site's main links and will have a small icon indicating that they point to |
| 13 |
an external site. You can add external links to the nav bar like so: |
| 14 |
|
| 15 |
.. code:: python |
| 16 |
|
| 17 |
html_theme_options = { |
| 18 |
"external_links": [ |
| 19 |
{"name": "link-one-name", "url": "https://<link-one>"}, |
| 20 |
{"name": "link-two-name", "url": "https://<link-two>"} |
| 21 |
] |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
Navigation bar dropdown links |
| 26 |
============================= |
| 27 |
|
| 28 |
By default, this theme will display the first **five** navigation links in the header (including both top-level links and external links). |
| 29 |
It will place the remaining header links in a **dropdown menu** titled "More". |
| 30 |
This prevents the header links from taking up so much space that they crowd out the UI components or spill off-screen. |
| 31 |
|
| 32 |
To control how many header links are displayed before being placed in the dropdown, use the ``header_links_before_dropdown`` theme configuration variable. |
| 33 |
For example, to change the number of displayed header links to be ``4`` instead of ``5``: |
| 34 |
|
| 35 |
.. code-block:: python |
| 36 |
|
| 37 |
html_theme_options = { |
| 38 |
"header_links_before_dropdown": 4 |
| 39 |
} |
| 40 |
|
| 41 |
.. _icon-links: |
| 42 |
|
| 43 |
Icon links |
| 44 |
========== |
| 45 |
|
| 46 |
Icon links are a collection of images and icons that each link to a page or external site. |
| 47 |
They are helpful if you wish to display social media icons, GitHub badges, or project logos. |
| 48 |
|
| 49 |
These links take the following form: |
| 50 |
|
| 51 |
.. code:: python |
| 52 |
|
| 53 |
html_theme_options = { |
| 54 |
... |
| 55 |
"icon_links": [ |
| 56 |
{ |
| 57 |
# Label for this link |
| 58 |
"name": "GitHub", |
| 59 |
# URL where the link will redirect |
| 60 |
"url": "https://github.com/<your-org>/<your-repo>", # required |
| 61 |
# Icon class (if "type": "fontawesome"), or path to local image (if "type": "local") |
| 62 |
"icon": "fa-brands fa-square-github", |
| 63 |
# The type of image to be used (see below for details) |
| 64 |
"type": "fontawesome", |
| 65 |
} |
| 66 |
] |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
Additionally, the screen-reader accessible label for this menu can be configured: |
| 71 |
|
| 72 |
.. code:: python |
| 73 |
|
| 74 |
html_theme_options = { |
| 75 |
... |
| 76 |
"icon_links_label": "Quick Links", |
| 77 |
... |
| 78 |
} |
| 79 |
|
| 80 |
There are two kinds of icons you can use, described below: |
| 81 |
|
| 82 |
FontAwesome icons |
| 83 |
----------------- |
| 84 |
|
| 85 |
`FontAwesome <https://fontawesome.com/>`_ is a collection of icons that are |
| 86 |
commonly used in websites. They include both generic shape icons (e.g., "arrow-down"), |
| 87 |
and brand-specific icons (e.g. "GitHub"). |
| 88 |
|
| 89 |
You can use FontAwesome icons by specifying ``"type": "fontawesome"``, and |
| 90 |
specifying a FontAwesome class in the ``icon`` value. |
| 91 |
The value of ``icon`` can be any full |
| 92 |
`FontAwesome 6 Free <https://fontawesome.com/search?o=r&m=free>`__ icon. |
| 93 |
In addition to the main icon class, e.g. ``fa-cat``, the "style" class must |
| 94 |
also be provided e.g. `fa-brands` for *branding*, or `fa-solid` for *solid*. |
| 95 |
|
| 96 |
Here are several examples: |
| 97 |
|
| 98 |
.. code:: python |
| 99 |
|
| 100 |
html_theme_options = { |
| 101 |
... |
| 102 |
"icon_links": [ |
| 103 |
{ |
| 104 |
"name": "GitHub", |
| 105 |
"url": "https://github.com/<your-org>/<your-repo>", |
| 106 |
"icon": "fa-brands fa-square-github", |
| 107 |
"type": "fontawesome", |
| 108 |
}, |
| 109 |
{ |
| 110 |
"name": "GitLab", |
| 111 |
"url": "https://gitlab.com/<your-org>/<your-repo>", |
| 112 |
"icon": "fa-brands fa-square-gitlab", |
| 113 |
"type": "fontawesome", |
| 114 |
}, |
| 115 |
{ |
| 116 |
"name": "Twitter", |
| 117 |
"url": "https://twitter.com/<your-handle>", |
| 118 |
"icon": "fa-brands fa-square-twitter", |
| 119 |
# The default for `type` is `fontawesome`, so it is not required in the above examples |
| 120 |
}, |
| 121 |
{ |
| 122 |
"name": "Mastodon", |
| 123 |
"url": "https://<your-host>@<your-handle>", |
| 124 |
"icon": "fa-brands fa-mastodon", |
| 125 |
}, |
| 126 |
], |
| 127 |
... |
| 128 |
} |
| 129 |
|
| 130 |
.. Hint:: |
| 131 |
|
| 132 |
To get custom colors like "Twitter blue", use the following in your CSS, |
| 133 |
e.g. ``custom.css``: |
| 134 |
|
| 135 |
.. code:: css |
| 136 |
|
| 137 |
svg.fa-square-twitter { |
| 138 |
color: #55acee; |
| 139 |
} |
| 140 |
|
| 141 |
Image icons |
| 142 |
----------- |
| 143 |
|
| 144 |
If you'd like to display an icon image that is not in the FontAwesome icons library, |
| 145 |
you may instead specify a URL or a path to a local image that will be used for the icon. |
| 146 |
You may also use ``.svg`` images as if they were FontAwesome with a little additional setup. |
| 147 |
|
| 148 |
Bitmap image icons |
| 149 |
~~~~~~~~~~~~~~~~~~ |
| 150 |
|
| 151 |
For all bitmap image icons such as ``.png``, ``.jpg``, etc., you must specify ``type`` as local. |
| 152 |
|
| 153 |
.. note:: |
| 154 |
|
| 155 |
All icon images with ``"type": "local"`` are inserted into the document using ``<img>`` tags. |
| 156 |
If you need features specific to objects in the ``svg`` class please see :ref:`svg image icons <svg-image-icons>` |
| 157 |
|
| 158 |
**To display an image on the web**, use ``"type": "url"``, and provide a URL to an image in the ``icon`` value. |
| 159 |
For example: |
| 160 |
|
| 161 |
.. code:: python |
| 162 |
|
| 163 |
html_theme_options = { |
| 164 |
... |
| 165 |
"icon_links": [ |
| 166 |
{ |
| 167 |
"name": "Pandas", |
| 168 |
"url": "https://pandas.pydata.org", |
| 169 |
"icon": "https://raw.githubusercontent.com/pydata/pydata-sphinx-theme/main/docs/_static/pandas-square.svg", |
| 170 |
"type": "url", |
| 171 |
}, |
| 172 |
], |
| 173 |
... |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
**To display a local image from a file path**, use ``"type": "local"``, and add a path to an image |
| 178 |
relative to your documentation root in the ``icon`` value. |
| 179 |
For example: |
| 180 |
|
| 181 |
.. code:: python |
| 182 |
|
| 183 |
html_theme_options = { |
| 184 |
... |
| 185 |
"icon_links": [ |
| 186 |
{ |
| 187 |
"name": "PyData", |
| 188 |
"url": "https://pydata.org", |
| 189 |
"icon": "_static/pydata-logo-square.png", |
| 190 |
"type": "local", |
| 191 |
}, |
| 192 |
], |
| 193 |
... |
| 194 |
} |
| 195 |
|
| 196 |
.. tip:: |
| 197 |
|
| 198 |
Use ``.svg`` images for a higher-resolution output that behaves similarly across screen sizes. |
| 199 |
|
| 200 |
.. _svg-image-icons: |
| 201 |
|
| 202 |
SVG image icons |
| 203 |
~~~~~~~~~~~~~~~ |
| 204 |
|
| 205 |
In order to make use of the full feature set of ``.svg`` images provided by HTML you will need |
| 206 |
to set up the ``.svg`` to be used as a FontAwesome type icon. This is a fairly straightforward process: |
| 207 |
|
| 208 |
#. Copy `custom-icons.js`_ into an appropriate directory of your documentation |
| 209 |
source (typically ``source/js``). In that file you will find a list of custom |
| 210 |
icon definitions. Each definition looks like this: |
| 211 |
|
| 212 |
.. code:: javascript |
| 213 |
|
| 214 |
{ |
| 215 |
prefix: "fa-custom", |
| 216 |
iconName: "pypi", |
| 217 |
icon: [ |
| 218 |
17.313, // viewBox width |
| 219 |
19.807, // viewBox height |
| 220 |
[], // ligature |
| 221 |
"e001", // unicode codepoint - private use area |
| 222 |
"m10.383 0.2-3.239 ...", // svg path |
| 223 |
], |
| 224 |
} |
| 225 |
|
| 226 |
#. Remove the existing list of icon definitions and add your own using the same pattern as above: |
| 227 |
|
| 228 |
#. Keep the value of ``prefix`` as "fa-custom" |
| 229 |
#. Set the value of ``iconName`` to a short, sensible, lowercase name for your icon |
| 230 |
#. Change the view box height and width to match that of your icon |
| 231 |
#. For each custom icon you define in the list, increment the Unicode codepoint by 1: ``"e001"``, ``"e002"``, ``"e003"``... |
| 232 |
#. Replace the SVG path string with the path that defines your custom icon |
| 233 |
|
| 234 |
#. In ``conf.py``, add the relative path from your source directory to the custom javascript file: |
| 235 |
|
| 236 |
.. code:: python |
| 237 |
|
| 238 |
html_js_files = [ |
| 239 |
... |
| 240 |
("js/custom-icons.js", {"defer": "defer"}), |
| 241 |
... |
| 242 |
] |
| 243 |
|
| 244 |
.. versionchanged:: v0.17.0 |
| 245 |
|
| 246 |
``defer`` attribute is required. |
| 247 |
|
| 248 |
.. important:: |
| 249 |
|
| 250 |
Do not add more than one ``custom-icons.js`` file in your ``conf.py``. |
| 251 |
|
| 252 |
Each custom icon js file includes a call to ``FontAwesome.library.add()``. |
| 253 |
Your site's JavaScript can only call that function once. In our testing, |
| 254 |
subsequent calls to that function do not load additional icons. |
| 255 |
|
| 256 |
#. Set up the icon link in the ``html_theme_options`` as a FontAwesome icon: |
| 257 |
|
| 258 |
.. code:: python |
| 259 |
|
| 260 |
html_theme_options = [ |
| 261 |
... |
| 262 |
"icon_links": [ |
| 263 |
{ |
| 264 |
"name": "PyPI", |
| 265 |
"url": "https://www.pypi.org", |
| 266 |
"icon": "fa-custom fa-pypi", |
| 267 |
"type": "fontawesome", |
| 268 |
}, |
| 269 |
], |
| 270 |
... |
| 271 |
] |
| 272 |
|
| 273 |
That's it, your icon will now be inserted with the ``<svg>`` tag and not ``<img>``! You can reference your custom FontAwesome icon in CSS using the pattern ``.fa-<iconName>`` , for example ``.fa-pypi``. |
| 274 |
|
| 275 |
.. _icon-link-shortcuts: |
| 276 |
|
| 277 |
Icon Link Shortcuts |
| 278 |
------------------- |
| 279 |
|
| 280 |
There are a few shortcuts supported to minimize configuration for commonly-used services. |
| 281 |
These may be removed in a future release in favor of ``icon_links``: |
| 282 |
|
| 283 |
.. code:: python |
| 284 |
|
| 285 |
html_theme_options = { |
| 286 |
... |
| 287 |
"github_url": "https://github.com/<your-org>/<your-repo>", |
| 288 |
"gitlab_url": "https://gitlab.com/<your-org>/<your-repo>", |
| 289 |
"bitbucket_url": "https://bitbucket.org/<your-org>/<your-repo>", |
| 290 |
"twitter_url": "https://twitter.com/<your-handle>", |
| 291 |
... |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
Add custom attributes to icon links |
| 296 |
----------------------------------- |
| 297 |
|
| 298 |
You can add custom attributes to the link element (``<a>``) of your icon links. |
| 299 |
This is helpful if you need to add custom link behavior. |
| 300 |
To do so, use the pattern ``"attributes": {"attribute1": "value1"}`` in a given icon link entry. |
| 301 |
|
| 302 |
For example, to specify a custom ``target`` and ``rel`` attribute, and to define your custom link classes: |
| 303 |
|
| 304 |
.. code:: python |
| 305 |
|
| 306 |
html_theme_options = { |
| 307 |
... |
| 308 |
"icon_links": [ |
| 309 |
{ |
| 310 |
"name": "PyData", |
| 311 |
"url": "https://pydata.org", |
| 312 |
"icon": "_static/pydata-logo-square.png", |
| 313 |
"type": "local", |
| 314 |
# Add additional attributes to the href link. |
| 315 |
# The defaults of the target, rel, class, title, and href may be overwritten. |
| 316 |
"attributes": { |
| 317 |
"target" : "_blank", |
| 318 |
"rel" : "noopener me", |
| 319 |
"class": "nav-link custom-fancy-css" |
| 320 |
} |
| 321 |
}, |
| 322 |
], |
| 323 |
... |
| 324 |
} |
| 325 |
|
| 326 |
.. warning:: |
| 327 |
This might make your icon links behave unexpectedly and might override the default behavior, so make sure you know what you're doing! |
| 328 |
|
| 329 |
.. _custom-icons.js: ../_static/custom-icons.js |