DirListing

This commit is contained in:
octospacc 2022-10-25 10:13:00 +02:00
parent 33e11e4a01
commit 5449dfeb07
1 changed files with 38 additions and 20 deletions

View File

@ -18,7 +18,7 @@ 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, Unite=[], Type='Page', Category=None, For='Menu', MarkdownExts=(), MenuStyle='Default'): def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type=None, PathFilter='', Category=None, For='Menu', MarkdownExts=(), MenuStyle='Default'):
ShowPaths, Flatten, SingleLine = True, False, False ShowPaths, Flatten, SingleLine = True, False, False
if MenuStyle == 'Flat': if MenuStyle == 'Flat':
Flatten = True Flatten = True
@ -30,7 +30,7 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page
if e[3]['Index'] == 'False' or e[3]['Index'] == 'None': if e[3]['Index'] == 'False' or e[3]['Index'] == 'None':
IndexPages.remove(e) IndexPages.remove(e)
for i,e in enumerate(IndexPages): for i,e in enumerate(IndexPages):
if e[3]['Type'] != Type: if Type and e[3]['Type'] != Type:
ToPop += [i] ToPop += [i]
ToPop = RevSort(ToPop) ToPop = RevSort(ToPop)
for i in ToPop: for i in ToPop:
@ -41,7 +41,7 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page
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:
if Meta['Type'] == Type and CanIndex(Meta['Index'], For) and (not Category or Category in Meta['Categories']): if (not Type or (Meta['Type'] == Type and CanIndex(Meta['Index'], For))) and (not Category or Category in Meta['Categories']) and File.startswith(PathFilter):
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]
@ -272,23 +272,24 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP
ContentHeader = MakeContentHeader(Meta, Locale, MakeCategoryLine(File, Meta)) ContentHeader = MakeContentHeader(Meta, Locale, MakeCategoryLine(File, Meta))
TimeNow = datetime.now().strftime('%Y-%m-%d %H:%M') TimeNow = datetime.now().strftime('%Y-%m-%d %H:%M')
for Line in HTML.splitlines(): if 'staticoso:DynamicPart:' in HTML: # Reduce risk of unnecessary cycles
Line = Line.lstrip().rstrip() for Line in HTML.splitlines():
if (Line.startswith('[staticoso:DynamicPart:') and Line.endswith(']')) or (Line.startswith('<staticoso:DynamicPart:') and Line.endswith('>')): Line = Line.lstrip().rstrip()
Path = Line[len('[staticoso:DynamicPart:'):-1] if (Line.startswith('[staticoso:DynamicPart:') and Line.endswith(']')) or (Line.startswith('<staticoso:DynamicPart:') and Line.endswith('>')):
Section = Path.split('/')[-1] Path = Line[len('<staticoso:DynamicPart:'):-1]
if Section in DynamicParts: Section = Path.split('/')[-1]
Part = DynamicParts[Section] if Section in DynamicParts:
Text = '' Part = DynamicParts[Section]
if type(Part) == list: Text = ''
for e in Part: if type(Part) == list:
Text += DynamicPartsText[f"{Path}/{e}"] + '\n' for e in Part:
elif type(Part) == str: Text += DynamicPartsText[f"{Path}/{e}"] + '\n'
Text = DynamicPartsText[f"{Path}/{Part}"] elif type(Part) == str:
else: Text = DynamicPartsText[f"{Path}/{Part}"]
Text = '' else:
HTML = ReplWithEsc(HTML, f"[staticoso:DynamicPart:{Path}]", Text) Text = ''
HTML = ReplWithEsc(HTML, f"<staticoso:DynamicPart:{Path}>", Text) HTML = ReplWithEsc(HTML, f"[staticoso:DynamicPart:{Path}]", Text)
HTML = ReplWithEsc(HTML, f"<staticoso:DynamicPart:{Path}>", Text)
for e in StaticPartsText: for e in StaticPartsText:
HTML = ReplWithEsc(HTML, f"[staticoso:StaticPart:{e}]", StaticPartsText[e]) HTML = ReplWithEsc(HTML, f"[staticoso:StaticPart:{e}]", StaticPartsText[e])
@ -315,6 +316,7 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP
'<staticoso:PagePath>': PagePath, '<staticoso:PagePath>': PagePath,
'[staticoso:Page:Style]': Meta['Style'], '[staticoso:Page:Style]': Meta['Style'],
'<staticoso:PageStyle>': Meta['Style'], '<staticoso:PageStyle>': Meta['Style'],
# NOTE: Content is injected in page only at this point! Keep in mind for other substitutions
'[staticoso:Page:Content]': Content, '[staticoso:Page:Content]': Content,
'<staticoso:PageContent>': Content, '<staticoso:PageContent>': Content,
'[staticoso:Page:ContentInfo]': ContentHeader, '[staticoso:Page:ContentInfo]': ContentHeader,
@ -421,6 +423,22 @@ def HandlePage(Flags, Page, Pages, Categories, LimitFiles, Snippets, ConfMenu, L
Locale=Locale, Locale=Locale,
LightRun=LightRun) LightRun=LightRun)
if 'staticoso:DirectoryList:' in HTML: # Reduce risk of unnecessary cycles
for Line in HTML.splitlines():
Line = Line.lstrip().rstrip()
if Line.startswith('<staticoso:DirectoryList:') and Line.endswith('>'):
Path = Line[len('<staticoso:DirectoryList:'):-1]
DirectoryList = GetHTMLPagesList(
Pages=Pages,
BlogName=BlogName,
SiteRoot=SiteRoot,
PathPrefix=GetPathLevels(File),
PathFilter=Path,
For='Categories',
MarkdownExts=MarkdownExts,
MenuStyle='Flat')
HTML = ReplWithEsc(HTML, f"<staticoso:DirectoryList:{Path}>", DirectoryList)
if Flags['Minify']: if Flags['Minify']:
if not LightRun: if not LightRun:
HTML = DoMinifyHTML(HTML, MinifyKeepComments) HTML = DoMinifyHTML(HTML, MinifyKeepComments)