mirror of
https://gitlab.com/octtspacc/staticoso
synced 2025-06-05 22:09:23 +02:00
Internal improvements
This commit is contained in:
@@ -10,6 +10,18 @@
|
||||
import configparser
|
||||
from ast import literal_eval
|
||||
|
||||
DefConf = {
|
||||
'Logging': 20,
|
||||
'OutDir': 'public',
|
||||
'SiteLang': 'en',
|
||||
'SiteTemplate': 'Default.html',
|
||||
'ActivityPubTypeFilter': 'Post',
|
||||
'ActivityPubHoursLimit': 168,
|
||||
'CategoriesUncategorized': 'Uncategorized',
|
||||
'FeedCategoryFilter': 'Blog',
|
||||
'FeedEntries': 10
|
||||
}
|
||||
|
||||
def LoadConfFile(File):
|
||||
Conf = configparser.ConfigParser()
|
||||
Conf.optionxform = str
|
||||
@@ -37,8 +49,15 @@ def EvalOpt(Opt):
|
||||
else:
|
||||
return None
|
||||
|
||||
# TODO: Cleaning
|
||||
|
||||
def OptionChoose(Default, Primary, Secondary, Tertiary=None):
|
||||
return Primary if Primary != None else Secondary if Secondary != None else Tertiary if Tertiary != None else Default
|
||||
def OptChoose(Default, Primary, Secondary, Tertiary=None):
|
||||
return OptionChoose(Default, Primary, Secondary, Tertiary=None)
|
||||
|
||||
def DefConfOptChoose(Key, Primary, Secondary):
|
||||
return OptChoose(DefConf[Key], Primary, Secondary)
|
||||
|
||||
def StringBoolChoose(Default, Primary, Secondary):
|
||||
Var = Default
|
||||
@@ -51,3 +70,5 @@ def StringBoolChoose(Default, Primary, Secondary):
|
||||
elif Check in ('False', 'None'):
|
||||
Var = False
|
||||
return Var
|
||||
def StrBoolChoose(Default, Primary, Secondary):
|
||||
return StringBoolChoose(Default, Primary, Secondary)
|
||||
|
@@ -76,11 +76,11 @@ def GetImage(Meta, BodyImage, Prefer='MetaImage'):
|
||||
|
||||
def MakeContentHeader(Meta, Locale, Categories=''):
|
||||
Header = ''
|
||||
for i in ['CreatedOn', 'EditedOn']:
|
||||
if Meta[i]:
|
||||
Header += f'{Locale[i]}: {Meta[i]}<br>'
|
||||
for e in ['CreatedOn', 'EditedOn']:
|
||||
if Meta[e]:
|
||||
Header += f'<span class="staticoso-ContentHeader-{e}"><span class="staticoso-Label">{Locale[e]}</span>: <span class="staticoso-Value">{Meta[e]}</span></span><br>'
|
||||
if Categories:
|
||||
Header += f"{Locale['Categories']}:{Categories.removesuffix(' ')}<br>"
|
||||
Header += f'<span class="staticoso-ContentHeader-Categories"><span class="staticoso-Label">{Locale["Categories"]}</span>:<span class="staticoso-Value">{Categories.removesuffix(" ")}</span></span><br>'
|
||||
return f'<p>{Header}</p>'
|
||||
|
||||
def MakeCategoryLine(File, Meta):
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from Modules.Config import *
|
||||
|
||||
LoggingFormat = '[%(levelname)s] %(message)s'
|
||||
LoggingLevels = {
|
||||
@@ -25,11 +26,11 @@ def SetupLogging(Level):
|
||||
logging.addLevelName(40, 'E')
|
||||
|
||||
def ConfigLogging(Level):
|
||||
Num = 20
|
||||
Num = DefConf['Logging']
|
||||
if Level:
|
||||
if Level.isdecimal():
|
||||
Num = int(Level)
|
||||
else:
|
||||
if Level.lower() in LoggingLevels:
|
||||
Num = LoggingLevels['Level']['Num']
|
||||
if Level.isdecimal():
|
||||
Num = int(Level)
|
||||
else:
|
||||
if Level.lower() in LoggingLevels:
|
||||
Num = LoggingLevels['Level']['Num']
|
||||
SetupLogging(Num)
|
||||
|
@@ -269,6 +269,8 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP
|
||||
Title = GetTitle(File.split('/')[-1], Meta, Titles, 'MetaTitle', BlogName)
|
||||
Description = GetDescription(Meta, BodyDescription, 'MetaDescription')
|
||||
Image = GetImage(Meta, BodyImage, 'MetaImage')
|
||||
ContentHeader = MakeContentHeader(Meta, Locale, MakeCategoryLine(File, Meta))
|
||||
TimeNow = datetime.now().strftime('%Y-%m-%d %H:%M')
|
||||
|
||||
for Line in HTML.splitlines():
|
||||
Line = Line.lstrip().rstrip()
|
||||
@@ -315,10 +317,10 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP
|
||||
'<staticoso:PageStyle>': Meta['Style'],
|
||||
'[staticoso:Page:Content]': Content,
|
||||
'<staticoso:PageContent>': Content,
|
||||
'[staticoso:Page:ContentInfo]': MakeContentHeader(Meta, Locale, MakeCategoryLine(File, Meta)),
|
||||
'<staticoso:PageContentInfo>': MakeContentHeader(Meta, Locale, MakeCategoryLine(File, Meta)),
|
||||
'[staticoso:BuildTime]': datetime.now().strftime('%Y-%m-%d %H:%M'),
|
||||
'<staticoso:BuildTime>': datetime.now().strftime('%Y-%m-%d %H:%M'),
|
||||
'[staticoso:Page:ContentInfo]': ContentHeader,
|
||||
'<staticoso:PageContentInfo>': ContentHeader,
|
||||
'[staticoso:BuildTime]': TimeNow,
|
||||
'<staticoso:BuildTime>': TimeNow,
|
||||
'<staticoso:SiteDomain>': SiteDomain,
|
||||
'[staticoso:Site:Name]': SiteName,
|
||||
'<staticoso:SiteName>': SiteName,
|
||||
|
Reference in New Issue
Block a user