mirror of https://gitlab.com/octtspacc/staticoso
Safe custom output directory; Some conf. flags fixes
This commit is contained in:
parent
342b2e8163
commit
7b15de12cb
|
@ -68,12 +68,24 @@ def GetConfMenu(Entries, MarkdownExts):
|
||||||
Menu[int(i)] = e
|
Menu[int(i)] = e
|
||||||
return Menu
|
return Menu
|
||||||
|
|
||||||
|
def CheckSafeOutputDir(OutDir):
|
||||||
|
InDir = os.path.realpath(os.getcwd())
|
||||||
|
OutDir = os.path.realpath(OutDir)
|
||||||
|
OutFolder = OutDir.split('/')[-1]
|
||||||
|
if InDir == OutDir:
|
||||||
|
print(f"[E] Output and Input directories ({OutDir}) can't be the same. Exiting.")
|
||||||
|
exit(1)
|
||||||
|
elif OutFolder in ReservedPaths and f"{InDir}/{OutFolder}" == OutDir:
|
||||||
|
print(f"[E] Output directory {OutDir} can't be a reserved subdirectory of the Input. Exiting.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
def Main(Args, FeedEntries):
|
def Main(Args, FeedEntries):
|
||||||
HavePages, HavePosts = False, False
|
HavePages, HavePosts = False, False
|
||||||
SiteConf = LoadConfFile('Site.ini')
|
SiteConf = LoadConfFile('Site.ini')
|
||||||
|
|
||||||
OutputDir = Args.OutputDir if Args.OutputDir else ReadConf(SiteConf, 'Site', 'OutputDir') if ReadConf(SiteConf, 'Site', 'OutputDir') else 'public'
|
OutputDir = Args.OutputDir if Args.OutputDir else ReadConf(SiteConf, 'Site', 'OutputDir') if ReadConf(SiteConf, 'Site', 'OutputDir') else 'public'
|
||||||
OutputDir = OutputDir.removesuffix('/')
|
OutputDir = OutputDir.removesuffix('/')
|
||||||
|
CheckSafeOutputDir(OutputDir)
|
||||||
print(f"[I] Outputting to {OutputDir}/")
|
print(f"[I] Outputting to {OutputDir}/")
|
||||||
|
|
||||||
SiteName = Args.SiteName if Args.SiteName else ReadConf(SiteConf, 'Site', 'Name') if ReadConf(SiteConf, 'Site', 'Name') else ''
|
SiteName = Args.SiteName if Args.SiteName else ReadConf(SiteConf, 'Site', 'Name') if ReadConf(SiteConf, 'Site', 'Name') else ''
|
||||||
|
@ -89,12 +101,14 @@ def Main(Args, FeedEntries):
|
||||||
DynamicParts = literal_eval(Args.DynamicParts) if Args.DynamicParts else EvalOpt(ReadConf(SiteConf, 'Site', 'DynamicParts')) if ReadConf(SiteConf, 'Site', 'DynamicParts') else {}
|
DynamicParts = literal_eval(Args.DynamicParts) if Args.DynamicParts else EvalOpt(ReadConf(SiteConf, 'Site', 'DynamicParts')) if ReadConf(SiteConf, 'Site', 'DynamicParts') else {}
|
||||||
MarkdownExts = literal_eval(Args.MarkdownExts) if Args.MarkdownExts else EvalOpt(ReadConf(SiteConf, 'Markdown', 'Exts')) if ReadConf(SiteConf, 'Markdown', 'Exts') else MarkdownExtsDefault
|
MarkdownExts = literal_eval(Args.MarkdownExts) if Args.MarkdownExts else EvalOpt(ReadConf(SiteConf, 'Markdown', 'Exts')) if ReadConf(SiteConf, 'Markdown', 'Exts') else MarkdownExtsDefault
|
||||||
ActivityPubTypeFilter = Args.ActivityPubTypeFilter if Args.ActivityPubTypeFilter else ReadConf(SiteConf, 'ActivityPub', 'TypeFilter') if ReadConf(SiteConf, 'ActivityPub', 'TypeFilter') else 'Post'
|
ActivityPubTypeFilter = Args.ActivityPubTypeFilter if Args.ActivityPubTypeFilter else ReadConf(SiteConf, 'ActivityPub', 'TypeFilter') if ReadConf(SiteConf, 'ActivityPub', 'TypeFilter') else 'Post'
|
||||||
FeedCategoryFilter = Args.FeedCategoryFilter if Args.FeedCategoryFilter else 'Blog'
|
ActivityPubHoursLimit = OptionChoose(168, Args.ActivityPubHoursLimit, ReadConf(SiteConf, 'ActivityPub', 'HoursLimit'))
|
||||||
|
FeedCategoryFilter = OptionChoose('Blog', Args.FeedCategoryFilter, ReadConf(SiteConf, 'Feed', 'CategoryFilter'))
|
||||||
Minify = StringBoolChoose(False, Args.Minify, ReadConf(SiteConf, 'Site', 'Minify'))
|
Minify = StringBoolChoose(False, Args.Minify, ReadConf(SiteConf, 'Site', 'Minify'))
|
||||||
NoScripts = StringBoolChoose(False, Args.NoScripts, ReadConf(SiteConf, 'Site', 'NoScripts'))
|
NoScripts = StringBoolChoose(False, Args.NoScripts, ReadConf(SiteConf, 'Site', 'NoScripts'))
|
||||||
ImgAltAndTitle = StringBoolChoose(True, Args.ImgAltAndTitle, ReadConf(SiteConf, 'Site', 'ImgAltAndTitle'))
|
ImgAltAndTitle = StringBoolChoose(True, Args.ImgAltAndTitle, ReadConf(SiteConf, 'Site', 'ImgAltAndTitle'))
|
||||||
AutoCategories = StringBoolChoose(False, Args.AutoCategories, ReadConf(SiteConf, 'Site', 'AutoCategories'))
|
AutoCategories = StringBoolChoose(False, Args.AutoCategories, ReadConf(SiteConf, 'Site', 'AutoCategories'))
|
||||||
GemtextOut = StringBoolChoose(False, Args.GemtextOut, ReadConf(SiteConf, 'Site', 'GemtextOut'))
|
GemtextOut = StringBoolChoose(False, Args.GemtextOut, ReadConf(SiteConf, 'Site', 'GemtextOut'))
|
||||||
|
GemtextHeader = Args.GemtextHeader if Args.GemtextHeader else ReadConf(SiteConf, 'Gemtext', 'Header') if ReadConf(SiteConf, 'Gemtext', 'Header') else f"# {SiteName}\n\n" if SiteName else ''
|
||||||
SitemapOut = StringBoolChoose(True, Args.SitemapOut, ReadConf(SiteConf, 'Site', 'SitemapOut'))
|
SitemapOut = StringBoolChoose(True, Args.SitemapOut, ReadConf(SiteConf, 'Site', 'SitemapOut'))
|
||||||
FeedEntries = int(FeedEntries) if (FeedEntries or FeedEntries == 0) and FeedEntries != 'Default' else int(ReadConf(SiteConf, 'Site', 'FeedEntries')) if ReadConf(SiteConf, 'Site', 'FeedEntries') else 10
|
FeedEntries = int(FeedEntries) if (FeedEntries or FeedEntries == 0) and FeedEntries != 'Default' else int(ReadConf(SiteConf, 'Site', 'FeedEntries')) if ReadConf(SiteConf, 'Site', 'FeedEntries') else 10
|
||||||
Sorting = literal_eval(Args.Sorting) if Args.Sorting else EvalOpt(ReadConf(SiteConf, 'Site', 'Sorting')) if ReadConf(SiteConf, 'Site', 'Sorting') else {}
|
Sorting = literal_eval(Args.Sorting) if Args.Sorting else EvalOpt(ReadConf(SiteConf, 'Site', 'Sorting')) if ReadConf(SiteConf, 'Site', 'Sorting') else {}
|
||||||
|
@ -177,7 +191,7 @@ def Main(Args, FeedEntries):
|
||||||
Locale=Locale,
|
Locale=Locale,
|
||||||
TypeFilter=ActivityPubTypeFilter,
|
TypeFilter=ActivityPubTypeFilter,
|
||||||
CategoryFilter=FeedCategoryFilter,
|
CategoryFilter=FeedCategoryFilter,
|
||||||
HoursLimit=Args.ActivityPubHoursLimit if Args.ActivityPubHoursLimit else 168)
|
HoursLimit=ActivityPubHoursLimit)
|
||||||
else:
|
else:
|
||||||
MastodonPosts = []
|
MastodonPosts = []
|
||||||
|
|
||||||
|
@ -192,15 +206,12 @@ def Main(Args, FeedEntries):
|
||||||
StrOpen=Locale['OpenInNewTab'],
|
StrOpen=Locale['OpenInNewTab'],
|
||||||
URL=p['Post'])
|
URL=p['Post'])
|
||||||
break
|
break
|
||||||
Content = Content.replace('[staticoso:Comments]', Post)
|
Content = ReplWithEsc(Content, '[staticoso:Comments]', Post)
|
||||||
WriteFile(File, Content)
|
WriteFile(File, Content)
|
||||||
|
|
||||||
if GemtextOut:
|
if GemtextOut:
|
||||||
print("[I] Generating Gemtext")
|
print("[I] Generating Gemtext")
|
||||||
GemtextCompileList(
|
GemtextCompileList(OutputDir, Pages, GemtextHeader)
|
||||||
OutputDir,
|
|
||||||
Pages,
|
|
||||||
Header=Args.GemtextHeader if Args.GemtextHeader else f"# {SiteName}\n\n" if SiteName else '')
|
|
||||||
|
|
||||||
print("[I] Cleaning Temporary Files")
|
print("[I] Cleaning Temporary Files")
|
||||||
DelTmp(OutputDir)
|
DelTmp(OutputDir)
|
||||||
|
@ -244,7 +255,7 @@ if __name__ == '__main__':
|
||||||
from Modules.Feed import *
|
from Modules.Feed import *
|
||||||
FeedEntries = Args.FeedEntries if Args.FeedEntries else 'Default'
|
FeedEntries = Args.FeedEntries if Args.FeedEntries else 'Default'
|
||||||
except:
|
except:
|
||||||
print("[E] Can't load the XML libraries. XML Feeds Generation is Disabled. Make sure the 'lxml' library is installed.")
|
print("[W] Can't load the XML libraries. XML Feeds Generation is Disabled. Make sure the 'lxml' library is installed.")
|
||||||
FeedEntries = 0
|
FeedEntries = 0
|
||||||
|
|
||||||
Main(
|
Main(
|
||||||
|
|
|
@ -38,12 +38,12 @@ def EvalOpt(Opt):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def OptionChoose(Default, Primary, Secondary):
|
||||||
|
return Primary if Primary != None else Secondary if Secondary != None else Default
|
||||||
|
|
||||||
def StringBoolChoose(Default, Primary, Secondary):
|
def StringBoolChoose(Default, Primary, Secondary):
|
||||||
Var = Default
|
Var = Default
|
||||||
if Primary != None:
|
Check = Primary if Primary != None else Secondary
|
||||||
Check = Primary
|
|
||||||
else:
|
|
||||||
Check = Secondary
|
|
||||||
if type(Check) == bool:
|
if type(Check) == bool:
|
||||||
Var = Check
|
Var = Check
|
||||||
elif type(Check) == str:
|
elif type(Check) == str:
|
||||||
|
|
|
@ -12,6 +12,7 @@ import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
ReservedPaths = ('Site.ini', 'Assets', 'Pages', 'Posts', 'Templates', 'StaticParts', 'DynamicParts')
|
||||||
FileExtensions = {
|
FileExtensions = {
|
||||||
'Pages': ('htm', 'html', 'markdown', 'md', 'pug', 'txt'),
|
'Pages': ('htm', 'html', 'markdown', 'md', 'pug', 'txt'),
|
||||||
'HTML': ('.htm', '.html'),
|
'HTML': ('.htm', '.html'),
|
||||||
|
|
Loading…
Reference in New Issue