Tweak pages list generation, add cover data-image attribute to links

This commit is contained in:
octospacc 2024-04-13 15:05:16 +02:00
parent 8e892e096d
commit 923e74954e
2 changed files with 17 additions and 13 deletions

View File

@ -57,12 +57,11 @@ def DashifyTitle(Title:str, Done:list=[]):
# :Item 4 // <li>Item 4</li>
def GenHTMLTreeList(MetaList:str, Type:str='ul', Class:str=""):
HTML = ''
Lines = MetaList.splitlines()
CurDepth, NextDepth, PrevDepth = 0, 0, 0
for i,e in enumerate(Lines):
CurDepth = e.find(':')
NextDepth = Lines[i+1].find(':') if i+1 < len(Lines) else 0
HTML += '\n<li>' + e[CurDepth+1:]
for i,item in enumerate(MetaList):
CurDepth = item['text'].find(':')
NextDepth = MetaList[i+1]['text'].find(':') if i+1 < len(MetaList) else 0
HTML += f'\n<li {"attrs" in item and item["attrs"] or ""}>' + item['text'][CurDepth+1:]
if NextDepth == CurDepth:
HTML += '</li>'
elif NextDepth > CurDepth:
@ -144,14 +143,14 @@ def MakeListTitle(File:str, Meta:dict, Titles:list, Prefer:str, BlogName:str, Pa
def FormatTitles(Titles:list, Flatten=False):
# TODO: Somehow titles written in Pug can end up here and don't work, they should be handled
List, DashyTitles = '', []
List, DashyTitles = [], []
for t in Titles:
n = 0 if Flatten else t.split(' ')[0].count('#')
Level = '.' * (n-1) + ':'
Title = MkSoup(t.lstrip('#')).get_text()
DashyTitle = DashifyTitle(Title, DashyTitles)
DashyTitles += [DashyTitle]
List += f'{Level}<a href="#{DashyTitle}">{html.escape(Title)}</a>\n'
List += [{ 'text': f'{Level}<a href="#{DashyTitle}">{html.escape(Title)}</a>\n' }]
return GenHTMLTreeList(List)
# Clean up a generic HTML tree such that it's compliant with the HTML Journal standard

View File

@ -25,7 +25,7 @@ def GetHTMLPagesList(Flags:dict, Pages:list, PathPrefix:str, CallbackFile=None,
Flatten = True
elif MenuStyle == 'Line':
ShowPaths, SingleLine = False, True
List, ToPop, LastParent = '', [], []
List, ToPop, LastParent = [], [], []
IndexPages = Pages.copy()
for e in IndexPages:
if e[3]['Index'].lower() in PageIndexStrNeg:
@ -51,6 +51,7 @@ def GetHTMLPagesList(Flags:dict, Pages:list, PathPrefix:str, CallbackFile=None,
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
# Folder names are handled here
if Depth > 1 and Meta['Order'] != 'Unite':
CurParent = File.split('/')[:-1]
@ -66,12 +67,13 @@ def GetHTMLPagesList(Flags:dict, Pages:list, PathPrefix:str, CallbackFile=None,
else:
Title = CurParent[Depth-2+i]
if SingleLine:
List += f' <span>{Title}</span> '
List += [{ 'text': f' <span>{Title}</span> ' }]
else:
List += f'{Levels}<span class="staticoso-List-Title">{Title}</span>\n'
List += [{ 'text': f'{Levels}<span class="staticoso-List-Title">{Title}</span>\n' }]
# Pages with any other path
if not (Depth > 1 and StripExt(File).split('/')[-1] == 'index'):
attrs = ('Image' in Meta and Meta['Image'] != '' and f'data-image="{html.escape(Meta["Image"])}"' or '')
Levels = '.' * ((Depth-1) if not Flatten else 0) + ':'
DoneCount += 1
if Meta['Order'] == 'Unite':
@ -79,14 +81,17 @@ def GetHTMLPagesList(Flags:dict, Pages:list, PathPrefix:str, CallbackFile=None,
else:
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', f.BlogName, PathPrefix)
if SingleLine:
List += ' <span>' + Title + '</span> '
List += [{ "attrs": attrs, 'text': ' <span>' + Title + '</span> ' }]
else:
List += Levels + Title + '\n'
List += [{ "attrs": attrs, 'text': Levels + Title + '\n' }]
if MenuStyle in ('Default', 'Flat'):
return GenHTMLTreeList(List, Class="staticoso-PagesList")
elif MenuStyle in ('Line', 'Excerpt', 'Image', 'Preview', 'Full'):
return List
htmlList = ''
for item in List:
htmlList += item['text']
return htmlList
def CheckHTMLCommentLine(Line:str):
if Line.startswith('<!--'):