mirror of https://gitlab.com/octtspacc/staticoso
Some site settings in INI file
This commit is contained in:
parent
bf438c75f3
commit
d5d4ba3f2a
|
@ -31,6 +31,7 @@ except:
|
||||||
print("[E] Can't load the ActivityPub module. Its use is disabled. Make sure the 'requests' library is installed.")
|
print("[E] Can't load the ActivityPub module. Its use is disabled. Make sure the 'requests' library is installed.")
|
||||||
ActivityPub = False
|
ActivityPub = False
|
||||||
|
|
||||||
|
from Modules.Config import *
|
||||||
from Modules.Gemini import *
|
from Modules.Gemini import *
|
||||||
from Modules.Pug import *
|
from Modules.Pug import *
|
||||||
from Modules.Utils import *
|
from Modules.Utils import *
|
||||||
|
@ -221,8 +222,8 @@ def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesLi
|
||||||
HTML = HTML.replace('[HTML:ContextPart:{}]'.format(Path), Text)
|
HTML = HTML.replace('[HTML:ContextPart:{}]'.format(Path), Text)
|
||||||
for i in PartsText:
|
for i in PartsText:
|
||||||
HTML = HTML.replace('[HTML:Part:{}]'.format(i), PartsText[i])
|
HTML = HTML.replace('[HTML:Part:{}]'.format(i), PartsText[i])
|
||||||
HTML = HTML.replace('[HTML:Page:LeftBox]', HTMLPagesList)
|
HTML = HTML.replace('[HTML:Site:Menu]', HTMLPagesList)
|
||||||
HTML = HTML.replace('[HTML:Page:RightBox]', HTMLTitles)
|
HTML = HTML.replace('[HTML:Page:Chapters]', HTMLTitles)
|
||||||
HTML = HTML.replace('[HTML:Page:Title]', Title)
|
HTML = HTML.replace('[HTML:Page:Title]', Title)
|
||||||
HTML = HTML.replace('[HTML:Page:Description]', Description)
|
HTML = HTML.replace('[HTML:Page:Description]', Description)
|
||||||
HTML = HTML.replace('[HTML:Page:Image]', Image)
|
HTML = HTML.replace('[HTML:Page:Image]', Image)
|
||||||
|
@ -250,9 +251,7 @@ def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesLi
|
||||||
return HTML, ContentHTML, SlimHTML, Description, Image
|
return HTML, ContentHTML, SlimHTML, Description, Image
|
||||||
|
|
||||||
def OrderPages(Old):
|
def OrderPages(Old):
|
||||||
New = []
|
New, NoOrder, Max = [], [], 0
|
||||||
NoOrder = []
|
|
||||||
Max = 0
|
|
||||||
for i,e in enumerate(Old):
|
for i,e in enumerate(Old):
|
||||||
Curr = e[3]['Order']
|
Curr = e[3]['Order']
|
||||||
if Curr:
|
if Curr:
|
||||||
|
@ -448,25 +447,65 @@ def SetSorting(Sorting):
|
||||||
Sorting.update({i:Default[i]})
|
Sorting.update({i:Default[i]})
|
||||||
return Sorting
|
return Sorting
|
||||||
|
|
||||||
|
def GetConfMenu(Conf):
|
||||||
|
Entries = ReadConf(Conf, 'Menu')
|
||||||
|
if Entries:
|
||||||
|
Menu, Max = [], 0
|
||||||
|
for i in Entries:
|
||||||
|
if int(i) > Max:
|
||||||
|
Max = int(i)
|
||||||
|
for i in range(Max+1):
|
||||||
|
Menu += [[]]
|
||||||
|
for i in Entries:
|
||||||
|
e = Entries[i]
|
||||||
|
if (e.startswith('<') and e.endswith('>')) or (e.startswith('[') and e.endswith(')')):
|
||||||
|
Menu[int(i)] = markdown(e, extensions=MarkdownExts)
|
||||||
|
else:
|
||||||
|
if not (e.lower().endswith('.html') or e.lower().endswith('.htm')):
|
||||||
|
Menu[int(i)] = e + '.html'
|
||||||
|
print(Menu)
|
||||||
|
return Menu
|
||||||
|
|
||||||
def Main(Args, FeedEntries):
|
def Main(Args, FeedEntries):
|
||||||
SiteName = Args.SiteName if Args.SiteName else ''
|
HavePages, HavePosts = False, False
|
||||||
SiteTagline = Args.SiteTagline if Args.SiteTagline else ''
|
SiteConf = LoadConf('Site.ini')
|
||||||
SiteDomain = Args.SiteDomain.rstrip('/') if Args.SiteDomain else ''
|
#SiteMenu = GetConfMenu(SiteConf)
|
||||||
SiteLang = Args.SiteLang if Args.SiteLang else 'en'
|
|
||||||
|
SiteName = Args.SiteName if Args.SiteName else ReadConf(SiteConf, 'Site', 'Name') if ReadConf(SiteConf, 'Site', 'Name') else ''
|
||||||
|
SiteTagline = Args.SiteTagline if Args.SiteTagline else ReadConf(SiteConf, 'Site', 'Tagline') if ReadConf(SiteConf, 'Site', 'Tagline') else ''
|
||||||
|
SiteDomain = Args.SiteDomain.rstrip('/') if Args.SiteDomain else ReadConf(SiteConf, 'Site', 'Domain') if ReadConf(SiteConf, 'Site', 'Domain') else ''
|
||||||
|
SiteLang = Args.SiteLang if Args.SiteLang else ReadConf(SiteConf, 'Site', 'Lang') if ReadConf(SiteConf, 'Site', 'Lang') else 'en'
|
||||||
Locale = LoadLocale(SiteLang)
|
Locale = LoadLocale(SiteLang)
|
||||||
MastodonURL = Args.MastodonURL if Args.MastodonURL else ''
|
MastodonURL = Args.MastodonURL if Args.MastodonURL else ''
|
||||||
MastodonToken = Args.MastodonToken if Args.MastodonToken else ''
|
MastodonToken = Args.MastodonToken if Args.MastodonToken else ''
|
||||||
|
MarkdownExts = literal_eval(Args.MarkdownExts) if Args.MarkdownExts else EvalOpt(ReadConf(SiteConf, 'Site', 'MarkdownExts')) if ReadConf(SiteConf, 'Site', 'MarkdownExts') else ['attr_list', 'def_list', 'markdown_del_ins', 'mdx_subscript', 'mdx_superscript']
|
||||||
|
|
||||||
|
AutoCategories = False
|
||||||
|
if Args.AutoCategories != None:
|
||||||
|
if literal_eval(Args.AutoCategories) == True:
|
||||||
|
AutoCategories = True
|
||||||
|
else:
|
||||||
|
if ReadConf(SiteConf, 'Site', 'AutoCategories') != None:
|
||||||
|
if EvalOpt(ReadConf(SiteConf, 'Site', 'AutoCategories')) == True:
|
||||||
|
AutoCategories = True
|
||||||
|
|
||||||
ResetPublic()
|
ResetPublic()
|
||||||
|
|
||||||
if os.path.isdir('Pages'):
|
if os.path.isdir('Pages'):
|
||||||
|
HavePages = True
|
||||||
shutil.copytree('Pages', 'public')
|
shutil.copytree('Pages', 'public')
|
||||||
if Args.GemtextOut:
|
if Args.GemtextOut:
|
||||||
shutil.copytree('Pages', 'public.gmi', ignore=IgnoreFiles)
|
shutil.copytree('Pages', 'public.gmi', ignore=IgnoreFiles)
|
||||||
if os.path.isdir('Posts'):
|
if os.path.isdir('Posts'):
|
||||||
|
HavePosts = True
|
||||||
shutil.copytree('Posts', 'public/Posts')
|
shutil.copytree('Posts', 'public/Posts')
|
||||||
if Args.GemtextOut:
|
if Args.GemtextOut:
|
||||||
shutil.copytree('Posts', 'public.gmi/Posts', ignore=IgnoreFiles)
|
shutil.copytree('Posts', 'public.gmi/Posts', ignore=IgnoreFiles)
|
||||||
|
|
||||||
|
if not HavePages and not HavePosts:
|
||||||
|
print("[E] No Pages or posts found. Nothing to do, exiting!")
|
||||||
|
exit()
|
||||||
|
|
||||||
print("[I] Generating HTML")
|
print("[I] Generating HTML")
|
||||||
Pages = MakeSite(
|
Pages = MakeSite(
|
||||||
TemplatesText=LoadFromDir('Templates', '*.html'),
|
TemplatesText=LoadFromDir('Templates', '*.html'),
|
||||||
|
@ -481,8 +520,8 @@ def Main(Args, FeedEntries):
|
||||||
Locale=Locale,
|
Locale=Locale,
|
||||||
Minify=Args.Minify if Args.Minify else 'None',
|
Minify=Args.Minify if Args.Minify else 'None',
|
||||||
Sorting=SetSorting(literal_eval(Args.ContextParts) if Args.ContextParts else {}),
|
Sorting=SetSorting(literal_eval(Args.ContextParts) if Args.ContextParts else {}),
|
||||||
MarkdownExts=literal_eval(Args.MarkdownExts) if Args.MarkdownExts else ['attr_list', 'def_list', 'markdown_del_ins', 'mdx_subscript', 'mdx_superscript'],
|
MarkdownExts=MarkdownExts,
|
||||||
AutoCategories=Args.AutoCategories)
|
AutoCategories=AutoCategories) # Args.AutoCategories if Args.AutoCategories else EvalOpt(ReadConf(SiteConf, 'Site', 'AutoCategories')) if ReadConf(SiteConf, 'Site', 'AutoCategories') else None)
|
||||||
|
|
||||||
if FeedEntries != 0:
|
if FeedEntries != 0:
|
||||||
print("[I] Generating Feeds")
|
print("[I] Generating Feeds")
|
||||||
|
@ -527,8 +566,10 @@ def Main(Args, FeedEntries):
|
||||||
Pages,
|
Pages,
|
||||||
Header=Args.GemtextHeader if Args.GemtextHeader else '# {}\n\n'.format(SiteName) if SiteName else '')
|
Header=Args.GemtextHeader if Args.GemtextHeader else '# {}\n\n'.format(SiteName) if SiteName else '')
|
||||||
|
|
||||||
|
print("[I] Last Steps")
|
||||||
DelTmp()
|
DelTmp()
|
||||||
os.system("cp -R Assets/* public/")
|
os.system("cp -R Assets/* public/")
|
||||||
|
|
||||||
print("[I] Done!")
|
print("[I] Done!")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -548,7 +589,7 @@ if __name__ == '__main__':
|
||||||
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)
|
||||||
Parser.add_argument('--AutoCategories', type=bool)
|
Parser.add_argument('--AutoCategories', type=str)
|
||||||
Args = Parser.parse_args()
|
Args = Parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
""" ================================= |
|
||||||
|
| This file is part of |
|
||||||
|
| staticoso |
|
||||||
|
| Just a simple Static Site Generator |
|
||||||
|
| |
|
||||||
|
| Licensed under the AGPLv3 license |
|
||||||
|
| Copyright (C) 2022, OctoSpacc |
|
||||||
|
| ================================= """
|
||||||
|
|
||||||
|
import configparser
|
||||||
|
from ast import literal_eval
|
||||||
|
|
||||||
|
def LoadConf(File):
|
||||||
|
Conf = configparser.ConfigParser()
|
||||||
|
Conf.read(File)
|
||||||
|
return Conf
|
||||||
|
|
||||||
|
def ReadConf(Conf, Sect, Opt=None):
|
||||||
|
if Opt:
|
||||||
|
if Conf.has_option(Sect, Opt):
|
||||||
|
return Conf[Sect][Opt]
|
||||||
|
else:
|
||||||
|
if Conf.has_section(Sect):
|
||||||
|
return Conf[Sect]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def EvalOpt(Opt):
|
||||||
|
if Opt:
|
||||||
|
return literal_eval(Opt)
|
||||||
|
else:
|
||||||
|
return None
|
Loading…
Reference in New Issue