From ccfcbe4ad43940166ffa12c10956f5371cdd30cb Mon Sep 17 00:00:00 2001 From: OMN Date: Sat, 12 Dec 2020 19:20:23 +0000 Subject: [PATCH] Add multiple/themed CSS --- blog.py | 25 +++++++++++++++++++++---- webapp_login.py | 20 ++++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/blog.py b/blog.py index bd6df769..d149b419 100644 --- a/blog.py +++ b/blog.py @@ -10,11 +10,13 @@ import os from datetime import datetime from content import replaceEmojiFromTags -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 getPostAttachmentsAsHtml from webapp_media import addEmbeddedElements from utils import getFullDomain +from utils import getConfigParam from utils import getMediaFormats from utils import getNicknameFromActor from utils import getDomainFromActor @@ -383,10 +385,25 @@ def htmlBlogPost(authorized: bool, """ blogStr = '' - cssFilename = baseDir + '/epicyon-blog.css' + cssFiles = [] + + # the css filename + cssFiles.append(baseDir + '/epicyon-blog.css') if os.path.isfile(baseDir + '/blog.css'): - cssFilename = baseDir + '/blog.css' - blogStr = htmlHeaderWithExternalStyle(cssFilename) + cssFiles[0] = baseDir + '/blog.css' + + # TODO: Clean up and remove this override + cssFiles[0] = 'base.css' + + # Get theme-specific css if exists - must be named '.css' + themeName = getConfigParam(baseDir, 'theme') + + themePath = f'{baseDir}/theme/{themeName}.css' + if os.path.isfile(themePath): + cssFiles.append('theme/' + themeName + '.css') + + blogStr = htmlHeaderWithExternalStyles(cssFiles) + _htmlBlogRemoveCwButton(blogStr, translate) blogStr += _htmlBlogPostContent(authorized, baseDir, diff --git a/webapp_login.py b/webapp_login.py index 423d7fb2..cc33a3e3 100644 --- a/webapp_login.py +++ b/webapp_login.py @@ -11,7 +11,7 @@ import time from shutil import copyfile from utils import getConfigParam from utils import noOfAccounts -from webapp_utils import htmlHeaderWithExternalStyle +from webapp_utils import htmlHeaderWithExternalStyles from webapp_utils import htmlFooter @@ -95,9 +95,21 @@ def htmlLogin(cssCache: {}, translate: {}, with open(baseDir + '/accounts/login.txt', 'r') as file: loginText = '' - cssFilename = baseDir + '/epicyon-login.css' + cssFiles = [] + + cssFiles.append(baseDir + '/epicyon-login.css') if os.path.isfile(baseDir + '/login.css'): - cssFilename = baseDir + '/login.css' + cssFiles[0] = baseDir + '/login.css' + + # TODO: Clean up and remove this override + cssFiles[0] = 'base.css' + + # Get theme-specific css if exists - must be named '.css' + themeName = getConfigParam(baseDir, 'theme') + + themePath = f'{baseDir}/theme/{themeName}.css' + if os.path.isfile(themePath): + cssFiles.append('theme/' + themeName + '.css') # show the register button registerButtonStr = '' @@ -129,7 +141,7 @@ def htmlLogin(cssCache: {}, translate: {}, if not autocomplete: autocompleteStr = 'autocomplete="off" value=""' - loginForm = htmlHeaderWithExternalStyle(cssFilename) + loginForm = htmlHeaderWithExternalStyles(cssFiles) loginForm += '
\n' loginForm += '
\n' loginForm += '
\n'