Alter HTML generation; add mulitple/themed CSS

alt-html-css
Admin 2020-12-03 09:48:19 +00:00
parent 0d36569a27
commit bd0c75ed7b
2 changed files with 107 additions and 29 deletions

View File

@ -9,14 +9,17 @@ __status__ = "Production"
import os
from utils import getConfigParam
from utils import getNicknameFromActor
from utils import isEditor
from posts import isEditor
from posts import isModerator
from webapp_utils import sharesTimelineJson
from webapp_utils import htmlPostSeparator
from webapp_utils import getLeftImageFile
from webapp_utils import headerButtonsFrontScreen
from webapp_utils import htmlHeaderWithExternalStyle
from webapp_utils import getIconsWebPath
from webapp_utils import htmlHeaderWithExternalStyle, htmlHeaderWithExternalStyles
from webapp_utils import htmlFooter
from webapp_utils import getBannerFile
from webapp_headerbuttons import headerNewsTabs
def _linksExist(baseDir: str) -> bool:
@ -90,15 +93,12 @@ def getLeftColumnContent(baseDir: str, nickname: str, domainFull: str,
'<button class="cancelbtn">' + \
translate['Go Back'] + '</button></a>\n'
if (editor or rssIconAtTop) and not showHeaderImage:
if (editor or rssIconAtTop):
htmlStr += '<div class="columnIcons">'
if editImageClass == 'leftColEdit':
htmlStr += '\n <center>\n'
if editor or rssIconAtTop:
htmlStr += ' <div class="leftColIcons">\n'
if editor:
# show the edit icon
htmlStr += \
@ -131,13 +131,10 @@ def getLeftColumnContent(baseDir: str, nickname: str, domainFull: str,
if rssIconAtTop:
htmlStr += rssIconStr
if editor or rssIconAtTop:
htmlStr += ' </div>\n'
if editImageClass == 'leftColEdit':
htmlStr += ' </center>\n'
if (editor or rssIconAtTop) and not showHeaderImage:
if (editor or rssIconAtTop):
htmlStr += '</div><br>'
# if showHeaderImage:
@ -249,28 +246,70 @@ def htmlLinksMobile(cssCache: {}, baseDir: str,
"""
htmlStr = ''
cssFiles = []
# the css filename
cssFilename = baseDir + '/epicyon-profile.css'
cssFiles.append(baseDir + '/epicyon-profile.css')
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
cssFiles[0] = baseDir + '/epicyon.css'
# TODO: Clean up and remove this override
cssFiles[0] = 'base.css'
# Get theme-specific css if exists - must be named '<theme-name>.css'
themeName = getConfigParam(baseDir, 'theme')
themePath = f'{baseDir}/theme/{themeName}.css'
if os.path.isfile(themePath):
cssFiles.append('theme/' + themeName + '.css')
# is the user a site editor?
if nickname == 'news':
editor = False
moderator = False
else:
# is the user a moderator?
moderator = isModerator(baseDir, nickname)
# is the user a site editor?
editor = isEditor(baseDir, nickname)
domain = domainFull
if ':' in domain:
domain = domain.split(':')[0]
htmlStr = htmlHeaderWithExternalStyle(cssFilename)
bannerFile, bannerFilename = \
getBannerFile(baseDir, nickname, domain, theme)
htmlStr += \
'<a href="/users/' + nickname + '/' + defaultTimeline + '">' + \
'<img loading="lazy" class="timeline-banner" ' + \
'src="/users/' + nickname + '/' + bannerFile + '" /></a>\n'
htmlStr = htmlHeaderWithExternalStyles(cssFiles)
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, userPages)
# Close banner div
htmlStr += '</div>\n'
htmlStr += '<div class="col-left-mobile">\n'
htmlStr += '<center>' + \

View File

@ -17,11 +17,14 @@ from utils import getNicknameFromActor
from utils import isEditor
from posts import isModerator
from webapp_utils import getRightImageFile
from webapp_utils import htmlHeaderWithExternalStyle
from webapp_utils import getImageFile
from webapp_utils import htmlHeaderWithExternalStyle, htmlHeaderWithExternalStyles
from webapp_utils import htmlFooter
from webapp_utils import getBannerFile
from webapp_utils import htmlPostSeparator
from webapp_utils import headerButtonsFrontScreen
from webapp_utils import getIconsWebPath
from webapp_headerbuttons import headerNewsTabs
def _votesIndicator(totalVotes: int, positiveVoting: bool) -> str:
@ -417,10 +420,22 @@ def htmlNewswireMobile(cssCache: {}, baseDir: str, nickname: str,
"""
htmlStr = ''
cssFiles = []
# the css filename
cssFilename = baseDir + '/epicyon-profile.css'
cssFiles.append(baseDir + '/epicyon-profile.css')
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
cssFiles[0] = baseDir + '/epicyon.css'
# TODO: Clean up and remove this override
cssFiles[0] = 'base.css'
# Get theme-specific css if exists - must be named '<theme-name>.css'
themeName = getConfigParam(baseDir, 'theme')
themePath = f'{baseDir}/theme/{themeName}.css'
if os.path.isfile(themePath):
cssFiles.append('theme/' + themeName + '.css')
if nickname == 'news':
editor = False
@ -434,14 +449,38 @@ def htmlNewswireMobile(cssCache: {}, baseDir: str, nickname: str,
showPublishButton = editor
htmlStr = htmlHeaderWithExternalStyle(cssFilename)
htmlStr = htmlHeaderWithExternalStyles(cssFiles)
bannerFile, bannerFilename = \
getBannerFile(baseDir, nickname, domain, theme)
htmlStr += \
'<a href="/users/' + nickname + '/' + defaultTimeline + '">' + \
'<img loading="lazy" class="timeline-banner" ' + \
'src="/users/' + nickname + '/' + bannerFile + '" /></a>\n'
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, userPages)
# Close banner div
htmlStr += '</div>\n'
htmlStr += '<div class="col-right-mobile">\n'