diff --git a/webapp_column_right.py b/webapp_column_right.py index 9e915382c..adb15a4dd 100644 --- a/webapp_column_right.py +++ b/webapp_column_right.py @@ -187,6 +187,25 @@ def getRightColumnContent(baseDir: str, nickname: str, domainFull: str, return htmlStr +def getBrokenFavSubstitute() -> str: + """Substitute link used if a favicon is not available + """ + return " onerror=\"this.onerror=null; this.src=''\"" + + +def getFavicon(url: str) -> str: + """Returns a favicon url from the given article link + """ + if '://' not in url: + return None + domain = url.split('://')[1] + if '/' not in domain: + return url + '/favicon.ico' + else: + domain = domain.split('/')[0] + return url.split('://')[0] + domain + '/favicon.ico' + + def _htmlNewswire(baseDir: str, newswire: {}, nickname: str, moderator: bool, translate: {}, positiveVoting: bool) -> str: """Converts a newswire dict into html @@ -212,6 +231,13 @@ def _htmlNewswire(baseDir: str, newswire: {}, nickname: str, moderator: bool, dateStrLink = dateStr.replace('T', ' ') dateStrLink = dateStrLink.replace('Z', '') + url = item[1] + faviconUrl = getFavicon(url) + faviconLink = '' + if faviconUrl: + faviconLink = \ + '' moderatedItem = item[5] htmlStr += separatorStr if moderatedItem and 'vote:' + nickname in item[2]: @@ -224,9 +250,10 @@ def _htmlNewswire(baseDir: str, newswire: {}, nickname: str, moderator: bool, title = removeLongWords(item[0], 16, []).replace('\n', '
') htmlStr += '

' + \ - '' + \ - '' + title + \ + '' + \ + faviconLink + title + \ '' + totalVotesStr if moderator: htmlStr += \ @@ -252,9 +279,9 @@ def _htmlNewswire(baseDir: str, newswire: {}, nickname: str, moderator: bool, title = removeLongWords(item[0], 16, []).replace('\n', '
') if moderator and moderatedItem: htmlStr += '

' + \ - '' + \ - title + '' + totalVotesStr + faviconLink + title + '' + totalVotesStr htmlStr += ' ' + dateShown htmlStr += '' + \ - title + '' + \ + faviconLink + title + '' + \ totalVotesStr htmlStr += ' ' htmlStr += dateShown + '

\n'