2022-07-14 20:38:45 +02:00
|
|
|
""" ================================= |
|
|
|
|
| This file is part of |
|
|
|
|
| staticoso |
|
|
|
|
| Just a simple Static Site Generator |
|
|
|
|
| |
|
|
|
|
| Licensed under the AGPLv3 license |
|
|
|
|
| Copyright (C) 2022, OctoSpacc |
|
|
|
|
| ================================= """
|
|
|
|
|
2022-11-18 20:51:54 +01:00
|
|
|
import shutil
|
2022-08-23 17:25:05 +02:00
|
|
|
from datetime import datetime
|
2022-08-30 21:10:45 +02:00
|
|
|
from multiprocessing import Pool, cpu_count
|
2022-07-14 20:38:45 +02:00
|
|
|
from Libs.bs4 import BeautifulSoup
|
2022-07-28 16:27:37 +02:00
|
|
|
from Modules.Config import *
|
2022-08-30 21:10:45 +02:00
|
|
|
from Modules.Elements import *
|
2022-12-20 13:05:41 +01:00
|
|
|
from Modules.Globals import *
|
2022-07-18 17:16:21 +02:00
|
|
|
from Modules.HTML import *
|
2022-09-03 17:48:39 +02:00
|
|
|
from Modules.Logging import *
|
2022-07-14 20:38:45 +02:00
|
|
|
from Modules.Markdown import *
|
|
|
|
from Modules.Pug import *
|
|
|
|
from Modules.Utils import *
|
|
|
|
|
2022-11-04 11:03:43 +01:00
|
|
|
# Menu styles:
|
|
|
|
# - Simple: Default, Flat, Line
|
|
|
|
# - Others: Excerpt, Image, Preview (Excerpt + Image), Full
|
2023-02-22 22:46:04 +01:00
|
|
|
def GetHTMLPagesList(Pages:list, BlogName:str, SiteRoot:str, PathPrefix:str, CallbackFile=None, Unite=[], Type=None, Limit=None, PathFilter='', Category=None, For='Menu', MarkdownExts=(), MenuStyle='Default', ShowPaths=True):
|
2022-11-04 11:03:43 +01:00
|
|
|
Flatten, SingleLine, DoneCount, PrevDepth = False, False, 0, 0
|
2022-08-13 13:14:48 +02:00
|
|
|
if MenuStyle == 'Flat':
|
|
|
|
Flatten = True
|
|
|
|
elif MenuStyle == 'Line':
|
|
|
|
ShowPaths, SingleLine = False, True
|
2022-07-14 20:38:45 +02:00
|
|
|
List, ToPop, LastParent = '', [], []
|
|
|
|
IndexPages = Pages.copy()
|
|
|
|
for e in IndexPages:
|
2022-12-20 13:05:41 +01:00
|
|
|
if e[3]['Index'].lower() in PageIndexStrNeg:
|
2022-07-14 20:38:45 +02:00
|
|
|
IndexPages.remove(e)
|
|
|
|
for i,e in enumerate(IndexPages):
|
2022-10-25 10:13:00 +02:00
|
|
|
if Type and e[3]['Type'] != Type:
|
2022-07-14 20:38:45 +02:00
|
|
|
ToPop += [i]
|
|
|
|
ToPop = RevSort(ToPop)
|
|
|
|
for i in ToPop:
|
|
|
|
IndexPages.pop(i)
|
|
|
|
if Type == 'Page':
|
|
|
|
IndexPages = OrderPages(IndexPages)
|
2022-07-15 00:12:58 +02:00
|
|
|
for i,e in enumerate(Unite):
|
|
|
|
if e:
|
2022-12-20 13:05:41 +01:00
|
|
|
IndexPages.insert(i, [e, None, None, {'Type':Type, 'Index':'True', 'Order':'Unite'}])
|
2022-07-14 20:38:45 +02:00
|
|
|
for File, Content, Titles, Meta in IndexPages:
|
2022-10-26 11:01:17 +02:00
|
|
|
# Allow for the virtual "Pages/" prefix to be used in path filtering
|
2022-10-25 12:04:17 +02:00
|
|
|
TmpPathFilter = PathFilter
|
|
|
|
if TmpPathFilter.startswith('Pages/'):
|
|
|
|
TmpPathFilter = TmpPathFilter[len('Pages/'):]
|
|
|
|
if File.startswith('Posts/'):
|
|
|
|
continue
|
2022-10-26 11:01:17 +02:00
|
|
|
|
|
|
|
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):
|
2022-07-15 16:48:18 +02:00
|
|
|
Depth = (File.count('/') + 1) if Meta['Order'] != 'Unite' else 1
|
2022-11-04 11:03:43 +01:00
|
|
|
# Folder names are handled here
|
|
|
|
if Depth > 1 and Meta['Order'] != 'Unite':
|
2022-07-14 20:38:45 +02:00
|
|
|
CurParent = File.split('/')[:-1]
|
|
|
|
for i,s in enumerate(CurParent):
|
2022-08-13 13:14:48 +02:00
|
|
|
if LastParent != CurParent and ShowPaths:
|
2022-07-14 20:38:45 +02:00
|
|
|
LastParent = CurParent
|
2022-11-04 11:03:43 +01:00
|
|
|
Levels = '.' * ((Depth-2+i) if not Flatten else 0) + ':'
|
2022-10-26 11:01:17 +02:00
|
|
|
# If search node endswith index, it's a page; else, it's a folder
|
2022-07-14 20:38:45 +02:00
|
|
|
if StripExt(File).endswith('index'):
|
2023-02-17 21:53:37 +01:00
|
|
|
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', BlogName, PathPrefix)
|
2022-10-26 11:01:17 +02:00
|
|
|
DoneCount += 1
|
2022-07-14 20:38:45 +02:00
|
|
|
else:
|
2022-07-15 16:48:18 +02:00
|
|
|
Title = CurParent[Depth-2+i]
|
2022-08-13 13:14:48 +02:00
|
|
|
if SingleLine:
|
2023-02-17 21:53:37 +01:00
|
|
|
List += f' <span>{Title}</span> '
|
2022-08-13 13:14:48 +02:00
|
|
|
else:
|
2023-02-17 21:53:37 +01:00
|
|
|
List += f'{Levels}<span>{Title}</span>\n'
|
2022-10-26 11:01:17 +02:00
|
|
|
|
|
|
|
# Pages with any other path
|
2022-07-25 17:06:16 +02:00
|
|
|
if not (Depth > 1 and StripExt(File).split('/')[-1] == 'index'):
|
2022-11-04 11:03:43 +01:00
|
|
|
Levels = '.' * ((Depth-1) if not Flatten else 0) + ':'
|
2022-10-26 11:01:17 +02:00
|
|
|
DoneCount += 1
|
2022-07-15 00:12:58 +02:00
|
|
|
if Meta['Order'] == 'Unite':
|
2022-11-04 11:03:43 +01:00
|
|
|
Title = markdown(MarkdownHTMLEscape(File, MarkdownExts), extensions=MarkdownExts).removeprefix('<p>').removesuffix('<p>')
|
2022-07-15 00:12:58 +02:00
|
|
|
else:
|
2023-02-17 21:53:37 +01:00
|
|
|
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', BlogName, PathPrefix)
|
2022-08-13 13:14:48 +02:00
|
|
|
if SingleLine:
|
|
|
|
List += ' <span>' + Title + '</span> '
|
|
|
|
else:
|
|
|
|
List += Levels + Title + '\n'
|
2022-10-26 11:01:17 +02:00
|
|
|
|
2022-11-04 11:03:43 +01:00
|
|
|
if MenuStyle in ('Default', 'Flat'):
|
2023-02-17 21:53:37 +01:00
|
|
|
return GenHTMLTreeList(List, Class="staticoso-PagesList")
|
2022-11-04 11:03:43 +01:00
|
|
|
elif MenuStyle in ('Line', 'Excerpt', 'Image', 'Preview', 'Full'):
|
|
|
|
return List
|
2022-07-14 20:38:45 +02:00
|
|
|
|
2023-02-22 22:46:04 +01:00
|
|
|
def CheckHTMLCommentLine(Line:str):
|
2022-09-23 00:23:52 +02:00
|
|
|
if Line.startswith('<!--'):
|
|
|
|
Line = Line[4:].lstrip()
|
|
|
|
if Line.endswith('-->'):
|
|
|
|
return Line
|
|
|
|
return None
|
|
|
|
|
2023-02-22 22:46:04 +01:00
|
|
|
def TemplatePreprocessor(Text:str):
|
2022-08-13 00:29:34 +02:00
|
|
|
Meta, MetaDefault = '', {
|
|
|
|
'MenuStyle': 'Default'}
|
|
|
|
for l in Text.splitlines():
|
2022-09-23 00:23:52 +02:00
|
|
|
ll = l.lstrip().rstrip()
|
|
|
|
lll = CheckHTMLCommentLine(ll)
|
|
|
|
if lll:
|
|
|
|
if lll.startswith('%'):
|
2022-08-13 00:29:34 +02:00
|
|
|
Meta += lll[1:-3].lstrip().rstrip() + '\n'
|
|
|
|
Meta = dict(ReadConf(LoadConfStr('[Meta]\n' + Meta), 'Meta'))
|
|
|
|
for i in MetaDefault:
|
|
|
|
if not i in Meta:
|
|
|
|
Meta.update({i:MetaDefault[i]})
|
|
|
|
return Meta
|
|
|
|
|
2023-02-22 22:46:04 +01:00
|
|
|
def FindPreprocLine(Line:str, Meta, Macros):
|
2022-12-15 16:29:22 +01:00
|
|
|
Changed = False
|
|
|
|
Line = Line.lstrip().rstrip()
|
|
|
|
lll = CheckHTMLCommentLine(Line)
|
|
|
|
if Line.startswith('//') or lll: # Find preprocessor lines
|
|
|
|
lll = Line[2:].lstrip()
|
|
|
|
if lll.startswith('%'):
|
|
|
|
Meta += lll[1:].lstrip() + '\n'
|
|
|
|
Changed = True
|
|
|
|
elif lll.startswith('$'):
|
|
|
|
Macros += lll[1:].lstrip() + '\n'
|
|
|
|
Changed = True
|
|
|
|
#if ll.startswith('<!--') and not ll.endswith('-->'): # Find comment and code blocks
|
|
|
|
# IgnoreBlocksStart += [l]
|
|
|
|
return (Meta, Macros, Changed)
|
|
|
|
|
2023-02-22 22:46:04 +01:00
|
|
|
def PagePreprocessor(Path:str, TempPath:str, Type:str, SiteTemplate, SiteRoot, GlobalMacros, CategoryUncategorized, LightRun:bool=False, Content=None):
|
|
|
|
File = ReadFile(Path) if not Content else Content
|
2022-08-14 17:35:58 +02:00
|
|
|
Path = Path.lower()
|
2022-08-13 00:29:34 +02:00
|
|
|
Content, Titles, DashyTitles, HTMLTitlesFound, Macros, Meta, MetaDefault = '', [], [], False, '', '', {
|
2022-08-12 19:53:49 +02:00
|
|
|
'Template': SiteTemplate,
|
2022-12-20 13:05:41 +01:00
|
|
|
'Head': '',
|
2022-07-14 20:38:45 +02:00
|
|
|
'Style': '',
|
2022-07-29 20:34:03 +02:00
|
|
|
'Type': Type,
|
|
|
|
'Index': 'Unspecified',
|
2022-07-24 16:47:12 +02:00
|
|
|
'Feed': 'True',
|
2022-07-14 20:38:45 +02:00
|
|
|
'Title': '',
|
|
|
|
'HTMLTitle': '',
|
|
|
|
'Description': '',
|
|
|
|
'Image': '',
|
2022-07-28 16:27:37 +02:00
|
|
|
'Macros': {},
|
2022-07-14 20:38:45 +02:00
|
|
|
'Categories': [],
|
2022-10-17 15:53:07 +02:00
|
|
|
'URLs': [],
|
2022-07-14 20:38:45 +02:00
|
|
|
'CreatedOn': '',
|
2022-10-17 15:53:07 +02:00
|
|
|
'UpdatedOn': '',
|
2022-07-14 20:38:45 +02:00
|
|
|
'EditedOn': '',
|
2022-11-18 20:51:54 +01:00
|
|
|
'Order': None,
|
2022-12-15 16:29:22 +01:00
|
|
|
'Language': None,
|
|
|
|
'Downsync': None}
|
2022-09-23 00:23:52 +02:00
|
|
|
# Find all positions of '<!--', '-->', add them in a list=[[pos0,pos1,line0,line1],...]
|
2022-07-14 20:38:45 +02:00
|
|
|
for l in File.splitlines():
|
2022-09-23 00:23:52 +02:00
|
|
|
ll = l.lstrip().rstrip()
|
2022-12-15 16:29:22 +01:00
|
|
|
Meta, Macros, Changed = FindPreprocLine(ll, Meta, Macros)
|
|
|
|
if not Changed: # Find headings
|
2022-09-23 00:23:52 +02:00
|
|
|
#if line in ignore block:
|
|
|
|
# continue
|
2022-07-21 19:15:30 +02:00
|
|
|
Headings = ('h1', 'h2', 'h3', 'h4', 'h5', 'h6')
|
2022-12-15 16:29:22 +01:00
|
|
|
#if Path.endswith(FileExtensions['HTML']):
|
|
|
|
# if ll[1:].startswith(Headings):
|
|
|
|
# if ll[3:].startswith((" class='NoTitle", ' class="NoTitle')):
|
|
|
|
# Content += l + '\n'
|
|
|
|
# elif ll.replace(' ', ' ').startswith('// %'):
|
|
|
|
# pass
|
|
|
|
# else:
|
|
|
|
# Title = '#'*int(ll[2]) + ' ' + ll[4:]
|
|
|
|
# DashTitle = DashifyTitle(Title.lstrip('#'), DashyTitles)
|
|
|
|
# DashyTitles += [DashTitle]
|
|
|
|
# Titles += [Title]
|
|
|
|
# Content += MakeLinkableTitle(l, Title, DashTitle, 'pug') + '\n'
|
|
|
|
# else:
|
|
|
|
# Content += l + '\n'
|
2022-08-14 17:35:58 +02:00
|
|
|
if Path.endswith(FileExtensions['HTML']) and not HTMLTitlesFound:
|
2022-07-21 19:15:30 +02:00
|
|
|
Soup = BeautifulSoup(File, 'html.parser')
|
|
|
|
Tags = Soup.find_all()
|
|
|
|
for t in Tags:
|
|
|
|
if t.name in Headings:
|
|
|
|
Title = '#'*int(t.name[1]) + ' ' + str(t.text)
|
|
|
|
DashTitle = DashifyTitle(Title.lstrip('#'), DashyTitles)
|
|
|
|
DashyTitles += [DashTitle]
|
|
|
|
Titles += [Title]
|
|
|
|
t.replace_with(MakeLinkableTitle(None, Title, DashTitle, 'md'))
|
|
|
|
HTMLTitlesFound = True
|
2022-12-15 16:29:22 +01:00
|
|
|
Content = ''
|
|
|
|
TmpContent = str(Soup.prettify(formatter=None))
|
|
|
|
for cl in TmpContent.splitlines():
|
|
|
|
_, _, IsMetaLine = FindPreprocLine(cl, Meta, Macros)
|
|
|
|
if not IsMetaLine:
|
|
|
|
#print(cl)
|
|
|
|
Content += cl + '\n'
|
|
|
|
break
|
2022-08-14 17:35:58 +02:00
|
|
|
elif Path.endswith(FileExtensions['Markdown']):
|
2022-09-23 00:23:52 +02:00
|
|
|
lsuffix = ''
|
|
|
|
if ll.startswith(('-', '+', '*')):
|
|
|
|
lsuffix += ll[0]
|
|
|
|
ll = ll[1:].lstrip()
|
2022-08-24 15:04:13 +02:00
|
|
|
if ll.startswith('#') or (ll.startswith('<') and ll[1:].startswith(Headings)):
|
|
|
|
if ll.startswith('#'):
|
|
|
|
Title = ll
|
|
|
|
elif ll.startswith('<'):
|
2022-09-03 17:48:39 +02:00
|
|
|
if ll[3:].startswith((" class='NoTitle", ' class="NoTitle')):
|
|
|
|
Content += l + '\n'
|
|
|
|
continue
|
|
|
|
else:
|
2022-12-15 16:29:22 +01:00
|
|
|
Title = '#'*int(ll[2]) + ' ' + ll[4:]
|
2022-08-24 15:04:13 +02:00
|
|
|
DashTitle = DashifyTitle(MkSoup(Title.lstrip('#')).get_text(), DashyTitles)
|
2022-07-14 20:38:45 +02:00
|
|
|
DashyTitles += [DashTitle]
|
2022-08-24 15:04:13 +02:00
|
|
|
Titles += [Title]
|
|
|
|
Title = MakeLinkableTitle(None, Title, DashTitle, 'md')
|
2022-12-15 16:29:22 +01:00
|
|
|
# I can't remember why I put this but it was needed
|
|
|
|
Title = Title.replace('> </', '> </').replace(' </', '</')
|
2022-09-23 00:23:52 +02:00
|
|
|
Content += lsuffix + Title + '\n'
|
2022-07-14 20:38:45 +02:00
|
|
|
else:
|
|
|
|
Content += l + '\n'
|
|
|
|
elif Path.endswith('.pug'):
|
2022-08-13 00:29:34 +02:00
|
|
|
if ll.startswith(Headings):
|
|
|
|
if ll[2:].startswith(("(class='NoTitle", '(class="NoTitle')):
|
2022-07-14 20:38:45 +02:00
|
|
|
Content += l + '\n'
|
|
|
|
else:
|
2022-12-15 16:29:22 +01:00
|
|
|
Title = '#'*int(ll[1]) + ll[3:]
|
2022-07-14 20:38:45 +02:00
|
|
|
DashTitle = DashifyTitle(Title.lstrip('#'), DashyTitles)
|
|
|
|
DashyTitles += [DashTitle]
|
|
|
|
Titles += [Title]
|
|
|
|
# TODO: We should handle headers that for any reason already have parenthesis
|
2022-08-13 00:29:34 +02:00
|
|
|
if ll[2:] == '(':
|
2022-07-14 20:38:45 +02:00
|
|
|
Content += l + '\n'
|
|
|
|
else:
|
|
|
|
Content += MakeLinkableTitle(l, Title, DashTitle, 'pug') + '\n'
|
|
|
|
else:
|
|
|
|
Content += l + '\n'
|
2022-08-14 17:35:58 +02:00
|
|
|
elif Path.endswith('.txt'):
|
|
|
|
Content += l + '\n'
|
2022-08-13 00:29:34 +02:00
|
|
|
Meta = dict(ReadConf(LoadConfStr('[Meta]\n' + Meta), 'Meta'))
|
|
|
|
for i in MetaDefault:
|
|
|
|
if i in Meta:
|
2022-10-17 15:53:07 +02:00
|
|
|
# TODO: Handle strings with spaces but wrapped in quotes
|
2022-08-13 00:29:34 +02:00
|
|
|
if i == 'Categories':
|
|
|
|
Categories = Meta['Categories'].split(' ')
|
|
|
|
Meta['Categories'] = []
|
|
|
|
for j in Categories:
|
|
|
|
Meta['Categories'] += [j]
|
2022-10-17 15:53:07 +02:00
|
|
|
elif i == 'URLs':
|
|
|
|
URLs = Meta['URLs'].split(' ')
|
|
|
|
Meta['URLs'] = []
|
|
|
|
for j in URLs:
|
|
|
|
Meta['URLs'] += [j]
|
2022-08-13 00:29:34 +02:00
|
|
|
else:
|
|
|
|
Meta.update({i:MetaDefault[i]})
|
2022-10-17 15:53:07 +02:00
|
|
|
if Meta['UpdatedOn']:
|
|
|
|
Meta['EditedOn'] = Meta['UpdatedOn']
|
2022-12-20 13:05:41 +01:00
|
|
|
if Meta['Index'].lower() in ('default', 'unspecified', 'categories'):
|
2022-07-29 20:34:03 +02:00
|
|
|
if not Meta['Categories']:
|
2022-08-29 20:28:12 +02:00
|
|
|
Meta['Categories'] = [CategoryUncategorized]
|
2022-12-20 13:05:41 +01:00
|
|
|
if Meta['Type'].lower() == 'page':
|
2022-09-23 00:23:52 +02:00
|
|
|
Meta['Index'] = 'Categories'
|
2022-12-20 13:05:41 +01:00
|
|
|
elif Meta['Type'].lower() == 'post':
|
2022-07-29 20:34:03 +02:00
|
|
|
Meta['Index'] = 'True'
|
2022-07-28 23:13:47 +02:00
|
|
|
if GlobalMacros:
|
|
|
|
Meta['Macros'].update(GlobalMacros)
|
|
|
|
Meta['Macros'].update(ReadConf(LoadConfStr('[Macros]\n' + Macros), 'Macros'))
|
2022-08-31 00:18:23 +02:00
|
|
|
return [TempPath, Content, Titles, Meta]
|
2022-07-14 20:38:45 +02:00
|
|
|
|
2022-12-20 13:05:41 +01:00
|
|
|
def PagePostprocessor(FileType, Text:str, Meta:dict):
|
2022-07-28 22:18:13 +02:00
|
|
|
for e in Meta['Macros']:
|
|
|
|
Text = ReplWithEsc(Text, f"[: {e} :]", f"[:{e}:]")
|
|
|
|
return Text
|
|
|
|
|
2022-12-20 13:05:41 +01:00
|
|
|
def OrderPages(Old:list):
|
2022-07-14 20:38:45 +02:00
|
|
|
New, NoOrder, Max = [], [], 0
|
|
|
|
for i,e in enumerate(Old):
|
|
|
|
Curr = e[3]['Order']
|
|
|
|
if Curr:
|
2022-08-13 00:29:34 +02:00
|
|
|
if int(Curr) > Max:
|
|
|
|
Max = int(Curr)
|
2022-07-14 20:38:45 +02:00
|
|
|
else:
|
|
|
|
NoOrder += [e]
|
2022-08-13 20:00:03 +02:00
|
|
|
New = [None] * (Max+1)
|
2022-07-14 20:38:45 +02:00
|
|
|
for i,e in enumerate(Old):
|
|
|
|
Curr = e[3]['Order']
|
|
|
|
if Curr:
|
2022-08-13 00:29:34 +02:00
|
|
|
New[int(Curr)] = e
|
2022-08-13 20:00:03 +02:00
|
|
|
while None in New:
|
|
|
|
New.remove(None)
|
2022-07-14 20:38:45 +02:00
|
|
|
return New + NoOrder
|
|
|
|
|
2022-12-20 13:05:41 +01:00
|
|
|
def CanIndex(Index:str, For:str):
|
|
|
|
if Index.lower() in PageIndexStrNeg:
|
2022-07-14 20:38:45 +02:00
|
|
|
return False
|
2022-12-20 13:05:41 +01:00
|
|
|
elif Index.lower() in PageIndexStrPos:
|
2022-07-14 20:38:45 +02:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return True if Index == For else False
|
|
|
|
|
2022-09-03 17:48:39 +02:00
|
|
|
def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLPagesList, PagePath, Content, Titles, Meta, SiteDomain, SiteRoot, SiteName, BlogName, FolderRoots, Categories, SiteLang, Locale, LightRun):
|
2022-07-14 20:38:45 +02:00
|
|
|
HTMLTitles = FormatTitles(Titles)
|
|
|
|
BodyDescription, BodyImage = '', ''
|
2022-08-14 17:35:58 +02:00
|
|
|
if not File.lower().endswith('.txt'):
|
2022-12-20 13:05:41 +01:00
|
|
|
Soup = MkSoup(Content)
|
|
|
|
if not BodyDescription:# and Soup.p:
|
|
|
|
#BodyDescription = Soup.p.get_text()[:150].replace('\n', ' ').replace('"', "'") + '...'
|
|
|
|
for t in Soup.find_all('p'):
|
|
|
|
if t.get_text():
|
|
|
|
BodyDescription = t.get_text()[:150].replace('\n', ' ').replace('"', "'") + '...'
|
|
|
|
break
|
2022-08-14 17:35:58 +02:00
|
|
|
if not BodyImage and Soup.img and Soup.img['src']:
|
|
|
|
BodyImage = Soup.img['src']
|
2022-07-29 18:12:13 +02:00
|
|
|
|
2022-08-14 17:35:58 +02:00
|
|
|
#Content = SquareFnrefs(Content)
|
2022-12-20 13:05:41 +01:00
|
|
|
if '<a class="footnote-ref" ' in Content:
|
|
|
|
Content = AddToTagStartEnd(Content, '<a class="footnote-ref" ', '</a>', '[', ']')
|
2022-07-14 20:38:45 +02:00
|
|
|
|
2022-10-26 11:01:17 +02:00
|
|
|
if any(_ in Content for _ in ('<!-- noprocess />', '<!--noprocess/>', '</ noprocess -->', '</ noprocess --->', '</noprocess-->', '</noprocess--->')):
|
2022-09-03 17:48:39 +02:00
|
|
|
Content = DictReplWithEsc(
|
|
|
|
Content, {
|
2022-12-20 13:05:41 +01:00
|
|
|
'<!--<%noprocess>': '',
|
|
|
|
'<noprocess%>-->': '',
|
|
|
|
'<noprocess%>--->': '',
|
2022-10-26 11:01:17 +02:00
|
|
|
'<!-- noprocess />': '',
|
|
|
|
'<!--noprocess/>': '',
|
|
|
|
'</ noprocess -->': '',
|
|
|
|
'</ noprocess --->': '',
|
|
|
|
'</noprocess-->': '',
|
|
|
|
'</noprocess--->': ''})
|
2022-09-03 17:48:39 +02:00
|
|
|
|
2022-08-14 17:35:58 +02:00
|
|
|
Title = GetTitle(File.split('/')[-1], Meta, Titles, 'MetaTitle', BlogName)
|
2022-07-14 20:38:45 +02:00
|
|
|
Description = GetDescription(Meta, BodyDescription, 'MetaDescription')
|
|
|
|
Image = GetImage(Meta, BodyImage, 'MetaImage')
|
2022-10-19 11:27:51 +02:00
|
|
|
ContentHeader = MakeContentHeader(Meta, Locale, MakeCategoryLine(File, Meta))
|
|
|
|
TimeNow = datetime.now().strftime('%Y-%m-%d %H:%M')
|
2022-11-04 11:03:43 +01:00
|
|
|
RelativeRoot = GetPathLevels(PagePath)
|
2022-07-14 20:38:45 +02:00
|
|
|
|
2022-10-25 10:13:00 +02:00
|
|
|
if 'staticoso:DynamicPart:' in HTML: # Reduce risk of unnecessary cycles
|
|
|
|
for Line in HTML.splitlines():
|
|
|
|
Line = Line.lstrip().rstrip()
|
|
|
|
if (Line.startswith('[staticoso:DynamicPart:') and Line.endswith(']')) or (Line.startswith('<staticoso:DynamicPart:') and Line.endswith('>')):
|
|
|
|
Path = Line[len('<staticoso:DynamicPart:'):-1]
|
|
|
|
Section = Path.split('/')[-1]
|
|
|
|
if Section in DynamicParts:
|
|
|
|
Part = DynamicParts[Section]
|
|
|
|
Text = ''
|
|
|
|
if type(Part) == list:
|
|
|
|
for e in Part:
|
|
|
|
Text += DynamicPartsText[f"{Path}/{e}"] + '\n'
|
|
|
|
elif type(Part) == str:
|
|
|
|
Text = DynamicPartsText[f"{Path}/{Part}"]
|
|
|
|
else:
|
|
|
|
Text = ''
|
|
|
|
HTML = ReplWithEsc(HTML, f"[staticoso:DynamicPart:{Path}]", Text)
|
|
|
|
HTML = ReplWithEsc(HTML, f"<staticoso:DynamicPart:{Path}>", Text)
|
2022-07-28 22:18:13 +02:00
|
|
|
|
2022-11-16 13:07:27 +01:00
|
|
|
for i in range(2):
|
|
|
|
for e in StaticPartsText:
|
|
|
|
HTML = ReplWithEsc(HTML, f"[staticoso:StaticPart:{e}]", StaticPartsText[e])
|
|
|
|
HTML = ReplWithEsc(HTML, f"<staticoso:StaticPart:{e}>", StaticPartsText[e])
|
2022-08-29 20:28:12 +02:00
|
|
|
|
|
|
|
if LightRun:
|
|
|
|
HTML = None
|
|
|
|
else:
|
2022-12-20 13:05:41 +01:00
|
|
|
HTML = WrapDictReplWithEsc(HTML, {
|
|
|
|
#'[staticoso:PageHead]': Meta['Head'],
|
|
|
|
#'<staticoso:PageHead>': Meta['Head'],
|
|
|
|
# #DEPRECATION #
|
|
|
|
'staticoso:Site:Menu': HTMLPagesList,
|
|
|
|
'staticoso:Page:Lang': Meta['Language'] if Meta['Language'] else SiteLang,
|
|
|
|
'staticoso:Page:Chapters': HTMLTitles,
|
|
|
|
'staticoso:Page:Title': Title,
|
|
|
|
'staticoso:Page:Description': Description,
|
|
|
|
'staticoso:Page:Image': Image,
|
|
|
|
'staticoso:Page:Path': PagePath,
|
|
|
|
'staticoso:Page:Style': Meta['Style'],
|
|
|
|
################
|
|
|
|
'staticoso:SiteMenu': HTMLPagesList,
|
|
|
|
'staticoso:PageLang': Meta['Language'] if Meta['Language'] else SiteLang,
|
|
|
|
'staticoso:PageLanguage': Meta['Language'] if Meta['Language'] else SiteLang,
|
|
|
|
'staticoso:PageSections': HTMLTitles,
|
|
|
|
'staticoso:PageTitle': Title,
|
|
|
|
'staticoso:PageDescription': Description,
|
|
|
|
'staticoso:PageImage': Image,
|
|
|
|
'staticoso:PagePath': PagePath,
|
|
|
|
'staticoso:PageHead': Meta['Head'],
|
|
|
|
'staticoso:PageStyle': Meta['Style'],
|
2022-11-04 11:03:43 +01:00
|
|
|
# NOTE: Content is injected in page only at this point! Keep in mind for other substitutions
|
2022-12-20 13:05:41 +01:00
|
|
|
# #DEPRECATION #
|
|
|
|
'staticoso:Page:Content': Content,
|
|
|
|
'staticoso:Page:ContentInfo': ContentHeader,
|
|
|
|
'staticoso:Site:Name': SiteName,
|
|
|
|
'staticoso:Site:AbsoluteRoot': SiteRoot,
|
|
|
|
'staticoso:Site:RelativeRoot': RelativeRoot,
|
|
|
|
################
|
|
|
|
'staticoso:PageContent': Content,
|
|
|
|
'staticoso:PageContentInfo': ContentHeader,
|
|
|
|
'staticoso:BuildTime': TimeNow,
|
|
|
|
'staticoso:SiteDomain': SiteDomain,
|
|
|
|
'staticoso:SiteName': SiteName,
|
|
|
|
'staticoso:SiteAbsoluteRoot': SiteRoot,
|
|
|
|
'staticoso:SiteRelativeRoot': RelativeRoot,
|
|
|
|
}, InternalMacrosWraps)
|
2022-11-04 11:03:43 +01:00
|
|
|
for e in Meta['Macros']:
|
|
|
|
HTML = ReplWithEsc(HTML, f"[:{e}:]", Meta['Macros'][e])
|
|
|
|
for e in FolderRoots:
|
2022-12-20 13:05:41 +01:00
|
|
|
HTML = WrapDictReplWithEsc(HTML, {
|
|
|
|
f'staticoso:CustomPath:{e}': FolderRoots[e],
|
|
|
|
f'staticoso:Folder:{e}:AbsoluteRoot': FolderRoots[e], #DEPRECATED
|
|
|
|
}, InternalMacrosWraps)
|
2022-11-04 11:03:43 +01:00
|
|
|
for e in Categories:
|
2022-12-20 13:05:41 +01:00
|
|
|
HTML = WrapDictReplWithEsc(HTML, {
|
|
|
|
f'staticoso:Category:{e}': Categories[e],
|
|
|
|
f'staticoso:CategoryList:{e}': Categories[e],
|
|
|
|
}, InternalMacrosWraps)
|
|
|
|
HTML = ReplWithEsc(HTML, f'<span>[staticoso:Category:{e}]</span>', Categories[e]) #DEPRECATED
|
2022-11-04 11:03:43 +01:00
|
|
|
|
|
|
|
# TODO: Clean this doubling?
|
|
|
|
ContentHTML = Content
|
2022-12-20 13:05:41 +01:00
|
|
|
ContentHTML = WrapDictReplWithEsc(ContentHTML, {
|
|
|
|
# #DEPRECATION #
|
2022-11-04 11:03:43 +01:00
|
|
|
'[staticoso:Page:Title]': Title,
|
|
|
|
'[staticoso:Page:Description]': Description,
|
2022-12-20 13:05:41 +01:00
|
|
|
'[staticoso:Site:Name]': SiteName,
|
|
|
|
'[staticoso:Site:AbsoluteRoot]': SiteRoot,
|
|
|
|
'[staticoso:Site:RelativeRoot]': RelativeRoot,
|
|
|
|
################
|
|
|
|
'<staticoso:PageTitle>': Title,
|
2022-11-04 11:03:43 +01:00
|
|
|
'<staticoso:PageDescription>': Description,
|
|
|
|
'<staticoso:SiteDomain>': SiteDomain,
|
|
|
|
'<staticoso:SiteName>': SiteName,
|
|
|
|
'<staticoso:SiteAbsoluteRoot>': SiteRoot,
|
2022-12-20 13:05:41 +01:00
|
|
|
'<staticoso:SiteRelativeRoot>': RelativeRoot,
|
|
|
|
}, InternalMacrosWraps)
|
2022-07-28 16:27:37 +02:00
|
|
|
for e in Meta['Macros']:
|
2022-07-29 18:12:13 +02:00
|
|
|
ContentHTML = ReplWithEsc(ContentHTML, f"[:{e}:]", Meta['Macros'][e])
|
2022-07-28 16:27:37 +02:00
|
|
|
for e in FolderRoots:
|
2022-12-20 13:05:41 +01:00
|
|
|
ContentHTML = WrapDictReplWithEsc(ContentHTML, {
|
|
|
|
f'staticoso:CustomPath:{e}': FolderRoots[e],
|
|
|
|
f'staticoso:Folder:{e}:AbsoluteRoot': FolderRoots[e], #DEPRECATED
|
|
|
|
}, InternalMacrosWraps)
|
2022-07-28 16:27:37 +02:00
|
|
|
for e in Categories:
|
2022-12-20 13:05:41 +01:00
|
|
|
ContentHTML = WrapDictReplWithEsc(ContentHTML, {
|
|
|
|
f'staticoso:Category:{e}': Categories[e],
|
|
|
|
f'staticoso:CategoryList:{e}': Categories[e],
|
|
|
|
}, InternalMacrosWraps)
|
|
|
|
ContentHTML = ReplWithEsc(ContentHTML, f'<span>[staticoso:Category:{e}]</span>', Categories[e]) #DEPRECATED
|
2022-07-14 20:38:45 +02:00
|
|
|
|
2022-08-29 20:28:12 +02:00
|
|
|
return HTML, ContentHTML, Description, Image
|
2022-07-14 20:38:45 +02:00
|
|
|
|
2022-08-30 21:10:45 +02:00
|
|
|
def HandlePage(Flags, Page, Pages, Categories, LimitFiles, Snippets, ConfMenu, Locale):
|
|
|
|
File, Content, Titles, Meta = Page
|
|
|
|
OutDir, MarkdownExts, Sorting, MinifyKeepComments = Flags['OutDir'], Flags['MarkdownExts'], Flags['Sorting'], Flags['MinifyKeepComments']
|
|
|
|
SiteName, BlogName, SiteTagline = Flags['SiteName'], Flags['BlogName'], Flags['SiteTagline']
|
|
|
|
SiteTemplate, SiteLang = Flags['SiteTemplate'], Flags['SiteLang']
|
|
|
|
SiteDomain, SiteRoot, FolderRoots = Flags['SiteDomain'], Flags['SiteRoot'], Flags['FolderRoots']
|
2022-08-30 16:31:33 +02:00
|
|
|
AutoCategories, CategoryUncategorized = Flags['CategoriesAutomatic'], Flags['CategoriesUncategorized']
|
|
|
|
ImgAltToTitle, ImgTitleToAlt = Flags['ImgAltToTitle'], Flags['ImgTitleToAlt']
|
2022-08-30 21:10:45 +02:00
|
|
|
DynamicParts, DynamicPartsText, StaticPartsText, TemplatesText = Flags['DynamicParts'], Snippets['DynamicParts'], Snippets['StaticParts'], Snippets['Templates']
|
|
|
|
|
|
|
|
FileLower = File.lower()
|
2023-02-22 22:46:04 +01:00
|
|
|
PagePath = f'{OutDir}/{StripExt(File)}.html'
|
|
|
|
ContentPagePath = f'{OutDir}.Content/{StripExt(File)}.html'
|
2022-08-30 21:10:45 +02:00
|
|
|
LightRun = False if LimitFiles == False or File in LimitFiles else True
|
|
|
|
|
|
|
|
if FileLower.endswith(FileExtensions['Markdown']):
|
|
|
|
Content = markdown(PagePostprocessor('md', Content, Meta), extensions=MarkdownExts)
|
|
|
|
elif FileLower.endswith(('.pug')):
|
|
|
|
Content = PagePostprocessor('pug', ReadFile(PagePath), Meta)
|
|
|
|
elif FileLower.endswith(('.txt')):
|
|
|
|
Content = '<pre>' + html.escape(Content) + '</pre>'
|
2023-02-22 22:46:04 +01:00
|
|
|
#elif FileLower.endswith(FileExtensions['HTML']):
|
|
|
|
# Content = ReadFile(PagePath)
|
2022-08-30 21:10:45 +02:00
|
|
|
|
|
|
|
if LightRun:
|
|
|
|
HTMLPagesList = None
|
|
|
|
else:
|
|
|
|
TemplateMeta = TemplatePreprocessor(TemplatesText[Meta['Template']])
|
|
|
|
HTMLPagesList = GetHTMLPagesList(
|
|
|
|
Pages=Pages,
|
|
|
|
BlogName=BlogName,
|
|
|
|
SiteRoot=SiteRoot,
|
|
|
|
PathPrefix=GetPathLevels(File),
|
|
|
|
Unite=ConfMenu,
|
|
|
|
Type='Page',
|
|
|
|
For='Menu',
|
|
|
|
MarkdownExts=MarkdownExts,
|
|
|
|
MenuStyle=TemplateMeta['MenuStyle'])
|
2022-08-31 00:18:23 +02:00
|
|
|
|
2022-08-30 21:10:45 +02:00
|
|
|
HTML, ContentHTML, Description, Image = PatchHTML(
|
|
|
|
File=File,
|
|
|
|
HTML=TemplatesText[Meta['Template']],
|
|
|
|
StaticPartsText=StaticPartsText,
|
|
|
|
DynamicParts=DynamicParts,
|
|
|
|
DynamicPartsText=DynamicPartsText,
|
|
|
|
HTMLPagesList=HTMLPagesList,
|
|
|
|
PagePath=PagePath[len(f"{OutDir}/"):],
|
|
|
|
Content=Content,
|
|
|
|
Titles=Titles,
|
|
|
|
Meta=Meta,
|
2022-09-03 17:48:39 +02:00
|
|
|
SiteDomain=SiteDomain,
|
2022-08-30 21:10:45 +02:00
|
|
|
SiteRoot=SiteRoot,
|
|
|
|
SiteName=SiteName,
|
|
|
|
BlogName=BlogName,
|
|
|
|
FolderRoots=FolderRoots,
|
|
|
|
Categories=Categories,
|
|
|
|
SiteLang=SiteLang,
|
|
|
|
Locale=Locale,
|
|
|
|
LightRun=LightRun)
|
|
|
|
|
2022-10-26 11:01:17 +02:00
|
|
|
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,
|
2022-10-31 22:05:16 +01:00
|
|
|
MenuStyle='Flat',
|
|
|
|
ShowPaths=False))
|
2022-10-25 10:13:00 +02:00
|
|
|
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(
|
2022-10-25 12:04:17 +02:00
|
|
|
CallbackFile=File,
|
2022-10-25 10:13:00 +02:00
|
|
|
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)
|
|
|
|
|
2022-11-05 12:17:23 +01:00
|
|
|
if Flags['MinifyOutput']:
|
2022-08-30 21:10:45 +02:00
|
|
|
if not LightRun:
|
|
|
|
HTML = DoMinifyHTML(HTML, MinifyKeepComments)
|
|
|
|
ContentHTML = DoMinifyHTML(ContentHTML, MinifyKeepComments)
|
2022-11-17 13:03:17 +01:00
|
|
|
if Flags['NoScripts'] and ('<script' in ContentHTML.lower() or '<script' in HTML.lower()):
|
2022-08-30 21:10:45 +02:00
|
|
|
if not LightRun:
|
|
|
|
HTML = StripTags(HTML, ['script'])
|
|
|
|
ContentHTML = StripTags(ContentHTML, ['script'])
|
|
|
|
if ImgAltToTitle or ImgTitleToAlt:
|
|
|
|
if not LightRun:
|
|
|
|
HTML = WriteImgAltAndTitle(HTML, ImgAltToTitle, ImgTitleToAlt)
|
|
|
|
ContentHTML = WriteImgAltAndTitle(ContentHTML, ImgAltToTitle, ImgTitleToAlt)
|
2022-09-03 17:48:39 +02:00
|
|
|
if Flags['HTMLFixPre']:
|
|
|
|
if not LightRun:
|
|
|
|
HTML = DoHTMLFixPre(HTML)
|
|
|
|
ContentHTML = DoHTMLFixPre(ContentHTML)
|
2022-08-31 00:18:23 +02:00
|
|
|
|
2022-08-30 21:10:45 +02:00
|
|
|
if LightRun:
|
|
|
|
SlimHTML = None
|
|
|
|
else:
|
|
|
|
SlimHTML = HTMLPagesList + ContentHTML
|
|
|
|
if not LightRun:
|
|
|
|
WriteFile(PagePath, HTML)
|
2023-02-22 22:46:04 +01:00
|
|
|
WriteFile(ContentPagePath, ContentHTML)
|
2022-08-31 00:18:23 +02:00
|
|
|
|
2022-11-18 20:51:54 +01:00
|
|
|
if not LightRun and 'htmljournal' in ContentHTML.lower(): # Avoid extra cycles
|
|
|
|
HTML, _, _, _ = PatchHTML(
|
|
|
|
File=File,
|
|
|
|
HTML=TemplatesText[Meta['Template']],
|
|
|
|
StaticPartsText=StaticPartsText,
|
|
|
|
DynamicParts=DynamicParts,
|
|
|
|
DynamicPartsText=DynamicPartsText,
|
|
|
|
HTMLPagesList=HTMLPagesList,
|
|
|
|
PagePath=f'{StripExt(File)}.Journal.html',
|
|
|
|
Content=MakeHTMLJournal(Flags, Locale, f'{StripExt(File)}.html', ContentHTML),
|
|
|
|
Titles='',
|
|
|
|
Meta=Meta,
|
|
|
|
SiteDomain=SiteDomain,
|
|
|
|
SiteRoot=SiteRoot,
|
|
|
|
SiteName=SiteName,
|
|
|
|
BlogName=BlogName,
|
|
|
|
FolderRoots=FolderRoots,
|
|
|
|
Categories=Categories,
|
|
|
|
SiteLang=SiteLang,
|
|
|
|
Locale=Locale,
|
|
|
|
LightRun=LightRun)
|
|
|
|
if Flags["JournalRedirect"]:
|
|
|
|
HTML = HTML.replace('</head>', f"""<meta http-equiv="refresh" content="0; url='./{PagePath.split('''/''')[-1]}'"></head>""")
|
|
|
|
WriteFile(StripExt(PagePath)+'.Journal.html', HTML)
|
|
|
|
|
2022-08-30 21:10:45 +02:00
|
|
|
return [File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image]
|
|
|
|
|
2022-08-31 00:18:23 +02:00
|
|
|
def MultiprocPagePreprocessor(d):
|
2022-10-17 15:53:07 +02:00
|
|
|
PrintProcPercentDots(d['Process'], 2)
|
2022-08-31 00:18:23 +02:00
|
|
|
return PagePreprocessor(d['Path'], d['TempPath'], d['Type'], d['Template'], d['SiteRoot'], d['GlobalMacros'], d['CategoryUncategorized'], d['LightRun'])
|
2022-08-30 21:10:45 +02:00
|
|
|
|
2022-10-17 15:53:07 +02:00
|
|
|
def MultiprocHandlePage(d):
|
|
|
|
PrintProcPercentDots(d['Process'])
|
|
|
|
return HandlePage(d['Flags'], d['Page'], d['Pages'], d['Categories'], d['LimitFiles'], d['Snippets'], d['ConfMenu'], d['Locale'])
|
|
|
|
|
2022-09-03 17:48:39 +02:00
|
|
|
def MakeSite(Flags, LimitFiles, Snippets, ConfMenu, GlobalMacros, Locale, Threads):
|
2022-08-31 00:18:23 +02:00
|
|
|
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
2022-09-03 17:48:39 +02:00
|
|
|
PoolSize = cpu_count() if Threads <= 0 else Threads
|
2022-11-05 12:17:23 +01:00
|
|
|
OutDir, MarkdownExts, Sorting = Flags['OutDir'], Flags['MarkdownExts'], Flags['Sorting']
|
2022-08-30 21:10:45 +02:00
|
|
|
SiteName, BlogName, SiteTagline = Flags['SiteName'], Flags['BlogName'], Flags['SiteTagline']
|
|
|
|
SiteTemplate, SiteLang = Flags['SiteTemplate'], Flags['SiteLang']
|
|
|
|
SiteDomain, SiteRoot, FolderRoots = Flags['SiteDomain'], Flags['SiteRoot'], Flags['FolderRoots']
|
|
|
|
AutoCategories, CategoryUncategorized = Flags['CategoriesAutomatic'], Flags['CategoriesUncategorized']
|
|
|
|
ImgAltToTitle, ImgTitleToAlt = Flags['ImgAltToTitle'], Flags['ImgTitleToAlt']
|
|
|
|
DynamicParts, DynamicPartsText, StaticPartsText, TemplatesText = Flags['DynamicParts'], Snippets['DynamicParts'], Snippets['StaticParts'], Snippets['Templates']
|
2022-08-30 16:31:33 +02:00
|
|
|
|
2022-07-14 20:38:45 +02:00
|
|
|
for Ext in FileExtensions['Pages']:
|
2022-07-28 22:18:13 +02:00
|
|
|
for File in Path('Pages').rglob(f"*.{Ext}"):
|
2022-07-14 20:38:45 +02:00
|
|
|
PagesPaths += [FileToStr(File, 'Pages/')]
|
2022-07-28 22:18:13 +02:00
|
|
|
for File in Path('Posts').rglob(f"*.{Ext}"):
|
2022-07-14 20:38:45 +02:00
|
|
|
PostsPaths += [FileToStr(File, 'Posts/')]
|
2022-10-19 13:29:06 +02:00
|
|
|
logging.info(f"Pages Found: {len(PagesPaths+PostsPaths)}")
|
2022-07-14 20:38:45 +02:00
|
|
|
|
2022-08-27 16:50:50 +02:00
|
|
|
PagesPaths = FileNameDateSort(PagesPaths)
|
|
|
|
if Sorting['Pages'] == 'Inverse':
|
|
|
|
PagesPaths.reverse()
|
|
|
|
PostsPaths = FileNameDateSort(PostsPaths)
|
|
|
|
if Sorting['Posts'] == 'Inverse':
|
|
|
|
PostsPaths.reverse()
|
2022-07-14 20:38:45 +02:00
|
|
|
|
2022-09-03 17:48:39 +02:00
|
|
|
logging.info("Preprocessing Source Pages")
|
2022-08-31 00:18:23 +02:00
|
|
|
MultiprocPages = []
|
2022-07-14 20:38:45 +02:00
|
|
|
for Type in ['Page', 'Post']:
|
|
|
|
if Type == 'Page':
|
|
|
|
Files = PagesPaths
|
2022-08-28 00:32:45 +02:00
|
|
|
PathPrefix = ''
|
2022-07-14 20:38:45 +02:00
|
|
|
elif Type == 'Post':
|
|
|
|
Files = PostsPaths
|
2022-08-28 00:32:45 +02:00
|
|
|
PathPrefix = 'Posts/'
|
2022-10-17 15:53:07 +02:00
|
|
|
for i,File in enumerate(Files):
|
2022-08-28 00:32:45 +02:00
|
|
|
TempPath = f"{PathPrefix}{File}"
|
|
|
|
LightRun = False if LimitFiles == False or TempPath in LimitFiles else True
|
2022-10-17 15:53:07 +02:00
|
|
|
MultiprocPages += [{'Process':{'Num':i, 'Count':len(Files)}, 'Path':f"{Type}s/{File}", 'TempPath':TempPath, 'Type':Type, 'Template':SiteTemplate, 'SiteRoot':SiteRoot, 'GlobalMacros':GlobalMacros, 'CategoryUncategorized':CategoryUncategorized, 'LightRun':LightRun}]
|
|
|
|
os.system('printf "["')
|
2022-08-31 00:18:23 +02:00
|
|
|
with Pool(PoolSize) as MultiprocPool:
|
|
|
|
Pages = MultiprocPool.map(MultiprocPagePreprocessor, MultiprocPages)
|
2022-10-26 11:01:17 +02:00
|
|
|
os.system('printf "]\n"') # Make newline after percentage dots
|
2022-10-17 15:53:07 +02:00
|
|
|
|
2022-08-31 00:18:23 +02:00
|
|
|
for File, Content, Titles, Meta in Pages:
|
|
|
|
for Cat in Meta['Categories']:
|
|
|
|
Categories.update({Cat:''})
|
2022-08-30 21:10:45 +02:00
|
|
|
PugCompileList(OutDir, Pages, LimitFiles)
|
2022-07-14 20:38:45 +02:00
|
|
|
|
|
|
|
if Categories:
|
2022-09-03 17:48:39 +02:00
|
|
|
logging.info("Generating Category Lists")
|
2022-07-14 20:38:45 +02:00
|
|
|
for Cat in Categories:
|
|
|
|
for Type in ('Page', 'Post'):
|
|
|
|
Categories[Cat] += GetHTMLPagesList(
|
|
|
|
Pages=Pages,
|
|
|
|
BlogName=BlogName,
|
|
|
|
SiteRoot=SiteRoot,
|
|
|
|
PathPrefix=GetPathLevels('Categories/'),
|
|
|
|
Type=Type,
|
|
|
|
Category=Cat,
|
2022-07-15 16:48:18 +02:00
|
|
|
For='Categories',
|
2022-07-25 17:06:16 +02:00
|
|
|
MarkdownExts=MarkdownExts,
|
2022-08-13 13:14:48 +02:00
|
|
|
MenuStyle='Flat')
|
2022-07-14 20:38:45 +02:00
|
|
|
|
|
|
|
if AutoCategories:
|
2022-08-30 21:10:45 +02:00
|
|
|
Dir = f"{OutDir}/Categories"
|
2022-07-14 20:38:45 +02:00
|
|
|
for Cat in Categories:
|
|
|
|
Exists = False
|
|
|
|
for File in Path(Dir).rglob(str(Cat)+'.*'):
|
|
|
|
Exists = True
|
|
|
|
break
|
|
|
|
if not Exists:
|
2022-07-28 22:18:13 +02:00
|
|
|
File = f"Categories/{Cat}.md"
|
2022-08-30 21:10:45 +02:00
|
|
|
FilePath = f"{OutDir}/{File}"
|
2022-10-17 15:53:07 +02:00
|
|
|
WriteFile(FilePath, CategoryPageTemplate.format(Name=Cat))
|
2023-02-22 22:46:04 +01:00
|
|
|
_, Content, Titles, Meta = PagePreprocessor(FilePath, FilePath, Type, SiteTemplate, SiteRoot, GlobalMacros, CategoryUncategorized, LightRun=LightRun)
|
2022-07-14 20:38:45 +02:00
|
|
|
Pages += [[File, Content, Titles, Meta]]
|
|
|
|
|
2023-02-22 22:46:04 +01:00
|
|
|
#logging.info("Building the HTML Search Page")
|
|
|
|
#Pages += [PagePreprocessor(Path='Search.html', TempPath='Search.html', Type='Page', SiteTemplate=SiteTemplate, SiteRoot=SiteRoot, GlobalMacros=GlobalMacros, CategoryUncategorized=CategoryUncategorized, LightRun=LightRun, Content=BuildPagesSearch(Flags, Pages))]
|
|
|
|
|
2022-07-15 00:12:58 +02:00
|
|
|
for i,e in enumerate(ConfMenu):
|
|
|
|
for File, Content, Titles, Meta in Pages:
|
|
|
|
File = StripExt(File)+'.html'
|
|
|
|
if e == File:
|
|
|
|
ConfMenu[i] = None
|
|
|
|
|
2022-09-03 17:48:39 +02:00
|
|
|
logging.info("Writing Pages")
|
2022-08-31 00:18:23 +02:00
|
|
|
MultiprocPages = []
|
2022-10-17 15:53:07 +02:00
|
|
|
for i,Page in enumerate(Pages):
|
|
|
|
MultiprocPages += [{'Process':{'Num':i, 'Count':len(Pages)}, 'Flags':Flags, 'Page':Page, 'Pages':Pages, 'Categories':Categories, 'LimitFiles':LimitFiles, 'Snippets':Snippets, 'ConfMenu':ConfMenu, 'Locale':Locale}]
|
|
|
|
os.system('printf "["')
|
2022-08-31 00:18:23 +02:00
|
|
|
with Pool(PoolSize) as MultiprocPool:
|
|
|
|
MadePages = MultiprocPool.map(MultiprocHandlePage, MultiprocPages)
|
2022-10-26 11:01:17 +02:00
|
|
|
os.system('printf "]\n"') # Make newline after percentage dots
|
2022-07-14 20:38:45 +02:00
|
|
|
|
2022-12-15 16:29:22 +01:00
|
|
|
# Do page transclusions here (?)
|
|
|
|
#while True:
|
|
|
|
# Operated = False
|
|
|
|
# for di,Dest in enumerate(MadePages):
|
|
|
|
# #print(Dest[0])
|
|
|
|
# #TempPath = f'{PathPrefix}{Dest["File"]}'
|
|
|
|
# #LightRun = False if LimitFiles == False or TempPath in LimitFiles else True
|
|
|
|
# #if not LightRun:
|
|
|
|
# if '[staticoso:Transclude:' in Dest[4] and (LimitFiles == False or f'{PathPrefix}{Dest[0]}' in LimitFiles):
|
|
|
|
# for Item in MadePages:
|
|
|
|
# SrcPrefix = '' if Item[0].startswith('Posts/') else 'Pages/'
|
|
|
|
# print(SrcPrefix, Item[0])
|
|
|
|
# if Item[0] != Dest[0] and f'[staticoso:Transclude:{SrcPrefix}{Item[0]}]' in Dest[4]:
|
|
|
|
# MadePages[di][4] = ReplWithEsc(Dest[4], f'<staticoso:Transclude:{Item[0]}>', Item[4])
|
|
|
|
# print(f'[staticoso:Transclude:{SrcPrefix}{Item[0]}]', Item[4])
|
|
|
|
# Operated = True
|
|
|
|
# if not Operated:
|
|
|
|
# break
|
|
|
|
|
2022-07-14 20:38:45 +02:00
|
|
|
return MadePages
|