mirror of https://gitlab.com/octtspacc/staticoso
Renamed HTML parts folders and macros, custom by-date file sorting algorithm
This commit is contained in:
parent
37e6da8f4f
commit
a1239d676b
|
@ -59,8 +59,7 @@ def GetConfMenu(Entries, MarkdownExts):
|
|||
for i in Entries:
|
||||
if int(i) > Max:
|
||||
Max = int(i)
|
||||
for i in range(Max+1):
|
||||
Menu += [[]]
|
||||
Menu = [None] * (Max+1)
|
||||
for i in Entries:
|
||||
e = Entries[i]
|
||||
if not ((e.startswith('<') or e.startswith('[') or e.startswith('- ')) and (e.endswith('>') or e.endswith(')') or e.endswith('}'))):
|
||||
|
@ -117,9 +116,9 @@ def Main(Args, FeedEntries):
|
|||
print("[I] Generating HTML")
|
||||
Pages = MakeSite(
|
||||
TemplatesText=LoadFromDir('Templates', '*.html'),
|
||||
PartsText=LoadFromDir('Parts', '*.html'),
|
||||
ContextParts=literal_eval(Args.ContextParts) if Args.ContextParts else {},
|
||||
ContextPartsText=LoadFromDir('ContextParts', '*.html'),
|
||||
StaticPartsText=LoadFromDir('StaticParts', '*.html'),
|
||||
DynamicParts=literal_eval(Args.DynamicParts) if Args.DynamicParts else {},
|
||||
DynamicPartsText=LoadFromDir('DynamicParts', '*.html'),
|
||||
ConfMenu=ConfMenu,
|
||||
GlobalMacros=ReadConf(SiteConf, 'Macros'),
|
||||
SiteName=SiteName,
|
||||
|
@ -133,7 +132,7 @@ def Main(Args, FeedEntries):
|
|||
Locale=Locale,
|
||||
Minify=Minify,
|
||||
NoScripts=NoScripts,
|
||||
Sorting=SetSorting(literal_eval(Args.ContextParts) if Args.ContextParts else {}),
|
||||
Sorting=SetSorting(literal_eval(Args.Sorting) if Args.Sorting else {}),
|
||||
MarkdownExts=MarkdownExts,
|
||||
AutoCategories=AutoCategories)
|
||||
|
||||
|
@ -213,7 +212,7 @@ if __name__ == '__main__':
|
|||
Parser.add_argument('--SitemapOut', type=str)
|
||||
Parser.add_argument('--FeedEntries', type=int)
|
||||
Parser.add_argument('--FolderRoots', type=str)
|
||||
Parser.add_argument('--ContextParts', type=str)
|
||||
Parser.add_argument('--DynamicParts', type=str)
|
||||
Parser.add_argument('--MarkdownExts', type=str)
|
||||
Parser.add_argument('--MastodonURL', type=str)
|
||||
Parser.add_argument('--MastodonToken', type=str)
|
||||
|
|
|
@ -129,8 +129,8 @@ def TemplatePreprocessor(Text):
|
|||
for l in Text.splitlines():
|
||||
ll = l.lstrip()
|
||||
if ll.startswith('<!--'):
|
||||
lll = ll[4:].lstrip()
|
||||
if lll.startswith('%'):
|
||||
lll = ll[4:].lstrip().rstrip()
|
||||
if lll.startswith('%') and lll.endswith('-->'):
|
||||
Meta += lll[1:-3].lstrip().rstrip() + '\n'
|
||||
Meta = dict(ReadConf(LoadConfStr('[Meta]\n' + Meta), 'Meta'))
|
||||
for i in MetaDefault:
|
||||
|
@ -262,14 +262,13 @@ def OrderPages(Old):
|
|||
Max = int(Curr)
|
||||
else:
|
||||
NoOrder += [e]
|
||||
for i in range(Max+1):
|
||||
New += [[]]
|
||||
New = [None] * (Max+1)
|
||||
for i,e in enumerate(Old):
|
||||
Curr = e[3]['Order']
|
||||
if Curr:
|
||||
New[int(Curr)] = e
|
||||
while [] in New:
|
||||
New.remove([])
|
||||
while None in New:
|
||||
New.remove(None)
|
||||
return New + NoOrder
|
||||
|
||||
def CanIndex(Index, For):
|
||||
|
@ -280,7 +279,7 @@ def CanIndex(Index, For):
|
|||
else:
|
||||
return True if Index == For else False
|
||||
|
||||
def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesList, PagePath, Content, Titles, Meta, SiteRoot, SiteName, BlogName, FolderRoots, Categories, SiteLang, Locale):
|
||||
def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLPagesList, PagePath, Content, Titles, Meta, SiteRoot, SiteName, BlogName, FolderRoots, Categories, SiteLang, Locale):
|
||||
HTMLTitles = FormatTitles(Titles)
|
||||
BodyDescription, BodyImage = '', ''
|
||||
Soup = BeautifulSoup(Content, 'html.parser')
|
||||
|
@ -299,23 +298,23 @@ def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesLi
|
|||
|
||||
for Line in HTML.splitlines():
|
||||
Line = Line.lstrip().rstrip()
|
||||
if Line.startswith('[staticoso:ContextPart:') and Line.endswith(']'):
|
||||
Path = Line[len('[staticoso:ContextPart:'):-1]
|
||||
if Line.startswith('[staticoso:DynamicPart:') and Line.endswith(']'):
|
||||
Path = Line[len('[staticoso:DynamicPart:'):-1]
|
||||
Section = Path.split('/')[-1]
|
||||
if Section in ContextParts:
|
||||
Part = ContextParts[Section]
|
||||
if Section in DynamicParts:
|
||||
Part = DynamicParts[Section]
|
||||
Text = ''
|
||||
if type(Part) == list:
|
||||
for e in Part:
|
||||
Text += ContextPartsText[f"{Path}/{e}"] + '\n'
|
||||
Text += DynamicPartsText[f"{Path}/{e}"] + '\n'
|
||||
elif type(Part) == str:
|
||||
Text = ContextPartsText[f"{Path}/{Part}"]
|
||||
Text = DynamicPartsText[f"{Path}/{Part}"]
|
||||
else:
|
||||
Text = ''
|
||||
HTML = ReplWithEsc(HTML, f"[staticoso:ContextPart:{Path}]", Text)
|
||||
HTML = ReplWithEsc(HTML, f"[staticoso:DynamicPart:{Path}]", Text)
|
||||
|
||||
for e in PartsText:
|
||||
HTML = ReplWithEsc(HTML, f"[staticoso:Part:{e}]", PartsText[e])
|
||||
for e in StaticPartsText:
|
||||
HTML = ReplWithEsc(HTML, f"[staticoso:StaticPart:{e}]", StaticPartsText[e])
|
||||
HTML = ReplWithEsc(HTML, '[staticoso:Site:Menu]', HTMLPagesList)
|
||||
HTML = ReplWithEsc(HTML, '[staticoso:Page:Lang]', SiteLang)
|
||||
HTML = ReplWithEsc(HTML, '[staticoso:Page:Chapters]', HTMLTitles)
|
||||
|
@ -362,7 +361,7 @@ def DoMinifyHTML(HTML):
|
|||
convert_charrefs=True,
|
||||
keep_pre=True)
|
||||
|
||||
def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu, GlobalMacros, SiteName, BlogName, SiteTagline, SiteTemplate, SiteDomain, SiteRoot, FolderRoots, SiteLang, Locale, Minify, NoScripts, Sorting, MarkdownExts, AutoCategories):
|
||||
def MakeSite(TemplatesText, StaticPartsText, DynamicParts, DynamicPartsText, ConfMenu, GlobalMacros, SiteName, BlogName, SiteTagline, SiteTemplate, SiteDomain, SiteRoot, FolderRoots, SiteLang, Locale, Minify, NoScripts, Sorting, MarkdownExts, AutoCategories):
|
||||
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
||||
for Ext in FileExtensions['Pages']:
|
||||
for File in Path('Pages').rglob(f"*.{Ext}"):
|
||||
|
@ -370,14 +369,12 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu,
|
|||
for File in Path('Posts').rglob(f"*.{Ext}"):
|
||||
PostsPaths += [FileToStr(File, 'Posts/')]
|
||||
|
||||
if Sorting['Pages'] == 'Standard':
|
||||
PagesPaths.sort()
|
||||
elif Sorting['Pages'] == 'Inverse':
|
||||
PagesPaths = RevSort(PagesPaths)
|
||||
if Sorting['Posts'] == 'Standard':
|
||||
PostsPaths.sort()
|
||||
elif Sorting['Posts'] == 'Inverse':
|
||||
PostsPaths = RevSort(PostsPaths)
|
||||
PagesPaths = FileNameDateSort(PagesPaths)
|
||||
if Sorting['Pages'] == 'Inverse':
|
||||
PagesPaths.reverse() #= RevSort(PagesPaths)
|
||||
PostsPaths = FileNameDateSort(PostsPaths)
|
||||
if Sorting['Posts'] == 'Inverse':
|
||||
PostsPaths.reverse() #= RevSort(PostsPaths)
|
||||
|
||||
print("[I] Preprocessing Source Pages")
|
||||
for Type in ['Page', 'Post']:
|
||||
|
@ -460,9 +457,9 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu,
|
|||
HTML, ContentHTML, SlimHTML, Description, Image = PatchHTML(
|
||||
File=File,
|
||||
HTML=TemplatesText[Meta['Template']],
|
||||
PartsText=PartsText,
|
||||
ContextParts=ContextParts,
|
||||
ContextPartsText=ContextPartsText,
|
||||
StaticPartsText=StaticPartsText,
|
||||
DynamicParts=DynamicParts,
|
||||
DynamicPartsText=DynamicPartsText,
|
||||
HTMLPagesList=HTMLPagesList,
|
||||
PagePath=PagePath[len('public/'):],
|
||||
Content=Content,
|
||||
|
|
|
@ -94,11 +94,52 @@ def ReplWithEsc(Str, Find, Repl, Esc='\\'):
|
|||
New += Repl + e
|
||||
return New
|
||||
|
||||
def NumsFromFileName(Path):
|
||||
Name = Path.split('/')[-1]
|
||||
Split = len(Name)
|
||||
for i,e in enumerate(Name):
|
||||
if e.lower() in 'qwfpbjluyarstgmneiozxcdvkh':
|
||||
return Name[:i]
|
||||
#Split = i
|
||||
#break
|
||||
#return Name[:Split]
|
||||
return Path
|
||||
|
||||
def RevSort(List):
|
||||
List.sort()
|
||||
List.reverse()
|
||||
return List
|
||||
|
||||
def FileNameDateSort(Old):
|
||||
New = []
|
||||
Old.sort()
|
||||
New.insert(0, Old[0])
|
||||
#print(Old)
|
||||
for i,e in enumerate(Old):
|
||||
if i == 0:
|
||||
continue
|
||||
#print(e)
|
||||
Done = False
|
||||
for j,f in enumerate(New):
|
||||
#print(f)
|
||||
#if NumsFromFileName(e) > NumsFromFileName(f):
|
||||
#print(j, e, f)
|
||||
#print(j, NumsFromFileName(e), NumsFromFileName(f))
|
||||
|
||||
#if NumsFromFileName(e) != e and NumsFromFileName(f) != f and NumsFromFileName(e) > NumsFromFileName(f):
|
||||
if NumsFromFileName(e) != e and NumsFromFileName(f) != f and NumsFromFileName(e) < NumsFromFileName(f):
|
||||
#if e.split('/')[-1] > f.split('/')[-1]:
|
||||
#New.insert(j+1, e)
|
||||
New.insert(j, e)
|
||||
Done = True
|
||||
break
|
||||
if not Done:
|
||||
#New.insert(0, e)
|
||||
New += [e]
|
||||
#New.reverse()
|
||||
print(New)
|
||||
return New
|
||||
|
||||
def FirstRealItem(List):
|
||||
return next(e for e in List if e)
|
||||
|
||||
|
|
7
TODO
7
TODO
|
@ -1,4 +1,4 @@
|
|||
- Fix sorting by date for files in different folders
|
||||
- Test sorting by date for files not starting with date, and dated folders
|
||||
- Make alt text for images also be title text
|
||||
- Custom category names showing in header links
|
||||
- Fix arguments - some are only callable from CLI and not Site.ini
|
||||
|
@ -15,3 +15,8 @@
|
|||
- Fix feed titles and page title ids
|
||||
- Use filename as page title if it is missing
|
||||
- Hybrid global+page menu (like on documentation generators)
|
||||
- Choosing templates for all pages in a folder
|
||||
- Exporting the entire site text as JSON for full-text search tools
|
||||
- Category-based feeds
|
||||
- Automatic guessing of .htm/.html extension for declarations of templates and stuff
|
||||
- Handle file extensions without case-sensitivity
|
||||
|
|
Loading…
Reference in New Issue