| 1 |
Configuration |
| 2 |
============= |
| 3 |
|
| 4 |
In the quickstart guide, you have used a simple list of favicons and **Sphinx Favicon** |
| 5 |
has automatically generated the corresponding HTML tags. |
| 6 |
|
| 7 |
This section will explain how to customize the configuration and use specific tags and |
| 8 |
attributes such as ``apple-touch-icon``. |
| 9 |
|
| 10 |
Defining favicons |
| 11 |
^^^^^^^^^^^^^^^^^ |
| 12 |
|
| 13 |
Every favicon in **Sphinx Favicon** is defined as a dictionary of HTML attributes. |
| 14 |
|
| 15 |
For a single favicon, you can provide a single dictionary: |
| 16 |
|
| 17 |
.. code-block:: python |
| 18 |
|
| 19 |
favicons = {"rel": "icon", "href": "icon.svg", "type": "image/svg+xml"} |
| 20 |
|
| 21 |
This will generate the following HTML tag: |
| 22 |
|
| 23 |
.. code-block:: html |
| 24 |
|
| 25 |
<link rel="icon" href="_static/icon.svg" type="image/svg+xml"> |
| 26 |
|
| 27 |
For multiple favicons, provide a list of dictionaries: |
| 28 |
|
| 29 |
.. code-block:: python |
| 30 |
|
| 31 |
favicons = [ |
| 32 |
{"rel": "icon", "href": "icon.svg", "type": "image/svg+xml"}, |
| 33 |
{"rel": "icon", "sizes": "16x16", "href": "favicon-16x16.png", "type": "image/png"}, |
| 34 |
{"rel": "icon", "sizes": "32x32", "href": "favicon-32x32.png", "type": "image/png"}, |
| 35 |
{"rel": "apple-touch-icon", "sizes": "180x180", "href": "apple-touch-icon-180x180.png" "type": "image/png"} |
| 36 |
] |
| 37 |
|
| 38 |
This will generate the following HTML tags: |
| 39 |
|
| 40 |
.. code-block:: html |
| 41 |
|
| 42 |
<link rel="icon" href="_static/icon.svg" type="image/svg+xml"> |
| 43 |
<link rel="icon" href="_static/favicon-16x16.png" sizes="16x16" type="image/png"> |
| 44 |
<link rel="icon" href="_static/favicon-32x32.png" sizes="32x32" type="image/png"> |
| 45 |
<link rel="apple-touch-icon" href="_static/apple-touch-icon-180x180.png" sizes="180x180" type="image/png"> |
| 46 |
|
| 47 |
For any attributes that you don't explicitly set, **Sphinx Favicon** will infer the |
| 48 |
values from your provided input. For example: if you don't provide a ``type`` attribute, |
| 49 |
**Sphinx Favicon** will infer the type from the file extension. If you don't provide a |
| 50 |
``sizes`` attribute, **Sphinx Favicon** will attempt to read the pixel dimensions of the |
| 51 |
provided image. |
| 52 |
|
| 53 |
.. note:: |
| 54 |
|
| 55 |
If you provide a simple list (like in the quickstart guide), **Sphinx Favicon** will |
| 56 |
automatically generate the dict behind the scenes. |
| 57 |
|
| 58 |
Your list of favicons can also be a mixture of strings and dicts: |
| 59 |
|
| 60 |
.. code-block:: python |
| 61 |
|
| 62 |
favicons = [ |
| 63 |
"icon.svg", |
| 64 |
"favicon-32x32.png", |
| 65 |
{"rel": "apple-touch-icon", "href": "apple-touch-icon.png"}, |
| 66 |
] |
| 67 |
|
| 68 |
This will generate the following HTML tags: |
| 69 |
|
| 70 |
.. code-block:: html |
| 71 |
|
| 72 |
<link href="_static/icon.svg" rel="icon" type="image/svg+xml"> |
| 73 |
<link href="_static/favicon-32x32.png" sizes="32x32" rel="icon" type="image/png"> |
| 74 |
<link rel="apple-touch-icon" href="_static/_static/_static/apple-touch-icon.png" sizes="180x180" type="image/png"> |
| 75 |
|
| 76 |
Customization |
| 77 |
^^^^^^^^^^^^^ |
| 78 |
|
| 79 |
You can use any parameters to define your favicon as long as they are interpreted by |
| 80 |
browsers. |
| 81 |
|
| 82 |
The following attributes are the most commonly used ones: |
| 83 |
|
| 84 |
``href``: the image location |
| 85 |
############################ |
| 86 |
|
| 87 |
You can define favicon images with the ``href`` attribute in two ways: |
| 88 |
|
| 89 |
Use an **absolute URL** for a favicon file. For example: |
| 90 |
|
| 91 |
.. code-block:: python |
| 92 |
|
| 93 |
"href": "https://www.sphinx-doc.org/en/master/_static/favicon.svg" |
| 94 |
|
| 95 |
Use a **local static file** as a favicon. Make sure you place your local static |
| 96 |
favicon file(s) inside a directory listed in the Sphinx |
| 97 |
`"html_static_path" <https://www.sphinx-doc.org/en/master/usage/configuration.html?highlight=static#confval-html_static_path>`__. |
| 98 |
For example: |
| 99 |
|
| 100 |
.. code-block:: python |
| 101 |
|
| 102 |
"href": "favicon.svg" |
| 103 |
|
| 104 |
.. note:: |
| 105 |
|
| 106 |
We continue to support the legacy ``static_file`` from v0.2 for local files. |
| 107 |
|
| 108 |
``sizes``: the image size |
| 109 |
######################### |
| 110 |
|
| 111 |
Use the ``sizes`` attribute as defined |
| 112 |
`here <https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes>`__. |
| 113 |
|
| 114 |
For example: |
| 115 |
|
| 116 |
.. code-block:: python |
| 117 |
|
| 118 |
"sizes": "16x16" |
| 119 |
|
| 120 |
**Sphinx Favicon** automatically computes a favicon's size if you don't provide a |
| 121 |
value for the ``sizes`` attribute (for BMP, GIF, JPEG, JPG and PNG files). |
| 122 |
|
| 123 |
``rel``: the favicon relation |
| 124 |
############################# |
| 125 |
|
| 126 |
Use the ``rel`` attribute to define the favicon relation. This can either be the |
| 127 |
standard `"icon" and "shortcut icon" <https://html.spec.whatwg.org/multipage/links.html#rel-icon>`__, |
| 128 |
or a custom relation like |
| 129 |
`"apple-touch-icon" <https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html>`__. |
| 130 |
|
| 131 |
For example: |
| 132 |
|
| 133 |
.. code-block:: python |
| 134 |
|
| 135 |
"rel": "apple-touch-icon" |
| 136 |
|
| 137 |
If you don't provide a value for the ``rel`` attribute, **Sphinx Favicon** will |
| 138 |
automatically set ``rel="icon"``. |
| 139 |
|
| 140 |
``type``: the image MIME type |
| 141 |
############################# |
| 142 |
|
| 143 |
Use the ``type`` to define a favicon's MIME type as defined |
| 144 |
`here <https://html.spec.whatwg.org/multipage/semantics.html#attr-link-type>`__. |
| 145 |
|
| 146 |
For example: |
| 147 |
|
| 148 |
.. code-block:: python |
| 149 |
|
| 150 |
"type": "image/svg+xml" |
| 151 |
|
| 152 |
If you don't provide a value for the ``rel`` attribute, **Sphinx Favicon** will |
| 153 |
automatically extract the MIME type from the provided image file (for BMP, GIF, ICO, |
| 154 |
JPEG, JPG, PNG, and SVG files). |
| 155 |
|
| 156 |
``name``: specific to msapp icons |
| 157 |
################################# |
| 158 |
|
| 159 |
You also have the option to specify a ``name`` attribute. This is useful for |
| 160 |
``msapplication``-style favicons. |
| 161 |
|
| 162 |
If you use the ``name`` attribute, **Sphinx Favicon** will automatically set the |
| 163 |
``rel`` attribute to ``"meta"``. |
| 164 |
|
| 165 |
For example: |
| 166 |
|
| 167 |
.. code-block:: python |
| 168 |
|
| 169 |
favicons = [ |
| 170 |
"mstile-150x150.png", |
| 171 |
{"name": "msapplication-TileColor", "content": "#2d89ef"}, |
| 172 |
{"name": "theme-color", "content": "#ffffff"}, |
| 173 |
] |
| 174 |
|
| 175 |
This will generate the following HTML tags: |
| 176 |
|
| 177 |
.. code-block:: html |
| 178 |
|
| 179 |
<link href="_static/mstile-150x150.png" sizes="150x150" rel="icon" type="image/png"> |
| 180 |
<meta name="msapplication-TileColor" content="#2d89ef"> |
| 181 |
<meta name="theme-color" content="#ffffff"> |
| 182 |
|
| 183 |
.. tip:: |
| 184 |
|
| 185 |
See the ``conf.py`` file for this documentation in the project's GitHub repository, |
| 186 |
at https://github.com/tcmetzger/sphinx-favicon/blob/main/docs/source/conf.py |