Default favicon for newswire, if site favicon is not available

merge-requests/30/head
Bob Mottram 2021-01-07 10:38:33 +00:00
parent 7387f7f5e9
commit a3ed814e9f
19 changed files with 19 additions and 8 deletions

View File

@ -1127,6 +1127,7 @@ class PubServer(BaseHTTPRequestHandler):
if self.path.startswith('/icons/') or \ if self.path.startswith('/icons/') or \
self.path.startswith('/avatars/') or \ self.path.startswith('/avatars/') or \
self.path.startswith('/favicon.ico') or \ self.path.startswith('/favicon.ico') or \
self.path.startswith('/newswire_favicon.ico') or \
self.path.startswith('/categories.xml') or \ self.path.startswith('/categories.xml') or \
self.path.startswith('/newswire.xml'): self.path.startswith('/newswire.xml'):
return False return False
@ -4835,18 +4836,19 @@ class PubServer(BaseHTTPRequestHandler):
'show logout', 'send manifest') 'show logout', 'send manifest')
def _getFavicon(self, callingDomain: str, def _getFavicon(self, callingDomain: str,
baseDir: str, debug: bool) -> None: baseDir: str, debug: bool,
"""Return the favicon favFile='favicon.ico') -> None:
"""Return the site favicon or default newswire favicon
""" """
favType = 'image/x-icon' favType = 'image/x-icon'
favFilename = 'favicon.ico' favFilename = favFile
if self._hasAccept(callingDomain): if self._hasAccept(callingDomain):
if 'image/webp' in self.headers['Accept']: if 'image/webp' in self.headers['Accept']:
favType = 'image/webp' favType = 'image/webp'
favFilename = 'favicon.webp' favFilename = favFile.split('.')[0] + '.webp'
if 'image/avif' in self.headers['Accept']: if 'image/avif' in self.headers['Accept']:
favType = 'image/avif' favType = 'image/avif'
favFilename = 'favicon.avif' favFilename = favFile.split('.')[0] + '.avif'
if not self.server.themeName: if not self.server.themeName:
self.themeName = getConfigParam(baseDir, 'theme') self.themeName = getConfigParam(baseDir, 'theme')
if not self.server.themeName: if not self.server.themeName:
@ -9731,7 +9733,16 @@ class PubServer(BaseHTTPRequestHandler):
# favicon image # favicon image
if 'favicon.ico' in self.path: if 'favicon.ico' in self.path:
self._getFavicon(callingDomain, self.server.baseDir, self._getFavicon(callingDomain, self.server.baseDir,
self.server.debug) self.server.debug,
'favicon.ico')
return
# default newswire favicon, for links to sites which
# have no favicon
if 'newswire_favicon.ico' in self.path:
self._getFavicon(callingDomain, self.server.baseDir,
self.server.debug,
'newswire_favicon.ico')
return return
# check authorization # check authorization

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

View File

@ -197,10 +197,10 @@ def _getNewswireFavicon(url: str) -> str:
"""Returns a favicon url from the given article link """Returns a favicon url from the given article link
""" """
if '://' not in url: if '://' not in url:
return None return '/newswire_favicon.ico'
if url.startswith('http://'): if url.startswith('http://'):
if not (url.endswith('.onion') or url.endswith('.i2p')): if not (url.endswith('.onion') or url.endswith('.i2p')):
return None return '/newswire_favicon.ico'
domain = url.split('://')[1] domain = url.split('://')[1]
if '/' not in domain: if '/' not in domain:
return url + '/favicon.ico' return url + '/favicon.ico'