mirror of https://gitlab.com/octtspacc/staticoso
Misc fixes; Add macro for showing list of latest posts
This commit is contained in:
parent
64453af5e7
commit
17c88320ed
|
@ -15,7 +15,6 @@ import time
|
|||
from ast import literal_eval
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from Modules.Config import *
|
||||
from Modules.Gemini import *
|
||||
from Modules.Logging import *
|
||||
|
@ -23,7 +22,6 @@ from Modules.Markdown import *
|
|||
from Modules.Site import *
|
||||
from Modules.Sitemap import *
|
||||
from Modules.Utils import *
|
||||
|
||||
try:
|
||||
from Modules.ActivityPub import *
|
||||
ActivityPub = True
|
||||
|
@ -108,7 +106,7 @@ def Main(Args, FeedEntries):
|
|||
HavePages, HavePosts = False, False
|
||||
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:
|
||||
# os.chdir(Args.InputDir)
|
||||
|
@ -123,8 +121,8 @@ def Main(Args, FeedEntries):
|
|||
CheckSafeOutDir(OutDir)
|
||||
logging.info(f"Outputting to: {OutDir}/")
|
||||
|
||||
Threads = Args.Threads if Args.Threads else 0
|
||||
DiffBuild = Args.DiffBuild if Args.DiffBuild else False
|
||||
Threads = Args.Threads if Args.Threads else DefConf['Threads']
|
||||
DiffBuild = Args.DiffBuild if Args.DiffBuild else DefConf['DiffBuild']
|
||||
|
||||
BlogName = Flags['BlogName'] = OptChoose('', Args.BlogName, ReadConf(SiteConf, 'Site', 'BlogName'))
|
||||
SiteTagline = Flags['SiteTagline'] = OptChoose('', Args.SiteTagline, ReadConf(SiteConf, 'Site', 'Tagline'))
|
||||
|
@ -274,7 +272,7 @@ if __name__ == '__main__':
|
|||
|
||||
Parser = argparse.ArgumentParser()
|
||||
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('--OutputDir', type=str)
|
||||
#Parser.add_argument('--InputDir', type=str)
|
||||
|
|
|
@ -12,6 +12,8 @@ from ast import literal_eval
|
|||
|
||||
DefConf = {
|
||||
'Logging': 20,
|
||||
'Threads': 0,
|
||||
'DiffBuild': False,
|
||||
'OutDir': 'public',
|
||||
'SiteLang': 'en',
|
||||
'SiteTemplate': 'Default.html',
|
||||
|
|
|
@ -91,7 +91,7 @@ def MakeCategoryLine(File, Meta):
|
|||
return Categories
|
||||
|
||||
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
|
||||
if Link:
|
||||
Title = '[{}]({})'.format(
|
||||
|
|
|
@ -18,8 +18,8 @@ from Modules.Markdown import *
|
|||
from Modules.Pug import *
|
||||
from Modules.Utils import *
|
||||
|
||||
def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, CallbackFile=None, Unite=[], Type=None, PathFilter='', Category=None, For='Menu', MarkdownExts=(), MenuStyle='Default'):
|
||||
ShowPaths, Flatten, SingleLine = True, False, False
|
||||
def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, CallbackFile=None, Unite=[], Type=None, Limit=None, PathFilter='', Category=None, For='Menu', MarkdownExts=(), MenuStyle='Default'):
|
||||
ShowPaths, Flatten, SingleLine, DoneCount = True, False, False, 0
|
||||
if MenuStyle == 'Flat':
|
||||
Flatten = True
|
||||
elif MenuStyle == 'Line':
|
||||
|
@ -41,12 +41,14 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, CallbackFile=None, U
|
|||
if e:
|
||||
IndexPages.insert(i,[e,None,None,{'Type':Type,'Index':'True','Order':'Unite'}])
|
||||
for File, Content, Titles, Meta in IndexPages:
|
||||
# Allow for the virtual "Pages/" prefix to be used in path filtering
|
||||
TmpPathFilter = PathFilter
|
||||
if TmpPathFilter.startswith('Pages/'):
|
||||
TmpPathFilter = TmpPathFilter[len('Pages/'):]
|
||||
if File.startswith('Posts/'):
|
||||
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
|
||||
if Depth > 1 and Meta['Order'] != 'Unite': # Folder names are handled here
|
||||
CurParent = File.split('/')[:-1]
|
||||
|
@ -54,17 +56,21 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, CallbackFile=None, U
|
|||
if LastParent != CurParent and ShowPaths:
|
||||
LastParent = CurParent
|
||||
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'):
|
||||
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, BlogName, PathPrefix)
|
||||
DoneCount += 1
|
||||
else:
|
||||
Title = CurParent[Depth-2+i]
|
||||
if SingleLine:
|
||||
List += ' <span>' + Title + '</span> '
|
||||
else:
|
||||
List += Levels + Title + '\n'
|
||||
|
||||
# Pages with any other path
|
||||
if not (Depth > 1 and StripExt(File).split('/')[-1] == 'index'):
|
||||
Levels = '- ' * (Depth if not Flatten else 1)
|
||||
DoneCount += 1
|
||||
if Meta['Order'] == 'Unite':
|
||||
Title = File
|
||||
else:
|
||||
|
@ -73,6 +79,7 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, CallbackFile=None, U
|
|||
List += ' <span>' + Title + '</span> '
|
||||
else:
|
||||
List += Levels + Title + '\n'
|
||||
|
||||
return markdown(MarkdownHTMLEscape(List, MarkdownExts), extensions=MarkdownExts)
|
||||
|
||||
def CheckHTMLCommentLine(Line):
|
||||
|
@ -262,14 +269,15 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP
|
|||
if '<a class="footnote-ref"' in Content:
|
||||
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, {
|
||||
"<!-- noprocess />": "",
|
||||
"<!--noprocess/>": "",
|
||||
"</ noprocess -->": "",
|
||||
"</noprocess-->": ""
|
||||
})
|
||||
'<!-- noprocess />': '',
|
||||
'<!--noprocess/>': '',
|
||||
'</ noprocess -->': '',
|
||||
'</ noprocess --->': '',
|
||||
'</noprocess-->': '',
|
||||
'</noprocess--->': ''})
|
||||
|
||||
Title = GetTitle(File.split('/')[-1], Meta, Titles, 'MetaTitle', BlogName)
|
||||
Description = GetDescription(Meta, BodyDescription, 'MetaDescription')
|
||||
|
@ -332,7 +340,9 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP
|
|||
'[staticoso:Site:Name]': SiteName,
|
||||
'<staticoso:SiteName>': SiteName,
|
||||
'[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']:
|
||||
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:SiteName>': SiteName,
|
||||
'[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']:
|
||||
ContentHTML = ReplWithEsc(ContentHTML, f"[:{e}:]", Meta['Macros'][e])
|
||||
|
@ -428,6 +440,17 @@ def HandlePage(Flags, Page, Pages, Categories, LimitFiles, Snippets, ConfMenu, L
|
|||
Locale=Locale,
|
||||
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
|
||||
for Line in HTML.splitlines():
|
||||
Line = Line.lstrip().rstrip()
|
||||
|
@ -520,7 +543,7 @@ def MakeSite(Flags, LimitFiles, Snippets, ConfMenu, GlobalMacros, Locale, Thread
|
|||
os.system('printf "["')
|
||||
with Pool(PoolSize) as MultiprocPool:
|
||||
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 Cat in Meta['Categories']:
|
||||
|
@ -569,6 +592,6 @@ def MakeSite(Flags, LimitFiles, Snippets, ConfMenu, GlobalMacros, Locale, Thread
|
|||
os.system('printf "["')
|
||||
with Pool(PoolSize) as MultiprocPool:
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue