Skip to content

Commit

Permalink
Meta (#25)
Browse files Browse the repository at this point in the history
* get is already defaulting to None

* accept any type of parameters

* support meta tags

* return favicon if no href

* add browserconfig.xml

* add android shortcut

* remove legacy files

* Fix andoid icon URL

Co-authored-by: Timo Cornelius Metzger <[email protected]>
  • Loading branch information
12rambau and tcmetzger authored Jan 27, 2023
1 parent f2ccfe1 commit 70c8aa6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 56 deletions.
9 changes: 0 additions & 9 deletions docs/source/_static/browserconfig.xml

This file was deleted.

14 changes: 0 additions & 14 deletions docs/source/_static/site.webmanifest

This file was deleted.

40 changes: 15 additions & 25 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,23 @@
}

# -- Option for favicons -------------------------------------------------------

favicons = [
# generic icons compatible with most browsers
{
"rel": "apple-touch-icon",
"size": "180x180",
"static-file": "apple-touch-icon.png",
},
{
"rel": "icon",
"type": "image/png",
# "rel": "icon", # automatically set to "icon" if ommitted
"size": "32x32",
"static-file": "favicon-32x32.png",
},
{
"rel": "icon",
"type": "image/png",
"size": "16x16",
"static-file": "favicon-16x16.png",
# "type": "image/png", # autogenerated from file type
"href": "favicon-32x32.png",
},
{"rel": "manifest", "static-file": "site.webmanifest"},
{"rel": "mask-icon", "color": "#2d89ef", "static-file": "safari-pinned-tab.svg"},
# {
# "name": "msapplication-TileColor",
# "content": "#2d89ef",
# },
# {
# "name": "theme-color",
# "size": "#ffffff",
# },
{"size": "16x16", "href": "favicon-16x16.png"},
{"rel": "shortcut icon", "size": "any", "href": "favicon.ico"},
# chrome specific
{"size": "192x192", "href": "android-chrome-192x192.png"},
# apple icons
{"rel": "mask-icon", "color": "#2d89ef", "href": "safari-pinned-tab.svg"},
{"rel": "apple-touch-icon", "size": "180x180", "href": "apple-touch-icon.png"},
# msapplications
{"name": "msapplication-TileColor", "content": "#2d89ef"},
{"name": "theme-color", "size": "#ffffff"},
{"href": "mstile-150x150.png"},
]
21 changes: 13 additions & 8 deletions sphinx_favicon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ def generate_meta(favicon: Dict[str, str]) -> str:
Favicon link or meta tag
"""
# get the tag of the output
tag = "link"
tag = "meta" if "name" in favicon else "link"

# prepare all the tag parameters and leave them in the favicon dict

# to raise an error if not set
favicon["href"]
# default to "icon" for link elements
if tag == "link":
favicon.setdefault("rel", "icon")
favicon["href"] # to raise an error if not set

# default to "icon"
favicon.setdefault("rel", "icon")

# set the type. if type is not set try to guess it from the file extention
# set the type for link elements.
# if type is not set try to guess it from the file extention
type_ = favicon.get("type")
if not type_:
if not type_ and tag == "link":
extention = favicon["href"].split(".")[-1]
if extention in SUPPORTED_MIME_TYPES.keys():
type_ = SUPPORTED_MIME_TYPES[extention]
Expand All @@ -80,6 +80,7 @@ def _static_to_href(pathto: Callable, favicon: Dict[str, str]) -> Dict[str, str]
if the ``href`` is a relative path then it's replaced with the correct ``href``. We keep checking for ``static-file`` for legacy reasons.
If both ``static-file`` and ``href`` are provided, ``href`` will be ignored.
If the favicon has no ``href`` nor ``static-file`` then do nothing.
Args:
pathto: Sphinx helper_ function to handle relative URLs
Expand All @@ -88,6 +89,10 @@ def _static_to_href(pathto: Callable, favicon: Dict[str, str]) -> Dict[str, str]
Returns:
The favicon with a fully qualified href
"""
# exit if the favicon tag has no href (like meta)
if not (FILE_FIELD in favicon or "href" in favicon):
return favicon

# legacy check for "static-file"
if FILE_FIELD in favicon:
favicon["href"] = favicon.pop(FILE_FIELD)
Expand Down

0 comments on commit 70c8aa6

Please sign in to comment.