a Django-based indieweb.org site https://00dani.me/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

46 lines
1.1 KiB

  1. from itertools import chain
  2. from django.core.files.storage import default_storage
  3. class Favicon:
  4. def __init__(self, size, rel='icon', mime='image/png'):
  5. self.rel = rel
  6. self.mime = mime
  7. if not isinstance(size, tuple):
  8. size = (size, size)
  9. self.size = size
  10. @property
  11. def url(self):
  12. return default_storage.url('favicon/' + self.filename)
  13. @property
  14. def filename(self):
  15. return 'favicon-{0}.png'.format(*self.size)
  16. @property
  17. def sizes(self):
  18. return 'x'.join(str(s) for s in self.size)
  19. tile_sizes = {'small': 128, 'medium': 270, 'wide': (558, 270), 'large': 558}
  20. class Tile(Favicon):
  21. def __init__(self, size_name):
  22. super().__init__(tile_sizes[size_name])
  23. self.size_name = size_name
  24. @property
  25. def filename(self):
  26. return '{0}tile.png'.format(self.size_name)
  27. sizes = (32, 57, 76, 96, 120, 128, 144, 180, 195, 228)
  28. icons = tuple(chain(
  29. (Favicon(s) for s in sizes),
  30. (Tile(s) for s in tile_sizes.keys()),
  31. (Favicon(152, rel='apple-touch-icon-precomposed'),
  32. Favicon(196, rel='shortcut icon'))
  33. ))