mirror of https://gitlab.com/octtspacc/staticoso
Misc fixes, Add progress bars, Add redirects
This commit is contained in:
parent
052c1d130a
commit
8ffad6c99c
|
@ -4,5 +4,7 @@
|
||||||
"Categories": "Categories",
|
"Categories": "Categories",
|
||||||
"ReadFullPost": "Read the full post",
|
"ReadFullPost": "Read the full post",
|
||||||
"Comments": "Comments",
|
"Comments": "Comments",
|
||||||
"OpenInNewTab": "Open in a new tab"
|
"OpenInNewTab": "Open in a new tab",
|
||||||
|
"ClickHere": "Click here",
|
||||||
|
"IfNotRedirected": "if you aren't automatically redirected"
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,7 @@
|
||||||
"Categories": "Categorie",
|
"Categories": "Categorie",
|
||||||
"ReadFullPost": "Leggi il post intero",
|
"ReadFullPost": "Leggi il post intero",
|
||||||
"Comments": "Commenti",
|
"Comments": "Commenti",
|
||||||
"OpenInNewTab": "Apri in una nuova scheda"
|
"OpenInNewTab": "Apri in una nuova scheda",
|
||||||
|
"ClickHere": "Clicca qui",
|
||||||
|
"IfNotRedirected": "se non subisci il reindirizzamento automatico"
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,10 +104,12 @@ def GetModifiedFiles(OutDir):
|
||||||
return Mod
|
return Mod
|
||||||
|
|
||||||
def Main(Args, FeedEntries):
|
def Main(Args, FeedEntries):
|
||||||
Flags, Snippets = {}, {}
|
Flags, Snippets, FinalPaths = {}, {}, []
|
||||||
HavePages, HavePosts = False, False
|
HavePages, HavePosts = False, False
|
||||||
SiteConf = LoadConfFile('Site.ini')
|
SiteConf = LoadConfFile('Site.ini')
|
||||||
|
|
||||||
|
ConfigLogging(OptionChoose(None, Args.Logging, ReadConf(SiteConf, 'Main', 'Logging')))
|
||||||
|
|
||||||
#if Args.InputDir:
|
#if Args.InputDir:
|
||||||
# os.chdir(Args.InputDir)
|
# os.chdir(Args.InputDir)
|
||||||
# print(f"[I] Current directory: {Args.InputDir}")
|
# print(f"[I] Current directory: {Args.InputDir}")
|
||||||
|
@ -228,13 +230,29 @@ def Main(Args, FeedEntries):
|
||||||
Post = ''
|
Post = ''
|
||||||
for p in MastodonPosts:
|
for p in MastodonPosts:
|
||||||
if p['Link'] == SiteDomain + '/' + File[len(f"{OutDir}/"):]:
|
if p['Link'] == SiteDomain + '/' + File[len(f"{OutDir}/"):]:
|
||||||
Post = '<br><h3>{StrComments}</h3><a href="{URL}" rel="noopener" target="_blank">{StrOpen} ↗️</a>'.format(
|
Post = HTMLCommentsBlock.format(
|
||||||
StrComments=Locale['Comments'],
|
StrComments=Locale['Comments'],
|
||||||
StrOpen=Locale['OpenInNewTab'],
|
StrOpen=Locale['OpenInNewTab'],
|
||||||
URL=p['Post'])
|
URL=p['Post'])
|
||||||
break
|
break
|
||||||
Content = ReplWithEsc(Content, '[staticoso:Comments]', Post)
|
Content = ReplWithEsc(Content, '[staticoso:Comments]', Post)
|
||||||
|
Content = ReplWithEsc(Content, '<staticoso:Comments>', Post)
|
||||||
WriteFile(File, Content)
|
WriteFile(File, Content)
|
||||||
|
FinalPaths += [File]
|
||||||
|
|
||||||
|
logging.info("Creating Redirects")
|
||||||
|
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
||||||
|
for URL in Meta['URLs']:
|
||||||
|
DestFile = f"{OutDir}/{URL}"
|
||||||
|
if DestFile not in FinalPaths:
|
||||||
|
DestURL = f"{GetPathLevels(URL)}{StripExt(File)}.html"
|
||||||
|
WriteFile(
|
||||||
|
DestFile,
|
||||||
|
RedirectPageTemplate.format(
|
||||||
|
DestURL=DestURL,
|
||||||
|
TitlePrefix=f"{SiteName} - " if SiteName else '',
|
||||||
|
StrClick=Locale["ClickHere"],
|
||||||
|
StrRedirect=Locale["IfNotRedirected"]))
|
||||||
|
|
||||||
if Flags['GemtextOutput']:
|
if Flags['GemtextOutput']:
|
||||||
logging.info("Generating Gemtext")
|
logging.info("Generating Gemtext")
|
||||||
|
|
|
@ -19,8 +19,21 @@ CategoryPageTemplate = """\
|
||||||
|
|
||||||
# {Name}
|
# {Name}
|
||||||
|
|
||||||
<div>[staticoso:Category:{Name}]</div>
|
<div><staticoso:Category:{Name}></div>
|
||||||
"""
|
"""
|
||||||
|
RedirectPageTemplate = """\
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>{TitlePrefix}Redirect</title>
|
||||||
|
<meta http-equiv="refresh" content="0; url='{DestURL}'" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p><a href="{DestURL}">{StrClick}</a> {StrRedirect}.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
HTMLCommentsBlock = '<br><h3>{StrComments}</h3><a href="{URL}" rel="noopener" target="_blank">{StrOpen} ↗️</a>'
|
||||||
|
|
||||||
def DashifyTitle(Title, Done=[]):
|
def DashifyTitle(Title, Done=[]):
|
||||||
return UndupeStr(DashifyStr(Title.lstrip(' ').rstrip(' ')), Done, '-')
|
return UndupeStr(DashifyStr(Title.lstrip(' ').rstrip(' ')), Done, '-')
|
||||||
|
|
|
@ -107,7 +107,9 @@ def PagePreprocessor(Path, TempPath, Type, SiteTemplate, SiteRoot, GlobalMacros,
|
||||||
'Image': '',
|
'Image': '',
|
||||||
'Macros': {},
|
'Macros': {},
|
||||||
'Categories': [],
|
'Categories': [],
|
||||||
|
'URLs': [],
|
||||||
'CreatedOn': '',
|
'CreatedOn': '',
|
||||||
|
'UpdatedOn': '',
|
||||||
'EditedOn': '',
|
'EditedOn': '',
|
||||||
'Order': None}
|
'Order': None}
|
||||||
# Find all positions of '<!--', '-->', add them in a list=[[pos0,pos1,line0,line1],...]
|
# Find all positions of '<!--', '-->', add them in a list=[[pos0,pos1,line0,line1],...]
|
||||||
|
@ -182,13 +184,21 @@ def PagePreprocessor(Path, TempPath, Type, SiteTemplate, SiteRoot, GlobalMacros,
|
||||||
Meta = dict(ReadConf(LoadConfStr('[Meta]\n' + Meta), 'Meta'))
|
Meta = dict(ReadConf(LoadConfStr('[Meta]\n' + Meta), 'Meta'))
|
||||||
for i in MetaDefault:
|
for i in MetaDefault:
|
||||||
if i in Meta:
|
if i in Meta:
|
||||||
|
# TODO: Handle strings with spaces but wrapped in quotes
|
||||||
if i == 'Categories':
|
if i == 'Categories':
|
||||||
Categories = Meta['Categories'].split(' ')
|
Categories = Meta['Categories'].split(' ')
|
||||||
Meta['Categories'] = []
|
Meta['Categories'] = []
|
||||||
for j in Categories:
|
for j in Categories:
|
||||||
Meta['Categories'] += [j]
|
Meta['Categories'] += [j]
|
||||||
|
elif i == 'URLs':
|
||||||
|
URLs = Meta['URLs'].split(' ')
|
||||||
|
Meta['URLs'] = []
|
||||||
|
for j in URLs:
|
||||||
|
Meta['URLs'] += [j]
|
||||||
else:
|
else:
|
||||||
Meta.update({i:MetaDefault[i]})
|
Meta.update({i:MetaDefault[i]})
|
||||||
|
if Meta['UpdatedOn']:
|
||||||
|
Meta['EditedOn'] = Meta['UpdatedOn']
|
||||||
if Meta['Index'] in ('Default', 'Unspecified', 'Categories'):
|
if Meta['Index'] in ('Default', 'Unspecified', 'Categories'):
|
||||||
if not Meta['Categories']:
|
if not Meta['Categories']:
|
||||||
Meta['Categories'] = [CategoryUncategorized]
|
Meta['Categories'] = [CategoryUncategorized]
|
||||||
|
@ -199,7 +209,6 @@ def PagePreprocessor(Path, TempPath, Type, SiteTemplate, SiteRoot, GlobalMacros,
|
||||||
if GlobalMacros:
|
if GlobalMacros:
|
||||||
Meta['Macros'].update(GlobalMacros)
|
Meta['Macros'].update(GlobalMacros)
|
||||||
Meta['Macros'].update(ReadConf(LoadConfStr('[Macros]\n' + Macros), 'Macros'))
|
Meta['Macros'].update(ReadConf(LoadConfStr('[Macros]\n' + Macros), 'Macros'))
|
||||||
#PrintPercentDots(ProcPercent)
|
|
||||||
return [TempPath, Content, Titles, Meta]
|
return [TempPath, Content, Titles, Meta]
|
||||||
|
|
||||||
def PagePostprocessor(FileType, Text, Meta):
|
def PagePostprocessor(FileType, Text, Meta):
|
||||||
|
@ -434,15 +443,16 @@ def HandlePage(Flags, Page, Pages, Categories, LimitFiles, Snippets, ConfMenu, L
|
||||||
if not LightRun:
|
if not LightRun:
|
||||||
WriteFile(PagePath, HTML)
|
WriteFile(PagePath, HTML)
|
||||||
|
|
||||||
#PrintPercentDots(ProcPercent)
|
|
||||||
return [File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image]
|
return [File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image]
|
||||||
|
|
||||||
def MultiprocHandlePage(d):
|
|
||||||
return HandlePage(d['Flags'], d['Page'], d['Pages'], d['Categories'], d['LimitFiles'], d['Snippets'], d['ConfMenu'], d['Locale'])
|
|
||||||
|
|
||||||
def MultiprocPagePreprocessor(d):
|
def MultiprocPagePreprocessor(d):
|
||||||
|
PrintProcPercentDots(d['Process'], 2)
|
||||||
return PagePreprocessor(d['Path'], d['TempPath'], d['Type'], d['Template'], d['SiteRoot'], d['GlobalMacros'], d['CategoryUncategorized'], d['LightRun'])
|
return PagePreprocessor(d['Path'], d['TempPath'], d['Type'], d['Template'], d['SiteRoot'], d['GlobalMacros'], d['CategoryUncategorized'], d['LightRun'])
|
||||||
|
|
||||||
|
def MultiprocHandlePage(d):
|
||||||
|
PrintProcPercentDots(d['Process'])
|
||||||
|
return HandlePage(d['Flags'], d['Page'], d['Pages'], d['Categories'], d['LimitFiles'], d['Snippets'], d['ConfMenu'], d['Locale'])
|
||||||
|
|
||||||
def MakeSite(Flags, LimitFiles, Snippets, ConfMenu, GlobalMacros, Locale, Threads):
|
def MakeSite(Flags, LimitFiles, Snippets, ConfMenu, GlobalMacros, Locale, Threads):
|
||||||
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
||||||
PoolSize = cpu_count() if Threads <= 0 else Threads
|
PoolSize = cpu_count() if Threads <= 0 else Threads
|
||||||
|
@ -476,13 +486,15 @@ def MakeSite(Flags, LimitFiles, Snippets, ConfMenu, GlobalMacros, Locale, Thread
|
||||||
elif Type == 'Post':
|
elif Type == 'Post':
|
||||||
Files = PostsPaths
|
Files = PostsPaths
|
||||||
PathPrefix = 'Posts/'
|
PathPrefix = 'Posts/'
|
||||||
for File in Files:
|
for i,File in enumerate(Files):
|
||||||
TempPath = f"{PathPrefix}{File}"
|
TempPath = f"{PathPrefix}{File}"
|
||||||
LightRun = False if LimitFiles == False or TempPath in LimitFiles else True
|
LightRun = False if LimitFiles == False or TempPath in LimitFiles else True
|
||||||
MultiprocPages += [{'Path':f"{Type}s/{File}", 'TempPath':TempPath, 'Type':Type, 'Template':SiteTemplate, 'SiteRoot':SiteRoot, 'GlobalMacros':GlobalMacros, 'CategoryUncategorized':CategoryUncategorized, 'LightRun':LightRun}]
|
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 "["')
|
||||||
with Pool(PoolSize) as MultiprocPool:
|
with Pool(PoolSize) as MultiprocPool:
|
||||||
Pages = MultiprocPool.map(MultiprocPagePreprocessor, MultiprocPages)
|
Pages = MultiprocPool.map(MultiprocPagePreprocessor, MultiprocPages)
|
||||||
#print() # Make newline after percentage dots
|
os.system('printf "]\n"') #print("]") # Make newline after percentage dots
|
||||||
|
|
||||||
for File, Content, Titles, Meta in Pages:
|
for File, Content, Titles, Meta in Pages:
|
||||||
for Cat in Meta['Categories']:
|
for Cat in Meta['Categories']:
|
||||||
Categories.update({Cat:''})
|
Categories.update({Cat:''})
|
||||||
|
@ -513,8 +525,8 @@ def MakeSite(Flags, LimitFiles, Snippets, ConfMenu, GlobalMacros, Locale, Thread
|
||||||
if not Exists:
|
if not Exists:
|
||||||
File = f"Categories/{Cat}.md"
|
File = f"Categories/{Cat}.md"
|
||||||
FilePath = f"{OutDir}/{File}"
|
FilePath = f"{OutDir}/{File}"
|
||||||
WriteFile(FilePath, CategoryPageTemplate.format(Title=Cat))
|
WriteFile(FilePath, CategoryPageTemplate.format(Name=Cat))
|
||||||
Content, Titles, Meta = PagePreprocessor(FilePath, 'Page', SiteTemplate, SiteRoot, GlobalMacros, CategoryUncategorized, LightRun=LightRun)
|
_, Content, Titles, Meta = PagePreprocessor(FilePath, FilePath, Type, SiteTemplate, SiteRoot, GlobalMacros, CategoryUncategorized, LightRun=LightRun)
|
||||||
Pages += [[File, Content, Titles, Meta]]
|
Pages += [[File, Content, Titles, Meta]]
|
||||||
|
|
||||||
for i,e in enumerate(ConfMenu):
|
for i,e in enumerate(ConfMenu):
|
||||||
|
@ -525,10 +537,11 @@ def MakeSite(Flags, LimitFiles, Snippets, ConfMenu, GlobalMacros, Locale, Thread
|
||||||
|
|
||||||
logging.info("Writing Pages")
|
logging.info("Writing Pages")
|
||||||
MultiprocPages = []
|
MultiprocPages = []
|
||||||
for Page in Pages:
|
for i,Page in enumerate(Pages):
|
||||||
MultiprocPages += [{'Flags':Flags, 'Page':Page, 'Pages':Pages, 'Categories':Categories, 'LimitFiles':LimitFiles, 'Snippets':Snippets, 'ConfMenu':ConfMenu, 'Locale':Locale}]
|
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 "["')
|
||||||
with Pool(PoolSize) as MultiprocPool:
|
with Pool(PoolSize) as MultiprocPool:
|
||||||
MadePages = MultiprocPool.map(MultiprocHandlePage, MultiprocPages)
|
MadePages = MultiprocPool.map(MultiprocHandlePage, MultiprocPages)
|
||||||
#print() # Make newline after percentage dots
|
os.system('printf "]\n"') #print("]") # Make newline after percentage dots
|
||||||
|
|
||||||
return MadePages
|
return MadePages
|
||||||
|
|
|
@ -158,10 +158,8 @@ def LoadLocale(Lang):
|
||||||
def IsLightRun(File, LimitFiles):
|
def IsLightRun(File, LimitFiles):
|
||||||
return False if LimitFiles == False or File in LimitFiles else True
|
return False if LimitFiles == False or File in LimitFiles else True
|
||||||
|
|
||||||
def PrintPercentDots(Percent):
|
def PrintProcPercentDots(Proc, DivMult=1):
|
||||||
Cur, Tot = Percent
|
Div = 5 * DivMult # 100/5 = 20 chars
|
||||||
CalcCur = int((Cur/Tot)*100)
|
Num, Count = Proc['Num'], Proc['Count']
|
||||||
if CalcCur % 10 == 0:
|
if int(((Num/Count)*100)/Div) != int((((Num+1)/Count)*100)/Div):
|
||||||
CalcPrev = int((Cur-1/Tot)*100)
|
os.system('printf "="') # For some reason print() without newline breaks here (doesn't print everytime)
|
||||||
if CalcPrev % 10 != 0:
|
|
||||||
print('.', end='')
|
|
||||||
|
|
Loading…
Reference in New Issue