Simplify header banner html generation

alt-html-css
Admin 2021-01-04 10:12:58 +00:00
parent f7507500b7
commit 720354066d
8 changed files with 88 additions and 213 deletions

View File

@ -16,9 +16,9 @@ from webapp_utils import htmlPostSeparator
from webapp_utils import getLeftImageFile
from webapp_utils import headerButtonsFrontScreen
from webapp_utils import htmlHeaderWithExternalStyle, htmlHeaderWithExternalStyles
from webapp_utils import htmlHeaderBanner
from webapp_utils import htmlFooter
from webapp_utils import getBannerFile
from webapp_headerbuttons import headerNewsTabs
def _linksExist(baseDir: str) -> bool:
@ -282,33 +282,13 @@ def htmlLinksMobile(cssCache: {}, baseDir: str,
bannerFile, bannerFilename = getBannerFile(baseDir, nickname, domain)
usersPath = '/users/' + nickname
htmlStr += '<div class="header">\n'
if not defaultTimeline == 'tlfeatures':
htmlStr += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/users/{nickname}/{defaultTimeline}\" "
f"style=\"background-image: url('{usersPath}/{bannerFile}');\">"
f"{translate['Switch to profile view']}</a>\n")
else:
# TODO: News instances should ignore personalised banners
# Currently uses the 'news' actor banner - as it remains unchanged
htmlStr += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/users/{nickname}/tlfeatures\">"
f"{translate['Features']}</a>\n"
f"\t<div class=\"title\">\n"
f"\t\t<span>#IndymediaBack</span>\n"
f"\t</div>\n")
# Certain Epciyon pages should only be accessible via the 'User' page for News instances
userPages = ['inbox', 'outbox', 'dm', 'tlreplies', 'tlblogs', 'tlmedia', 'tlshares', \
'tlsaves', 'tlevents', 'tlbookmarks', 'moderation', 'search', \
'followers', 'newfollowers']
# Full row "navbar"
if defaultTimeline == 'tlfeatures':
# Show "tab" links instead of standard "buttons"
htmlStr += headerNewsTabs('linksmobile', translate, usersPath, baseDir, authorized, userPages)
# Close banner div
htmlStr += '</div>\n'
htmlStr += htmlHeaderBanner(defaultTimeline, 'linksmobile', baseDir, usersPath,
authorized, translate, userPages, bannerFile)
htmlStr += '<div class="col-left-mobile">\n'
htmlStr += '<center>' + \

View File

@ -19,11 +19,11 @@ from posts import isModerator
from webapp_utils import getRightImageFile
from webapp_utils import getImageFile
from webapp_utils import htmlHeaderWithExternalStyle, htmlHeaderWithExternalStyles
from webapp_utils import htmlHeaderBanner
from webapp_utils import htmlFooter
from webapp_utils import getBannerFile
from webapp_utils import htmlPostSeparator
from webapp_utils import headerButtonsFrontScreen
from webapp_headerbuttons import headerNewsTabs
def _votesIndicator(totalVotes: int, positiveVoting: bool) -> str:
@ -218,6 +218,8 @@ def _htmlNewswire(baseDir: str, newswire: {}, nickname: str, moderator: bool,
continue
dateShown = publishedDate.strftime("%Y-%m-%d %H:%M")
#print(f'[DEBUG] mod: {moderator}\ndata: {item}') # DEBUG
dateStrLink = dateStr.replace('T', ' ')
dateStrLink = dateStrLink.replace('Z', '')
url = item[1]
@ -455,33 +457,13 @@ def htmlNewswireMobile(cssCache: {}, baseDir: str, nickname: str,
bannerFile, bannerFilename = getBannerFile(baseDir, nickname, domain)
usersPath = '/users/' + nickname
htmlStr += '<div class="header">\n'
if not defaultTimeline == 'tlfeatures':
htmlStr += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/users/{nickname}/{defaultTimeline}\" "
f"style=\"background-image: url('{usersPath}/{bannerFile}');\">"
f"{translate['Switch to profile view']}</a>\n")
else:
# TODO: News instances should ignore personalised banners
# Currently uses the 'news' actor banner - as it remains unchanged
htmlStr += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/users/{nickname}/tlfeatures\">"
f"{translate['Features']}</a>\n"
f"\t<div class=\"title\">\n"
f"\t\t<span>#IndymediaBack</span>\n"
f"\t</div>\n")
# Certain Epciyon pages should only be accessible via the 'User' page for News instances
userPages = ['inbox', 'outbox', 'dm', 'tlreplies', 'tlblogs', 'tlmedia', 'tlshares', \
'tlsaves', 'tlevents', 'tlbookmarks', 'moderation', 'search', \
'followers', 'newfollowers']
# Full row "navbar"
if defaultTimeline == 'tlfeatures':
# Show "tab" links instead of standard "buttons"
htmlStr += headerNewsTabs('newswiremobile', translate, usersPath, baseDir, authorized, userPages)
# Close banner div
htmlStr += '</div>\n'
htmlStr += htmlHeaderBanner(defaultTimeline, 'newswiremobile', baseDir, usersPath,
authorized, translate, userPages, bannerFile)
htmlStr += '<div class="col-right-mobile">\n'

View File

@ -15,8 +15,9 @@ from utils import getImageFormats
from utils import getMediaFormats
from webapp_utils import getBannerFile
from webapp_utils import htmlHeaderWithExternalStyles
from webapp_utils import htmlHeaderBanner
from webapp_utils import htmlFooter
from webapp_headerbuttons import headerButtonsTimeline, headerNewsTabs
from webapp_headerbuttons import headerButtonsTimeline
from posts import isModerator
@ -574,38 +575,16 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {},
usersPath = '/users/' + nickname
newPostForm += '<div class="header">\n'
if not defaultTimeline == 'tlfeatures':
newPostForm += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/users/{nickname}/{defaultTimeline}\" "
f"style=\"background-image: url('{usersPath}/{bannerFile}');\">"
f"{translate['Switch to timeline view']}</a>\n")
else:
# TODO: News instances should ignore personalised banners
# Currently uses the 'news' actor banner - as it remains unchanged
newPostForm += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/users/{nickname}/tlfeatures\">"
f"{translate['Features']}</a>\n"
f"\t<div class=\"title\">\n"
f"\t\t<span>#IndymediaBack</span>\n"
f"\t</div>\n")
# Certain Epciyon pages should only be accessible via the 'User' page for News instances
# TODO: Better solution - Currently this is a duplicate of list created in 'webapp_timeline.py'
userPages = ['inbox', 'outbox', 'dm', 'tlreplies', 'tlblogs', 'tlmedia', 'tlshares', \
'tlsaves', 'tlevents', 'tlbookmarks', 'moderation', 'search', \
'followers', 'newfollowers', 'newdm', 'newpost', 'newblog', 'newevent']
# Full row "navbar"
if defaultTimeline == 'tlfeatures':
# Show "tab" links instead of standard "buttons"
# NOTE: "inbox" is used as a generic boxName, as with 'User' pages
# NOTE: It should be "safe" to assume that this code would not be running,
# unless the user was already deemed 'authorized',
# thus allowing us to pass True directly
newPostForm += headerNewsTabs('inbox', translate, usersPath, baseDir, True, userPages)
# Close banner div
newPostForm += '</div>\n'
# 'authorized' is assumed to be True if this function is being called
# TODO: Confirm this assumption
newPostForm += htmlHeaderBanner(defaultTimeline, 'inbox', baseDir, usersPath,
True, translate, userPages, bannerFile)
mentionsStr = ''
for m in mentions:

View File

@ -12,11 +12,10 @@ from utils import getDomainFromActor
from utils import getConfigParam
from person import personBoxJson
from webapp_utils import htmlHeaderWithExternalStyles
from webapp_utils import htmlFooter
from webapp_utils import htmlHeaderBanner, htmlFooter
from webapp_utils import getBannerFile
from webapp_utils import htmlPostSeparator
from webapp_utils import headerButtonsFrontScreen
from webapp_headerbuttons import headerNewsTabs
from webapp_column_left import getLeftColumnContent
from webapp_column_right import getRightColumnContent
from webapp_post import individualPostAsHtml
@ -111,21 +110,9 @@ def htmlFrontScreen(rssIconAtTop: bool,
# If this is the news account then show a different banner
bannerFile, bannerFilename = getBannerFile(baseDir, nickname, domain)
profileHeaderStr = '<div class="header">\n'
# TODO: News instances should ignore personalised banners
# Currently uses the 'news' actor banner - as it remains unchanged
profileHeaderStr += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/users/{nickname}/tlfeatures\">"
f"{translate['Features']}</a>\n"
f"\t<div class=\"title\">\n"
f"\t\t<span>#IndymediaBack</span>\n"
f"\t</div>\n")
# Show "tab" links instead of standard "buttons"
profileHeaderStr += headerNewsTabs('tlfeatures', translate, '/users/news', baseDir, authorized, None)
# Close banner div
profileHeaderStr += '</div>\n'
# NOTE: This currently more-or-less assumes being run only if 'news' instance
profileHeaderStr = htmlHeaderBanner(defaultTimeline, 'frontpage', baseDir, '/users/news',
authorized, translate, None, bannerFile);
# TODO: Should probably use a more generic class, easier to re-use and help simplify CSS
# NOTE: Related also to class "page" added to 'webapp_create_post.py'
@ -164,8 +151,11 @@ def htmlFrontScreen(rssIconAtTop: bool,
profileStr += ' <div class="section main">\n'
licenseStr = ''
bannerFile, bannerFilename = \
getBannerFile(baseDir, nickname, domain, theme)
# NOTE: Redundant
# bannerFile, bannerFilename = \
# getBannerFile(baseDir, nickname, domain)
profileStr += \
_htmlFrontScreenPosts(recentPostsCache, maxRecentPosts,
translate,

View File

@ -361,61 +361,3 @@ def headerButtonsTimeline(defaultTimeline: str,
tlStr += '\t</div>\n'
return tlStr
def headerNewsTabs(boxName: str,
translate: {},
usersPath: str,
baseDir: str,
authorized: bool,
userPages: []) -> str:
navTabList = []
navTabList.append(('tlfeatures',
{'pageRef': '/tlfeatures',
'translateText': 'Features'}
))
navTabList.append(('newswiremobile',
{'pageRef': '/newswiremobile',
'translateText': 'Newswire',
'class': 'tab-news'}
))
# navTabList.append(('calendar',
# {'pageRef': '/calendar',
# 'translateText': 'Calendar'}
# ))
navTabList.append(('linksmobile',
{'pageRef': '/linksmobile',
'translateText': 'Links',
'class': 'tab-links'}
))
if authorized:
navTabList.append(('inbox',
{'pageRef': '/inbox',
'translateText': 'User'}
))
navStr = '\t\t<div class="section navtabs">\n'
navStr += '\t\t\t<ul>\n'
for name, config in navTabList:
classStr = ''
if name == boxName:
classStr = 'tab-highlight'
elif name == 'inbox' and userPages and boxName in userPages:
classStr = 'tab-highlight'
if 'class' in config:
classStr += ' ' + config['class']
textStr = translate[config['translateText']]
navStr += (f"\t\t\t\t<a class=\"{classStr}\" href=\"{usersPath}{config['pageRef']}\">\n"
f'\t\t\t\t\t<li>{textStr}</li>\n'
f'\t\t\t\t</a>\n')
navStr += '\t\t\t</ul>\n\t\t</div>\n'
return navStr

View File

@ -44,6 +44,7 @@ from webapp_frontscreen import htmlFrontScreen
from webapp_utils import scheduledPostsExist
from webapp_utils import getPersonAvatarUrl
from webapp_utils import htmlHeaderWithExternalStyle, htmlHeaderWithExternalStyles
from webapp_utils import htmlHeaderBanner
from webapp_utils import htmlFooter
from webapp_utils import addEmojiToDisplayName
from webapp_utils import getBannerFile
@ -51,7 +52,7 @@ from webapp_utils import htmlPostSeparator
from webapp_utils import getBlogAddress
from webapp_post import individualPostAsHtml
from webapp_timeline import htmlIndividualShare
from webapp_headerbuttons import headerButtonsTimeline, headerNewsTabs
from webapp_headerbuttons import headerButtonsTimeline
def htmlProfileAfterSearch(cssCache: {},
@ -1205,37 +1206,15 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
usersPath = '/users/' + nickname
# top banner
editProfileForm += '<div class="header">\n'
if not defaultTimeline == 'tlfeatures':
editProfileForm += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/users/{nickname}/{defaultTimeline}\" "
f"style=\"background-image: url('{usersPath}/{bannerFile}');\">"
f"{translate['Switch to timeline view']}</a>\n")
else:
# TODO: News instances should ignore personalised banners
# Currently uses the 'news' actor banner - as it remains unchanged
editProfileForm += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/users/{nickname}/tlfeatures\">"
f"{translate['Features']}</a>\n"
f"\t<div class=\"title\">\n"
f"\t\t<span>#IndymediaBack</span>\n"
f"\t</div>\n")
# Certain Epciyon pages should only be accessible via the 'User' page for News instances
userPages = ['inbox', 'outbox', 'dm', 'tlreplies', 'tlblogs', 'tlmedia', 'tlshares', \
'tlsaves', 'tlevents', 'tlbookmarks', 'moderation', 'search', \
'followers', 'newfollowers', 'newdm', 'newpost', 'newblog', 'newevent', 'editprofile']
# Full row "navbar"
if defaultTimeline == 'tlfeatures':
# Show "tab" links instead of standard "buttons"
# NOTE: It should be "safe" to assume that this code would not be running,
# unless the user was already deemed 'authorized',
# thus allowing us to pass True directly
editProfileForm += headerNewsTabs('editprofile', translate, usersPath, baseDir, True, userPages)
# Close banner div
editProfileForm += '</div>\n'
# Safe to assume this function would not be called if user was not authorized
# TODO: Confirm this assumption
editProfileForm += htmlHeaderBanner(defaultTimeline, 'editprofile', baseDir, usersPath,
True, translate, userPages, bannerFile)
# TODO: Place form inside a "page" div for 'News' instances
# NOTE: Duplicate of code from webapp_create_post.py

View File

@ -17,14 +17,14 @@ from person import isPersonSnoozed
from webapp_utils import htmlPostSeparator
from webapp_utils import getBannerFile
from webapp_utils import htmlHeaderWithExternalStyle, htmlHeaderWithExternalStyles
from webapp_utils import htmlFooter
from webapp_utils import htmlHeaderBanner, htmlFooter
from webapp_utils import sharesTimelineJson
from webapp_utils import htmlHighlightLabel
from webapp_post import preparePostFromHtmlCache
from webapp_post import individualPostAsHtml
from webapp_column_left import getLeftColumnContent
from webapp_column_right import getRightColumnContent
from webapp_headerbuttons import headerButtonsTimeline, headerNewsTabs
from webapp_headerbuttons import headerButtonsTimeline
from posts import isModerator
@ -141,45 +141,18 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
if defaultTimeline == 'tlfeatures':# and boxName == 'tlfeatures':
newsHeader = True
# Banner and "profile toggle" link
tlStr += '<div class="header">\n'
# TODO: This CSS should be moved out of the code
# Items like this that can be different per user should be kept
# in the user's folder and loaded as final CSS, to allow overwrite(s)
if not newsHeader:
tlStr += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/users/{nickname}\" "
f"style=\"background-image: url('{usersPath}/{bannerFile}');\">"
f"{translate['Switch to profile view']}</a>\n")
else:
# TODO: News instances should ignore personalised banners
# Currently uses the 'news' actor banner - as it remains unchanged
tlStr += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/users/{nickname}/tlfeatures\">"
f"{translate['Features']}</a>\n"
f"\t<div class=\"title\">\n"
f"\t\t<span>#IndymediaBack</span>\n"
f"\t</div>\n")
# Certain Epciyon pages should only be accessible via the 'User' page for News instances
# TODO: The 'new...' pages appear to require handling elsewhere
userPages = ['inbox', 'outbox', 'dm', 'tlreplies', 'tlblogs', 'tlmedia', 'tlshares', \
'tlsaves', 'tlevents', 'tlbookmarks', 'moderation', 'search', \
'followers', 'newfollowers', 'newdm', 'newpost', 'newblog', 'newevent', 'editprofile']
# Full row "navbar"
if defaultTimeline == 'tlfeatures':
# Show "tab" links instead of standard "buttons"
tlStr += headerNewsTabs(boxName, translate, usersPath, baseDir, authorized, userPages)
# Banner and "profile toggle" link
# Close banner div
tlStr += '</div>\n'
elif fullWidthTimelineButtonHeader:
# Close banner div
tlStr += '</div>\n'
tlStr += htmlHeaderBanner(defaultTimeline, boxName, baseDir, usersPath,
authorized, translate, userPages, bannerFile);
if not newsHeader and fullWidthTimelineButtonHeader:
tlStr += \
headerButtonsTimeline(defaultTimeline, boxName, pageNumber,
translate, usersPath,
@ -188,9 +161,6 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
baseDir, nickname,
domain, timelineStartTime,
iconsAsButtons, userPages)
else:
# Close banner div
tlStr += '</div>\n'
# TODO: Should probably use a more generic class, easier to re-use and help simplify CSS
# NOTE: Related also to class "page" added to 'webapp_create_post.py'

View File

@ -19,6 +19,7 @@ from cache import getPersonFromCache
from cache import storePersonInCache
from content import addHtmlTags
from content import replaceEmojiFromTags
from webapp_headernewstabs import headerNewsTabs
def getBrokenLinkSubstitute() -> str:
@ -552,6 +553,58 @@ def htmlHeaderWithExternalStyles(cssFiles: [], lang='en') -> str:
return htmlStr
# TODO: Determine if bannerFile should really only be determined here
def htmlHeaderBanner(defaultTimeline, boxName,
baseDir, usersPath, authorized,
translate, userPages,
bannerFile) -> str:
newsHeader = False
if defaultTimeline == 'tlfeatures' or \
(defaultTimeline == 'inbox' and boxName == 'frontpage'):
newsHeader = True
# Banner and "profile toggle" link
bannerStr = '<div class="header">\n'
# TODO: This CSS should be moved out of the code
# Items like this that can be different per user should be kept
# in the user's folder and loaded as final CSS, to allow overwrite(s)
# This needs further thought
if not newsHeader:
bannerStr += (f"\t<a class=\"timeline-banner hidden-text\" href=\"{usersPath}\" "
f"style=\"background-image: url('{usersPath}/{bannerFile}');\">"
f"{translate['Switch to profile view']}</a>\n")
else:
# TODO: News instances should ignore personalised banners
# Currently uses the 'news' actor banner - as it remains unchanged
# More sensible location would be within each theme directory
# e.g. as 'banner_news.png' to keep with existing naming convention
bannerStr += (f"\t<a class=\"timeline-banner hidden-text\" href=\"{usersPath}/tlfeatures\">"
f"{translate['Features']}</a>\n"
f"\t<div class=\"title\">\n"
f"\t\t<span>#IndymediaBack</span>\n"
f"\t</div>\n")
# TODO: Should this be "global" for importers of this module?
# # Certain Epciyon pages should only be accessible via the 'User' page for News instances
# # TODO: The 'new...' pages appear to require handling elsewhere
# userPages = ['inbox', 'outbox', 'dm', 'tlreplies', 'tlblogs', 'tlmedia', 'tlshares', \
# 'tlsaves', 'tlevents', 'tlbookmarks', 'moderation', 'search', \
# 'followers', 'newfollowers', 'newdm', 'newpost', 'newblog', 'newevent', 'editprofile']
# Full row "navbar"
if newsHeader:
# Show "tab" links instead of standard "buttons"
bannerStr += headerNewsTabs(boxName, translate, usersPath, baseDir, authorized, userPages)
# Close banner div
bannerStr += '</div>\n'
return bannerStr
def htmlFooter() -> str:
htmlStr = ' <div class="section footer">\n'
htmlStr += ' <ul>\n'