Improve handling of banners

main
Bob Mottram 2020-11-02 10:12:01 +00:00
parent c9a1ee1634
commit 079edc2593
1 changed files with 41 additions and 24 deletions

View File

@ -6032,24 +6032,32 @@ def getBannerFile(baseDir: str, nickname: str, domain: str) -> (str, str):
""" """
returns the banner filename returns the banner filename
""" """
# filename of the banner shown at the top bannerExtensions = ('png', 'jpg', 'jpeg', 'gif', 'avif', 'webp')
bannerFile = 'banner.png' bannerFile = ''
bannerFilename = baseDir + '/accounts/' + \ bannerFilename = ''
nickname + '@' + domain + '/' + bannerFile for ext in bannerExtensions:
if not os.path.isfile(bannerFilename): bannerFile = 'banner.' + ext
bannerFile = 'banner.jpg'
bannerFilename = baseDir + '/accounts/' + \ bannerFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/' + bannerFile nickname + '@' + domain + '/' + bannerFile
if not os.path.isfile(bannerFilename): if os.path.isfile(bannerFilename):
bannerFile = 'banner.gif' break
return bannerFile, bannerFilename
def getSearchBannerFile(baseDir: str,
nickname: str, domain: str) -> (str, str):
"""
returns the search banner filename
"""
bannerExtensions = ('png', 'jpg', 'jpeg', 'gif', 'avif', 'webp')
bannerFile = ''
bannerFilename = ''
for ext in bannerExtensions:
bannerFile = 'search_banner.' + ext
bannerFilename = baseDir + '/accounts/' + \ bannerFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/' + bannerFile nickname + '@' + domain + '/' + bannerFile
if not os.path.isfile(bannerFilename): if os.path.isfile(bannerFilename):
bannerFile = 'banner.avif' break
bannerFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/' + bannerFile
if not os.path.isfile(bannerFilename):
bannerFile = 'banner.webp'
return bannerFile, bannerFilename return bannerFile, bannerFilename
@ -8612,23 +8620,32 @@ def htmlSearch(cssCache: {}, translate: {},
followStr = htmlHeader(cssFilename, profileStyle) followStr = htmlHeader(cssFilename, profileStyle)
# show a banner above the search box # show a banner above the search box
searchBannerFilename = \ usersPath = baseDir + '/accounts/' + searchNickname + '@' + domain
baseDir + '/accounts/' + searchNickname + '@' + domain + \ searchBannerFile, searchBannerFilename = \
'/search_banner.png' getSearchBannerFile(baseDir, searchNickname, domain)
if not os.path.isfile(searchBannerFilename): if not os.path.isfile(searchBannerFilename):
# get the default search banner for the theme
theme = getConfigParam(baseDir, 'theme').lower() theme = getConfigParam(baseDir, 'theme').lower()
if theme == 'default': if theme == 'default':
theme = '' theme = ''
else: else:
theme = '_' + theme theme = '_' + theme
themeSearchBannerFilename = \ bannerExtensions = ('png', 'jpg', 'jpeg', 'gif', 'avif', 'webp')
baseDir + '/img/search_banner' + theme + '.png' for ext in bannerExtensions:
if os.path.isfile(themeSearchBannerFilename): searchBannerFile = 'search_banner.' + ext
copyfile(themeSearchBannerFilename, searchBannerFilename) searchBannerFilename = usersPath + '/' + searchBannerFile
themeSearchBannerFilename = \
baseDir + '/img/search_banner' + theme + '.' + ext
if os.path.isfile(themeSearchBannerFilename):
copyfile(themeSearchBannerFilename, searchBannerFilename)
break
if os.path.isfile(searchBannerFilename): if os.path.isfile(searchBannerFilename):
followStr += '<center>\n<div class="searchBanner">\n' + \ followStr += \
'<br><br><br><br><br><br><br><br>' + \ '<a href="/users/' + searchNickname + '" title="' + \
'<br><br><br><br><br><br><br><br>\n</div>\n</center>\n' translate['Switch to profile view'] + '" alt="' + \
translate['Switch to profile view'] + '">\n'
followStr += '<img loading="lazy" class="timeline-banner" src="' + \
usersPath + '/' + searchBannerFile + '" /></a>\n'
# show the search box # show the search box
followStr += '<div class="follow">\n' followStr += '<div class="follow">\n'