Allow for mutliple css files

alt-html-css
Admin 2020-11-24 14:07:38 +00:00
parent f922fc338e
commit b12cf702aa
4 changed files with 94 additions and 44 deletions

View File

@ -9058,7 +9058,9 @@ class PubServer(BaseHTTPRequestHandler):
""" """
# get the last part of the path # get the last part of the path
# eg. /my/path/file.css becomes file.css # eg. /my/path/file.css becomes file.css
if '/' in path: if 'theme/' in path:
path = 'theme/' + path.split('/')[-1]
elif '/' in path:
path = path.split('/')[-1] path = path.split('/')[-1]
if os.path.isfile(path): if os.path.isfile(path):
tries = 0 tries = 0

View File

@ -1282,6 +1282,7 @@ def getCSS(baseDir: str, cssFilename: str, cssCache: {}) -> str:
if cssCache.get(cssFilename): if cssCache.get(cssFilename):
if cssCache[cssFilename][0] == lastModified: if cssCache[cssFilename][0] == lastModified:
# file hasn't changed, so return the version in the cache # file hasn't changed, so return the version in the cache
# TODO: Should this simply return 304 to allow user to use local cache?
return cssCache[cssFilename][1] return cssCache[cssFilename][1]
with open(cssFilename, 'r') as fpCSS: with open(cssFilename, 'r') as fpCSS:

View File

@ -11,11 +11,12 @@ import time
from utils import getFullDomain from utils import getFullDomain
from utils import isEditor from utils import isEditor
from utils import removeIdEnding from utils import removeIdEnding
from utils import getConfigParam
from follow import followerApprovalActive from follow import followerApprovalActive
from person import isPersonSnoozed from person import isPersonSnoozed
from webapp_utils import htmlPostSeparator from webapp_utils import htmlPostSeparator
from webapp_utils import getBannerFile from webapp_utils import getBannerFile
from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlHeaderWithExternalStyle, htmlHeaderWithExternalStyles
from webapp_utils import htmlFooter from webapp_utils import htmlFooter
from webapp_utils import sharesTimelineJson from webapp_utils import sharesTimelineJson
from webapp_utils import htmlHighlightLabel from webapp_utils import htmlHighlightLabel
@ -77,10 +78,23 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
if boxName != 'tlmedia': if boxName != 'tlmedia':
separatorStr = htmlPostSeparator(baseDir, None) separatorStr = htmlPostSeparator(baseDir, None)
# the css filename cssFiles = []
cssFilename = baseDir + '/epicyon-profile.css'
# TODO: Clean up - default load only one base css file
# default css
cssFiles.append(baseDir + '/epicyon-profile.css')
if os.path.isfile(baseDir + '/epicyon.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')
# filename of the banner shown at the top # filename of the banner shown at the top
bannerFile, bannerFilename = \ bannerFile, bannerFilename = \
@ -111,7 +125,12 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
if timeDiff > 100: if timeDiff > 100:
print('TIMELINE TIMING ' + boxName + ' 3 = ' + str(timeDiff)) print('TIMELINE TIMING ' + boxName + ' 3 = ' + str(timeDiff))
tlStr = htmlHeaderWithExternalStyle(cssFilename, profileStyle) tlStr = htmlHeaderWithExternalStyles(cssFiles)
# benchmark 4
timeDiff = int((time.time() - timelineStartTime) * 1000)
if timeDiff > 100:
print('TIMELINE TIMING ' + boxName + ' 4 = ' + str(timeDiff))
_logTimelineTiming(enableTimingLog, timelineStartTime, boxName, '4') _logTimelineTiming(enableTimingLog, timelineStartTime, boxName, '4')
@ -134,32 +153,33 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
else: else:
# TODO: News instances should ignore personalised banners # TODO: News instances should ignore personalised banners
# Currently uses the 'news' actor banner - as it remains unchanged # Currently uses the 'news' actor banner - as it remains unchanged
tlStr += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/tlnews\" " tlStr += (f"\t<a class=\"timeline-banner hidden-text\" href=\"/tlnews\">"
f"style=\"background-image: url('/users/news/{bannerFile}');\">" f"{translate['News']}</a>\n"
f"{translate['News']}</a>\n") f"\t<div class=\"title\">\n"
f"\t\t<span>#IndymediaBack</span>\n"
tlStr += '</div>\n' f"\t</div>\n")
# TODO: Include '/editprofile' link on 'User' page for 'News' instances # TODO: Include '/editprofile' link on 'User' page for 'News' instances
# 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" # Full row "navbar"
if defaultTimeline == 'tlnews': if defaultTimeline == 'tlnews':
# Show "tab" links instead of standard "buttons" # Show "tab" links instead of standard "buttons"
tlStr += headerNewsTabs(boxName, translate, usersPath, moderator, baseDir) tlStr += headerNewsTabs(boxName, translate, usersPath, moderator, baseDir, userPages)
# Close banner div
tlStr += '</div>\n'
# Only show standard "buttons" on 'inbox' page
if boxName == 'inbox':
tlStr += \
headerButtonsTimeline(defaultTimeline, boxName, pageNumber,
translate, usersPath,
minimal, moderator,
manuallyApproveFollowers,
baseDir, nickname,
domain, timelineStartTime,
iconsAsButtons)
elif fullWidthTimelineButtonHeader: elif fullWidthTimelineButtonHeader:
# Close banner div
tlStr += '</div>\n'
tlStr += \ tlStr += \
headerButtonsTimeline(defaultTimeline, boxName, pageNumber, headerButtonsTimeline(defaultTimeline, boxName, pageNumber,
translate, usersPath, translate, usersPath,
@ -174,14 +194,27 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
# left column # Only show standard "buttons" on 'inbox' page
leftColumnStr = \ if defaultTimeline == 'tlnews' and boxName in userPages:
getLeftColumnContent(baseDir, nickname, domainFull, tlStr += \
httpPrefix, translate, headerButtonsTimeline(defaultTimeline, boxName, pageNumber,
editor, False, None, rssIconAtTop, translate, usersPath,
True, False) minimal, moderator,
tlStr += ' <div class="section links">\n' + \ manuallyApproveFollowers,
leftColumnStr + ' </div>\n' baseDir, nickname,
domain, timelineStartTime,
iconsAsButtons, userPages)
else:
# left column
leftColumnStr = \
getLeftColumnContent(baseDir, nickname, domainFull,
httpPrefix, translate, iconsPath,
editor, False, None, rssIconAtTop,
True, False)
tlStr += ' <div class="section links">\n' + \
leftColumnStr + ' </div>\n'
# center column containing posts # center column containing posts
tlStr += ' <div class="section main">\n' tlStr += ' <div class="section main">\n'
@ -366,17 +399,18 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
# end of column-center # end of column-center
tlStr += ' </div>\n' tlStr += ' </div>\n'
# right column if defaultTimeline == 'tlnews' and boxName not in userPages:
rightColumnStr = getRightColumnContent(baseDir, nickname, domainFull, # right column
httpPrefix, translate, rightColumnStr = getRightColumnContent(baseDir, nickname, domainFull,
moderator, editor, httpPrefix, translate, iconsPath,
newswire, positiveVoting, moderator, editor,
False, None, True, newswire, positiveVoting,
showPublishAsIcon, False, None, True,
rssIconAtTop, publishButtonAtTop, showPublishAsIcon,
authorized, True) rssIconAtTop, publishButtonAtTop,
tlStr += ' <div class="section newswire">' + \ authorized, True)
rightColumnStr + ' </div>\n' tlStr += ' <div class="section newswire">' + \
rightColumnStr + ' </div>\n'
_logTimelineTiming(enableTimingLog, timelineStartTime, boxName, '9') _logTimelineTiming(enableTimingLog, timelineStartTime, boxName, '9')

View File

@ -528,9 +528,22 @@ def htmlHeaderWithExternalStyle(cssFilename: str, lang='en') -> str:
htmlStr += ' <meta charset="utf-8">\n' htmlStr += ' <meta charset="utf-8">\n'
htmlStr += ' <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">\n' htmlStr += ' <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">\n'
cssFile = '/' + cssFilename.split('/')[-1] cssFile = '/' + cssFilename.split('/')[-1]
# TODO: Clean up - default load only one base css file htmlStr += ' <link rel="stylesheet" href="' + cssFile + '">\n'
htmlStr += ' <link rel="stylesheet" href="base.css">\n' htmlStr += ' <link rel="manifest" href="/manifest.json">\n'
#htmlStr += ' <link rel="stylesheet" href="' + cssFile + '">\n' htmlStr += ' <meta name="theme-color" content="grey">\n'
htmlStr += ' <title>Epicyon</title>\n'
htmlStr += ' </head>\n'
htmlStr += ' <body>\n'
return htmlStr
def htmlHeaderWithExternalStyles(cssFiles: [], lang='en') -> str:
htmlStr = '<!DOCTYPE html>\n'
htmlStr += '<html lang="' + lang + '">\n'
htmlStr += ' <head>\n'
htmlStr += ' <meta charset="utf-8">\n'
htmlStr += ' <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">\n'
for path in cssFiles:
htmlStr += ' <link rel="stylesheet" href="' + path + '">\n'
htmlStr += ' <link rel="manifest" href="/manifest.json">\n' htmlStr += ' <link rel="manifest" href="/manifest.json">\n'
htmlStr += ' <meta name="theme-color" content="grey">\n' htmlStr += ' <meta name="theme-color" content="grey">\n'
htmlStr += ' <title>Epicyon</title>\n' htmlStr += ' <title>Epicyon</title>\n'