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:
|
for i in Entries:
|
||||||
if int(i) > Max:
|
if int(i) > Max:
|
||||||
Max = int(i)
|
Max = int(i)
|
||||||
for i in range(Max+1):
|
Menu = [None] * (Max+1)
|
||||||
Menu += [[]]
|
|
||||||
for i in Entries:
|
for i in Entries:
|
||||||
e = Entries[i]
|
e = Entries[i]
|
||||||
if not ((e.startswith('<') or e.startswith('[') or e.startswith('- ')) and (e.endswith('>') or e.endswith(')') or e.endswith('}'))):
|
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")
|
print("[I] Generating HTML")
|
||||||
Pages = MakeSite(
|
Pages = MakeSite(
|
||||||
TemplatesText=LoadFromDir('Templates', '*.html'),
|
TemplatesText=LoadFromDir('Templates', '*.html'),
|
||||||
PartsText=LoadFromDir('Parts', '*.html'),
|
StaticPartsText=LoadFromDir('StaticParts', '*.html'),
|
||||||
ContextParts=literal_eval(Args.ContextParts) if Args.ContextParts else {},
|
DynamicParts=literal_eval(Args.DynamicParts) if Args.DynamicParts else {},
|
||||||
ContextPartsText=LoadFromDir('ContextParts', '*.html'),
|
DynamicPartsText=LoadFromDir('DynamicParts', '*.html'),
|
||||||
ConfMenu=ConfMenu,
|
ConfMenu=ConfMenu,
|
||||||
GlobalMacros=ReadConf(SiteConf, 'Macros'),
|
GlobalMacros=ReadConf(SiteConf, 'Macros'),
|
||||||
SiteName=SiteName,
|
SiteName=SiteName,
|
||||||
|
@ -133,7 +132,7 @@ def Main(Args, FeedEntries):
|
||||||
Locale=Locale,
|
Locale=Locale,
|
||||||
Minify=Minify,
|
Minify=Minify,
|
||||||
NoScripts=NoScripts,
|
NoScripts=NoScripts,
|
||||||
Sorting=SetSorting(literal_eval(Args.ContextParts) if Args.ContextParts else {}),
|
Sorting=SetSorting(literal_eval(Args.Sorting) if Args.Sorting else {}),
|
||||||
MarkdownExts=MarkdownExts,
|
MarkdownExts=MarkdownExts,
|
||||||
AutoCategories=AutoCategories)
|
AutoCategories=AutoCategories)
|
||||||
|
|
||||||
|
@ -213,7 +212,7 @@ if __name__ == '__main__':
|
||||||
Parser.add_argument('--SitemapOut', type=str)
|
Parser.add_argument('--SitemapOut', type=str)
|
||||||
Parser.add_argument('--FeedEntries', type=int)
|
Parser.add_argument('--FeedEntries', type=int)
|
||||||
Parser.add_argument('--FolderRoots', type=str)
|
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('--MarkdownExts', type=str)
|
||||||
Parser.add_argument('--MastodonURL', type=str)
|
Parser.add_argument('--MastodonURL', type=str)
|
||||||
Parser.add_argument('--MastodonToken', type=str)
|
Parser.add_argument('--MastodonToken', type=str)
|
||||||
|
|
|
@ -129,8 +129,8 @@ def TemplatePreprocessor(Text):
|
||||||
for l in Text.splitlines():
|
for l in Text.splitlines():
|
||||||
ll = l.lstrip()
|
ll = l.lstrip()
|
||||||
if ll.startswith('<!--'):
|
if ll.startswith('<!--'):
|
||||||
lll = ll[4:].lstrip()
|
lll = ll[4:].lstrip().rstrip()
|
||||||
if lll.startswith('%'):
|
if lll.startswith('%') and lll.endswith('-->'):
|
||||||
Meta += lll[1:-3].lstrip().rstrip() + '\n'
|
Meta += lll[1:-3].lstrip().rstrip() + '\n'
|
||||||
Meta = dict(ReadConf(LoadConfStr('[Meta]\n' + Meta), 'Meta'))
|
Meta = dict(ReadConf(LoadConfStr('[Meta]\n' + Meta), 'Meta'))
|
||||||
for i in MetaDefault:
|
for i in MetaDefault:
|
||||||
|
@ -262,14 +262,13 @@ def OrderPages(Old):
|
||||||
Max = int(Curr)
|
Max = int(Curr)
|
||||||
else:
|
else:
|
||||||
NoOrder += [e]
|
NoOrder += [e]
|
||||||
for i in range(Max+1):
|
New = [None] * (Max+1)
|
||||||
New += [[]]
|
|
||||||
for i,e in enumerate(Old):
|
for i,e in enumerate(Old):
|
||||||
Curr = e[3]['Order']
|
Curr = e[3]['Order']
|
||||||
if Curr:
|
if Curr:
|
||||||
New[int(Curr)] = e
|
New[int(Curr)] = e
|
||||||
while [] in New:
|
while None in New:
|
||||||
New.remove([])
|
New.remove(None)
|
||||||
return New + NoOrder
|
return New + NoOrder
|
||||||
|
|
||||||
def CanIndex(Index, For):
|
def CanIndex(Index, For):
|
||||||
|
@ -280,7 +279,7 @@ def CanIndex(Index, For):
|
||||||
else:
|
else:
|
||||||
return True if Index == For else False
|
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)
|
HTMLTitles = FormatTitles(Titles)
|
||||||
BodyDescription, BodyImage = '', ''
|
BodyDescription, BodyImage = '', ''
|
||||||
Soup = BeautifulSoup(Content, 'html.parser')
|
Soup = BeautifulSoup(Content, 'html.parser')
|
||||||
|
@ -299,23 +298,23 @@ def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesLi
|
||||||
|
|
||||||
for Line in HTML.splitlines():
|
for Line in HTML.splitlines():
|
||||||
Line = Line.lstrip().rstrip()
|
Line = Line.lstrip().rstrip()
|
||||||
if Line.startswith('[staticoso:ContextPart:') and Line.endswith(']'):
|
if Line.startswith('[staticoso:DynamicPart:') and Line.endswith(']'):
|
||||||
Path = Line[len('[staticoso:ContextPart:'):-1]
|
Path = Line[len('[staticoso:DynamicPart:'):-1]
|
||||||
Section = Path.split('/')[-1]
|
Section = Path.split('/')[-1]
|
||||||
if Section in ContextParts:
|
if Section in DynamicParts:
|
||||||
Part = ContextParts[Section]
|
Part = DynamicParts[Section]
|
||||||
Text = ''
|
Text = ''
|
||||||
if type(Part) == list:
|
if type(Part) == list:
|
||||||
for e in Part:
|
for e in Part:
|
||||||
Text += ContextPartsText[f"{Path}/{e}"] + '\n'
|
Text += DynamicPartsText[f"{Path}/{e}"] + '\n'
|
||||||
elif type(Part) == str:
|
elif type(Part) == str:
|
||||||
Text = ContextPartsText[f"{Path}/{Part}"]
|
Text = DynamicPartsText[f"{Path}/{Part}"]
|
||||||
else:
|
else:
|
||||||
Text = ''
|
Text = ''
|
||||||
HTML = ReplWithEsc(HTML, f"[staticoso:ContextPart:{Path}]", Text)
|
HTML = ReplWithEsc(HTML, f"[staticoso:DynamicPart:{Path}]", Text)
|
||||||
|
|
||||||
for e in PartsText:
|
for e in StaticPartsText:
|
||||||
HTML = ReplWithEsc(HTML, f"[staticoso:Part:{e}]", PartsText[e])
|
HTML = ReplWithEsc(HTML, f"[staticoso:StaticPart:{e}]", StaticPartsText[e])
|
||||||
HTML = ReplWithEsc(HTML, '[staticoso:Site:Menu]', HTMLPagesList)
|
HTML = ReplWithEsc(HTML, '[staticoso:Site:Menu]', HTMLPagesList)
|
||||||
HTML = ReplWithEsc(HTML, '[staticoso:Page:Lang]', SiteLang)
|
HTML = ReplWithEsc(HTML, '[staticoso:Page:Lang]', SiteLang)
|
||||||
HTML = ReplWithEsc(HTML, '[staticoso:Page:Chapters]', HTMLTitles)
|
HTML = ReplWithEsc(HTML, '[staticoso:Page:Chapters]', HTMLTitles)
|
||||||
|
@ -362,7 +361,7 @@ def DoMinifyHTML(HTML):
|
||||||
convert_charrefs=True,
|
convert_charrefs=True,
|
||||||
keep_pre=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 = [], [], [], [], {}
|
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
||||||
for Ext in FileExtensions['Pages']:
|
for Ext in FileExtensions['Pages']:
|
||||||
for File in Path('Pages').rglob(f"*.{Ext}"):
|
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}"):
|
for File in Path('Posts').rglob(f"*.{Ext}"):
|
||||||
PostsPaths += [FileToStr(File, 'Posts/')]
|
PostsPaths += [FileToStr(File, 'Posts/')]
|
||||||
|
|
||||||
if Sorting['Pages'] == 'Standard':
|
PagesPaths = FileNameDateSort(PagesPaths)
|
||||||
PagesPaths.sort()
|
if Sorting['Pages'] == 'Inverse':
|
||||||
elif Sorting['Pages'] == 'Inverse':
|
PagesPaths.reverse() #= RevSort(PagesPaths)
|
||||||
PagesPaths = RevSort(PagesPaths)
|
PostsPaths = FileNameDateSort(PostsPaths)
|
||||||
if Sorting['Posts'] == 'Standard':
|
if Sorting['Posts'] == 'Inverse':
|
||||||
PostsPaths.sort()
|
PostsPaths.reverse() #= RevSort(PostsPaths)
|
||||||
elif Sorting['Posts'] == 'Inverse':
|
|
||||||
PostsPaths = RevSort(PostsPaths)
|
|
||||||
|
|
||||||
print("[I] Preprocessing Source Pages")
|
print("[I] Preprocessing Source Pages")
|
||||||
for Type in ['Page', 'Post']:
|
for Type in ['Page', 'Post']:
|
||||||
|
@ -460,9 +457,9 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu,
|
||||||
HTML, ContentHTML, SlimHTML, Description, Image = PatchHTML(
|
HTML, ContentHTML, SlimHTML, Description, Image = PatchHTML(
|
||||||
File=File,
|
File=File,
|
||||||
HTML=TemplatesText[Meta['Template']],
|
HTML=TemplatesText[Meta['Template']],
|
||||||
PartsText=PartsText,
|
StaticPartsText=StaticPartsText,
|
||||||
ContextParts=ContextParts,
|
DynamicParts=DynamicParts,
|
||||||
ContextPartsText=ContextPartsText,
|
DynamicPartsText=DynamicPartsText,
|
||||||
HTMLPagesList=HTMLPagesList,
|
HTMLPagesList=HTMLPagesList,
|
||||||
PagePath=PagePath[len('public/'):],
|
PagePath=PagePath[len('public/'):],
|
||||||
Content=Content,
|
Content=Content,
|
||||||
|
|
|
@ -94,11 +94,52 @@ def ReplWithEsc(Str, Find, Repl, Esc='\\'):
|
||||||
New += Repl + e
|
New += Repl + e
|
||||||
return New
|
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):
|
def RevSort(List):
|
||||||
List.sort()
|
List.sort()
|
||||||
List.reverse()
|
List.reverse()
|
||||||
return List
|
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):
|
def FirstRealItem(List):
|
||||||
return next(e for e in List if e)
|
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
|
- Make alt text for images also be title text
|
||||||
- Custom category names showing in header links
|
- Custom category names showing in header links
|
||||||
- Fix arguments - some are only callable from CLI and not Site.ini
|
- Fix arguments - some are only callable from CLI and not Site.ini
|
||||||
|
@ -15,3 +15,8 @@
|
||||||
- Fix feed titles and page title ids
|
- Fix feed titles and page title ids
|
||||||
- Use filename as page title if it is missing
|
- Use filename as page title if it is missing
|
||||||
- Hybrid global+page menu (like on documentation generators)
|
- 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