mirror of
https://gitlab.com/octtspacc/staticoso
synced 2025-06-05 22:09:23 +02:00
Misc fixes; Add macro for showing list of latest posts
This commit is contained in:
@ -15,7 +15,6 @@ import time
|
|||||||
from ast import literal_eval
|
from ast import literal_eval
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from Modules.Config import *
|
from Modules.Config import *
|
||||||
from Modules.Gemini import *
|
from Modules.Gemini import *
|
||||||
from Modules.Logging import *
|
from Modules.Logging import *
|
||||||
@ -23,7 +22,6 @@ from Modules.Markdown import *
|
|||||||
from Modules.Site import *
|
from Modules.Site import *
|
||||||
from Modules.Sitemap import *
|
from Modules.Sitemap import *
|
||||||
from Modules.Utils import *
|
from Modules.Utils import *
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from Modules.ActivityPub import *
|
from Modules.ActivityPub import *
|
||||||
ActivityPub = True
|
ActivityPub = True
|
||||||
@ -108,7 +106,7 @@ def Main(Args, FeedEntries):
|
|||||||
HavePages, HavePosts = False, False
|
HavePages, HavePosts = False, False
|
||||||
SiteConf = LoadConfFile('Site.ini')
|
SiteConf = LoadConfFile('Site.ini')
|
||||||
|
|
||||||
ConfigLogging(DefConfOptChoose('Logging', Args.Logging, ReadConf(SiteConf, 'Main', 'Logging')))
|
ConfigLogging(DefConfOptChoose('Logging', Args.Logging, ReadConf(SiteConf, 'staticoso', 'Logging')))
|
||||||
|
|
||||||
#if Args.InputDir:
|
#if Args.InputDir:
|
||||||
# os.chdir(Args.InputDir)
|
# os.chdir(Args.InputDir)
|
||||||
@ -123,8 +121,8 @@ def Main(Args, FeedEntries):
|
|||||||
CheckSafeOutDir(OutDir)
|
CheckSafeOutDir(OutDir)
|
||||||
logging.info(f"Outputting to: {OutDir}/")
|
logging.info(f"Outputting to: {OutDir}/")
|
||||||
|
|
||||||
Threads = Args.Threads if Args.Threads else 0
|
Threads = Args.Threads if Args.Threads else DefConf['Threads']
|
||||||
DiffBuild = Args.DiffBuild if Args.DiffBuild else False
|
DiffBuild = Args.DiffBuild if Args.DiffBuild else DefConf['DiffBuild']
|
||||||
|
|
||||||
BlogName = Flags['BlogName'] = OptChoose('', Args.BlogName, ReadConf(SiteConf, 'Site', 'BlogName'))
|
BlogName = Flags['BlogName'] = OptChoose('', Args.BlogName, ReadConf(SiteConf, 'Site', 'BlogName'))
|
||||||
SiteTagline = Flags['SiteTagline'] = OptChoose('', Args.SiteTagline, ReadConf(SiteConf, 'Site', 'Tagline'))
|
SiteTagline = Flags['SiteTagline'] = OptChoose('', Args.SiteTagline, ReadConf(SiteConf, 'Site', 'Tagline'))
|
||||||
@ -274,7 +272,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
Parser = argparse.ArgumentParser()
|
Parser = argparse.ArgumentParser()
|
||||||
Parser.add_argument('--Logging', type=str) # Levels: Debug, Info, Warning, Error.
|
Parser.add_argument('--Logging', type=str) # Levels: Debug, Info, Warning, Error.
|
||||||
Parser.add_argument('--Threads', type=str)
|
Parser.add_argument('--Threads', type=str) # Set 0 to use all CPU cores
|
||||||
Parser.add_argument('--DiffBuild', type=str)
|
Parser.add_argument('--DiffBuild', type=str)
|
||||||
Parser.add_argument('--OutputDir', type=str)
|
Parser.add_argument('--OutputDir', type=str)
|
||||||
#Parser.add_argument('--InputDir', type=str)
|
#Parser.add_argument('--InputDir', type=str)
|
||||||
|
@ -12,6 +12,8 @@ from ast import literal_eval
|
|||||||
|
|
||||||
DefConf = {
|
DefConf = {
|
||||||
'Logging': 20,
|
'Logging': 20,
|
||||||
|
'Threads': 0,
|
||||||
|
'DiffBuild': False,
|
||||||
'OutDir': 'public',
|
'OutDir': 'public',
|
||||||
'SiteLang': 'en',
|
'SiteLang': 'en',
|
||||||
'SiteTemplate': 'Default.html',
|
'SiteTemplate': 'Default.html',
|
||||||
|
@ -91,7 +91,7 @@ def MakeCategoryLine(File, Meta):
|
|||||||
return Categories
|
return Categories
|
||||||
|
|
||||||
def MakeListTitle(File, Meta, Titles, Prefer, SiteRoot, BlogName, PathPrefix=''):
|
def MakeListTitle(File, Meta, Titles, Prefer, SiteRoot, BlogName, PathPrefix=''):
|
||||||
Title = GetTitle(File.split('/')[-1], Meta, Titles, Prefer, BlogName)
|
Title = GetTitle(File.split('/')[-1], Meta, Titles, Prefer, BlogName).lstrip().rstrip()
|
||||||
Link = False if Meta['Index'] == 'Unlinked' else True
|
Link = False if Meta['Index'] == 'Unlinked' else True
|
||||||
if Link:
|
if Link:
|
||||||
Title = '[{}]({})'.format(
|
Title = '[{}]({})'.format(
|
||||||
|
@ -18,8 +18,8 @@ from Modules.Markdown import *
|
|||||||
from Modules.Pug import *
|
from Modules.Pug import *
|
||||||
from Modules.Utils import *
|
from Modules.Utils import *
|
||||||
|
|
||||||
def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, CallbackFile=None, Unite=[], Type=None, PathFilter='', Category=None, For='Menu', MarkdownExts=(), MenuStyle='Default'):
|
def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, CallbackFile=None, Unite=[], Type=None, Limit=None, PathFilter='', Category=None, For='Menu', MarkdownExts=(), MenuStyle='Default'):
|
||||||
ShowPaths, Flatten, SingleLine = True, False, False
|
ShowPaths, Flatten, SingleLine, DoneCount = True, False, False, 0
|
||||||
if MenuStyle == 'Flat':
|
if MenuStyle == 'Flat':
|
||||||
Flatten = True
|
Flatten = True
|
||||||
elif MenuStyle == 'Line':
|
elif MenuStyle == 'Line':
|
||||||
@ -41,12 +41,14 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, CallbackFile=None, U
|
|||||||
if e:
|
if e:
|
||||||
IndexPages.insert(i,[e,None,None,{'Type':Type,'Index':'True','Order':'Unite'}])
|
IndexPages.insert(i,[e,None,None,{'Type':Type,'Index':'True','Order':'Unite'}])
|
||||||
for File, Content, Titles, Meta in IndexPages:
|
for File, Content, Titles, Meta in IndexPages:
|
||||||
|
# Allow for the virtual "Pages/" prefix to be used in path filtering
|
||||||
TmpPathFilter = PathFilter
|
TmpPathFilter = PathFilter
|
||||||
if TmpPathFilter.startswith('Pages/'):
|
if TmpPathFilter.startswith('Pages/'):
|
||||||
TmpPathFilter = TmpPathFilter[len('Pages/'):]
|
TmpPathFilter = TmpPathFilter[len('Pages/'):]
|
||||||
if File.startswith('Posts/'):
|
if File.startswith('Posts/'):
|
||||||
continue
|
continue
|
||||||
if (not Type or (Meta['Type'] == Type and CanIndex(Meta['Index'], For))) and (not Category or Category in Meta['Categories']) and File.startswith(TmpPathFilter) and File != CallbackFile:
|
|
||||||
|
if (not Type or (Meta['Type'] == Type and CanIndex(Meta['Index'], For))) and (not Category or Category in Meta['Categories']) and File.startswith(TmpPathFilter) and File != CallbackFile and (not Limit or Limit > DoneCount):
|
||||||
Depth = (File.count('/') + 1) if Meta['Order'] != 'Unite' else 1
|
Depth = (File.count('/') + 1) if Meta['Order'] != 'Unite' else 1
|
||||||
if Depth > 1 and Meta['Order'] != 'Unite': # Folder names are handled here
|
if Depth > 1 and Meta['Order'] != 'Unite': # Folder names are handled here
|
||||||
CurParent = File.split('/')[:-1]
|
CurParent = File.split('/')[:-1]
|
||||||
@ -54,17 +56,21 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, CallbackFile=None, U
|
|||||||
if LastParent != CurParent and ShowPaths:
|
if LastParent != CurParent and ShowPaths:
|
||||||
LastParent = CurParent
|
LastParent = CurParent
|
||||||
Levels = '- ' * ((Depth-1+i) if not Flatten else 1)
|
Levels = '- ' * ((Depth-1+i) if not Flatten else 1)
|
||||||
# Folders with else without an index file
|
# If search node endswith index, it's a page; else, it's a folder
|
||||||
if StripExt(File).endswith('index'):
|
if StripExt(File).endswith('index'):
|
||||||
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, BlogName, PathPrefix)
|
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, BlogName, PathPrefix)
|
||||||
|
DoneCount += 1
|
||||||
else:
|
else:
|
||||||
Title = CurParent[Depth-2+i]
|
Title = CurParent[Depth-2+i]
|
||||||
if SingleLine:
|
if SingleLine:
|
||||||
List += ' <span>' + Title + '</span> '
|
List += ' <span>' + Title + '</span> '
|
||||||
else:
|
else:
|
||||||
List += Levels + Title + '\n'
|
List += Levels + Title + '\n'
|
||||||
|
|
||||||
|
# Pages with any other path
|
||||||
if not (Depth > 1 and StripExt(File).split('/')[-1] == 'index'):
|
if not (Depth > 1 and StripExt(File).split('/')[-1] == 'index'):
|
||||||
Levels = '- ' * (Depth if not Flatten else 1)
|
Levels = '- ' * (Depth if not Flatten else 1)
|
||||||
|
DoneCount += 1
|
||||||
if Meta['Order'] == 'Unite':
|
if Meta['Order'] == 'Unite':
|
||||||
Title = File
|
Title = File
|
||||||
else:
|
else:
|
||||||
@ -73,6 +79,7 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, CallbackFile=None, U
|
|||||||
List += ' <span>' + Title + '</span> '
|
List += ' <span>' + Title + '</span> '
|
||||||
else:
|
else:
|
||||||
List += Levels + Title + '\n'
|
List += Levels + Title + '\n'
|
||||||
|
|
||||||
return markdown(MarkdownHTMLEscape(List, MarkdownExts), extensions=MarkdownExts)
|
return markdown(MarkdownHTMLEscape(List, MarkdownExts), extensions=MarkdownExts)
|
||||||
|
|
||||||
def CheckHTMLCommentLine(Line):
|
def CheckHTMLCommentLine(Line):
|
||||||
@ -262,14 +269,15 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP
|
|||||||
if '<a class="footnote-ref"' in Content:
|
if '<a class="footnote-ref"' in Content:
|
||||||
Content = AddToTagStartEnd(Content, '<a class="footnote-ref"', '</a>', '[', ']')
|
Content = AddToTagStartEnd(Content, '<a class="footnote-ref"', '</a>', '[', ']')
|
||||||
|
|
||||||
if ("<!-- noprocess />" or "<!--noprocess/>") in Content and ("</ noprocess -->" or "</noprocess-->") in Content:
|
if any(_ in Content for _ in ('<!-- noprocess />', '<!--noprocess/>', '</ noprocess -->', '</ noprocess --->', '</noprocess-->', '</noprocess--->')):
|
||||||
Content = DictReplWithEsc(
|
Content = DictReplWithEsc(
|
||||||
Content, {
|
Content, {
|
||||||
"<!-- noprocess />": "",
|
'<!-- noprocess />': '',
|
||||||
"<!--noprocess/>": "",
|
'<!--noprocess/>': '',
|
||||||
"</ noprocess -->": "",
|
'</ noprocess -->': '',
|
||||||
"</noprocess-->": ""
|
'</ noprocess --->': '',
|
||||||
})
|
'</noprocess-->': '',
|
||||||
|
'</noprocess--->': ''})
|
||||||
|
|
||||||
Title = GetTitle(File.split('/')[-1], Meta, Titles, 'MetaTitle', BlogName)
|
Title = GetTitle(File.split('/')[-1], Meta, Titles, 'MetaTitle', BlogName)
|
||||||
Description = GetDescription(Meta, BodyDescription, 'MetaDescription')
|
Description = GetDescription(Meta, BodyDescription, 'MetaDescription')
|
||||||
@ -332,7 +340,9 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP
|
|||||||
'[staticoso:Site:Name]': SiteName,
|
'[staticoso:Site:Name]': SiteName,
|
||||||
'<staticoso:SiteName>': SiteName,
|
'<staticoso:SiteName>': SiteName,
|
||||||
'[staticoso:Site:AbsoluteRoot]': SiteRoot,
|
'[staticoso:Site:AbsoluteRoot]': SiteRoot,
|
||||||
'[staticoso:Site:RelativeRoot]': GetPathLevels(PagePath)
|
'<staticoso:SiteAbsoluteRoot>': SiteRoot,
|
||||||
|
'[staticoso:Site:RelativeRoot]': GetPathLevels(PagePath),
|
||||||
|
'<staticoso:SiteRelativeRoot>': GetPathLevels(PagePath)
|
||||||
})
|
})
|
||||||
for e in Meta['Macros']:
|
for e in Meta['Macros']:
|
||||||
HTML = ReplWithEsc(HTML, f"[:{e}:]", Meta['Macros'][e])
|
HTML = ReplWithEsc(HTML, f"[:{e}:]", Meta['Macros'][e])
|
||||||
@ -355,7 +365,9 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP
|
|||||||
'[staticoso:Site:Name]': SiteName,
|
'[staticoso:Site:Name]': SiteName,
|
||||||
'<staticoso:SiteName>': SiteName,
|
'<staticoso:SiteName>': SiteName,
|
||||||
'[staticoso:Site:AbsoluteRoot]': SiteRoot,
|
'[staticoso:Site:AbsoluteRoot]': SiteRoot,
|
||||||
'[staticoso:Site:RelativeRoot]': GetPathLevels(PagePath)
|
'<staticoso:SiteAbsoluteRoot>': SiteRoot,
|
||||||
|
'[staticoso:Site:RelativeRoot]': GetPathLevels(PagePath),
|
||||||
|
'<staticoso:SiteRelativeRoot>': GetPathLevels(PagePath)
|
||||||
})
|
})
|
||||||
for e in Meta['Macros']:
|
for e in Meta['Macros']:
|
||||||
ContentHTML = ReplWithEsc(ContentHTML, f"[:{e}:]", Meta['Macros'][e])
|
ContentHTML = ReplWithEsc(ContentHTML, f"[:{e}:]", Meta['Macros'][e])
|
||||||
@ -428,6 +440,17 @@ def HandlePage(Flags, Page, Pages, Categories, LimitFiles, Snippets, ConfMenu, L
|
|||||||
Locale=Locale,
|
Locale=Locale,
|
||||||
LightRun=LightRun)
|
LightRun=LightRun)
|
||||||
|
|
||||||
|
HTML = ReplWithEsc(HTML, f"<staticoso:Feed>", GetHTMLPagesList(
|
||||||
|
Limit=Flags['FeedEntries'],
|
||||||
|
Type='Post',
|
||||||
|
Category=None if Flags['FeedCategoryFilter'] == '*' else Flags['FeedCategoryFilter'],
|
||||||
|
Pages=Pages,
|
||||||
|
BlogName=BlogName,
|
||||||
|
SiteRoot=SiteRoot,
|
||||||
|
PathPrefix=GetPathLevels(File),
|
||||||
|
For='Categories',
|
||||||
|
MarkdownExts=MarkdownExts,
|
||||||
|
MenuStyle='Flat'))
|
||||||
if 'staticoso:DirectoryList:' in HTML: # Reduce risk of unnecessary cycles
|
if 'staticoso:DirectoryList:' in HTML: # Reduce risk of unnecessary cycles
|
||||||
for Line in HTML.splitlines():
|
for Line in HTML.splitlines():
|
||||||
Line = Line.lstrip().rstrip()
|
Line = Line.lstrip().rstrip()
|
||||||
@ -520,7 +543,7 @@ def MakeSite(Flags, LimitFiles, Snippets, ConfMenu, GlobalMacros, Locale, Thread
|
|||||||
os.system('printf "["')
|
os.system('printf "["')
|
||||||
with Pool(PoolSize) as MultiprocPool:
|
with Pool(PoolSize) as MultiprocPool:
|
||||||
Pages = MultiprocPool.map(MultiprocPagePreprocessor, MultiprocPages)
|
Pages = MultiprocPool.map(MultiprocPagePreprocessor, MultiprocPages)
|
||||||
os.system('printf "]\n"') #print("]") # Make newline after percentage dots
|
os.system('printf "]\n"') # Make newline after percentage dots
|
||||||
|
|
||||||
for File, Content, Titles, Meta in Pages:
|
for File, Content, Titles, Meta in Pages:
|
||||||
for Cat in Meta['Categories']:
|
for Cat in Meta['Categories']:
|
||||||
@ -569,6 +592,6 @@ def MakeSite(Flags, LimitFiles, Snippets, ConfMenu, GlobalMacros, Locale, Thread
|
|||||||
os.system('printf "["')
|
os.system('printf "["')
|
||||||
with Pool(PoolSize) as MultiprocPool:
|
with Pool(PoolSize) as MultiprocPool:
|
||||||
MadePages = MultiprocPool.map(MultiprocHandlePage, MultiprocPages)
|
MadePages = MultiprocPool.map(MultiprocHandlePage, MultiprocPages)
|
||||||
os.system('printf "]\n"') #print("]") # Make newline after percentage dots
|
os.system('printf "]\n"') # Make newline after percentage dots
|
||||||
|
|
||||||
return MadePages
|
return MadePages
|
||||||
|
Reference in New Issue
Block a user