2018-04-19 22:35:51 -04:00
|
|
|
from itertools import chain
|
|
|
|
from django.core.files.storage import default_storage
|
|
|
|
|
|
|
|
|
|
|
|
class Favicon:
|
2023-08-10 02:52:37 -04:00
|
|
|
def __init__(self, size, rel="icon", mime="image/png"):
|
2018-04-19 22:35:51 -04:00
|
|
|
self.rel = rel
|
|
|
|
self.mime = mime
|
|
|
|
if not isinstance(size, tuple):
|
|
|
|
size = (size, size)
|
|
|
|
self.size = size
|
|
|
|
|
|
|
|
@property
|
|
|
|
def url(self):
|
2023-08-10 02:52:37 -04:00
|
|
|
return default_storage.url("favicon/" + self.filename)
|
2018-04-19 22:35:51 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def filename(self):
|
2023-08-10 02:52:37 -04:00
|
|
|
return "favicon-{0}.png".format(*self.size)
|
2018-04-19 22:35:51 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def sizes(self):
|
2023-08-10 02:52:37 -04:00
|
|
|
return "x".join(str(s) for s in self.size)
|
2018-04-19 22:35:51 -04:00
|
|
|
|
|
|
|
|
2023-08-10 02:52:37 -04:00
|
|
|
tile_sizes = {"small": 128, "medium": 270, "wide": (558, 270), "large": 558}
|
2018-04-19 22:35:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
class Tile(Favicon):
|
|
|
|
def __init__(self, size_name):
|
|
|
|
super().__init__(tile_sizes[size_name])
|
|
|
|
self.size_name = size_name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def filename(self):
|
2023-08-10 02:52:37 -04:00
|
|
|
return "{0}tile.png".format(self.size_name)
|
2018-04-19 22:35:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
sizes = (32, 57, 76, 96, 120, 128, 144, 180, 195, 228)
|
2023-08-10 02:52:37 -04:00
|
|
|
icons = tuple(
|
|
|
|
chain(
|
|
|
|
(Favicon(s) for s in sizes),
|
|
|
|
(Tile(s) for s in tile_sizes.keys()),
|
|
|
|
(
|
|
|
|
Favicon(152, rel="apple-touch-icon-precomposed"),
|
|
|
|
Favicon(196, rel="shortcut icon"),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|