mirror of https://gitlab.com/octtspacc/staticoso
Code improvements, mainly for handling conf. flags
This commit is contained in:
parent
e44924eda6
commit
c546458073
|
@ -110,25 +110,29 @@ def Main(Args, FeedEntries):
|
||||||
# os.chdir(Args.InputDir)
|
# os.chdir(Args.InputDir)
|
||||||
# print(f"[I] Current directory: {Args.InputDir}")
|
# print(f"[I] Current directory: {Args.InputDir}")
|
||||||
|
|
||||||
DiffBuild = Args.DiffBuild
|
SiteName = OptionChoose('', Args.SiteName, ReadConf(SiteConf, 'Site', 'Name'))
|
||||||
OutputDir = Args.OutputDir if Args.OutputDir else ReadConf(SiteConf, 'Site', 'OutputDir') if ReadConf(SiteConf, 'Site', 'OutputDir') else 'public'
|
if SiteName:
|
||||||
|
print(f"[I] Compiling: {SiteName}")
|
||||||
|
|
||||||
|
OutputDir = OptionChoose('public', Args.OutputDir, ReadConf(SiteConf, 'Site', 'OutputDir'))
|
||||||
OutputDir = OutputDir.removesuffix('/')
|
OutputDir = OutputDir.removesuffix('/')
|
||||||
CheckSafeOutputDir(OutputDir)
|
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 ''
|
DiffBuild = Args.DiffBuild
|
||||||
BlogName = Args.BlogName if Args.BlogName else ReadConf(SiteConf, 'Site', 'BlogName') if ReadConf(SiteConf, 'Site', 'BlogName') else ''
|
BlogName = OptionChoose('', Args.BlogName, ReadConf(SiteConf, 'Site', 'BlogName'))
|
||||||
SiteTagline = Args.SiteTagline if Args.SiteTagline else ReadConf(SiteConf, 'Site', 'Tagline') if ReadConf(SiteConf, 'Site', 'Tagline') else ''
|
SiteTagline = OptionChoose('', Args.SiteTagline, ReadConf(SiteConf, 'Site', 'Tagline'))
|
||||||
SiteTemplate = Args.SiteTemplate if Args.SiteTemplate else ReadConf(SiteConf, 'Site', 'Template') if ReadConf(SiteConf, 'Site', 'Template') else 'Default.html'
|
SiteTemplate = OptionChoose('Default.html', Args.SiteTemplate, ReadConf(SiteConf, 'Site', 'Template'))
|
||||||
SiteDomain = Args.SiteDomain.rstrip('/') if Args.SiteDomain else ReadConf(SiteConf, 'Site', 'Domain').rstrip('/') if ReadConf(SiteConf, 'Site', 'Domain') else ''
|
SiteDomain = OptionChoose('', Args.SiteDomain, ReadConf(SiteConf, 'Site', 'Domain'))
|
||||||
SiteRoot = Args.SiteRoot if Args.SiteRoot else ReadConf(SiteConf, 'Site', 'Root') if ReadConf(SiteConf, 'Site', 'Root') else '/'
|
SiteDomain = SiteDomain.removesuffix('/')
|
||||||
SiteLang = Args.SiteLang if Args.SiteLang else ReadConf(SiteConf, 'Site', 'Lang') if ReadConf(SiteConf, 'Site', 'Lang') else 'en'
|
SiteRoot = OptionChoose('/', Args.SiteRoot, ReadConf(SiteConf, 'Site', 'Root'))
|
||||||
|
SiteLang = OptionChoose('en', Args.SiteLang, ReadConf(SiteConf, 'Site', 'Lang'))
|
||||||
Locale = LoadLocale(SiteLang)
|
Locale = LoadLocale(SiteLang)
|
||||||
MastodonURL = Args.MastodonURL if Args.MastodonURL else ReadConf(SiteConf, 'Mastodon', 'URL') if ReadConf(SiteConf, 'Mastodon', 'URL') else ''
|
MastodonURL = OptionChoose('', Args.MastodonURL, ReadConf(SiteConf, 'Mastodon', 'URL'))
|
||||||
MastodonToken = Args.MastodonToken if Args.MastodonToken else ReadConf(SiteConf, 'Mastodon', 'Token') if ReadConf(SiteConf, 'Mastodon', 'Token') else ''
|
MastodonToken = OptionChoose('', Args.MastodonToken, ReadConf(SiteConf, 'Mastodon', 'Token'))
|
||||||
DynamicParts = literal_eval(Args.DynamicParts) if Args.DynamicParts else EvalOpt(ReadConf(SiteConf, 'Site', 'DynamicParts')) if ReadConf(SiteConf, 'Site', 'DynamicParts') else {}
|
DynamicParts = literal_eval(OptionChoose('{}', Args.DynamicParts, ReadConf(SiteConf, 'Site', 'DynamicParts')))
|
||||||
MarkdownExts = literal_eval(Args.MarkdownExts) if Args.MarkdownExts else EvalOpt(ReadConf(SiteConf, 'Markdown', 'Exts')) if ReadConf(SiteConf, 'Markdown', 'Exts') else MarkdownExtsDefault
|
MarkdownExts = literal_eval(OptionChoose(str(MarkdownExtsDefault), Args.MarkdownExts, ReadConf(SiteConf, 'Markdown', 'Exts')))
|
||||||
ActivityPubTypeFilter = Args.ActivityPubTypeFilter if Args.ActivityPubTypeFilter else ReadConf(SiteConf, 'ActivityPub', 'TypeFilter') if ReadConf(SiteConf, 'ActivityPub', 'TypeFilter') else 'Post'
|
ActivityPubTypeFilter = OptionChoose('Post', Args.ActivityPubTypeFilter, ReadConf(SiteConf, 'ActivityPub', 'TypeFilter'))
|
||||||
ActivityPubHoursLimit = OptionChoose(168, Args.ActivityPubHoursLimit, ReadConf(SiteConf, 'ActivityPub', 'HoursLimit'))
|
ActivityPubHoursLimit = OptionChoose(168, Args.ActivityPubHoursLimit, ReadConf(SiteConf, 'ActivityPub', 'HoursLimit'))
|
||||||
FeedCategoryFilter = OptionChoose('Blog', Args.FeedCategoryFilter, ReadConf(SiteConf, 'Feed', 'CategoryFilter'))
|
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'))
|
||||||
|
@ -140,7 +144,7 @@ def Main(Args, FeedEntries):
|
||||||
GemtextHeader = Args.GemtextHeader if Args.GemtextHeader else ReadConf(SiteConf, 'Gemtext', 'Header') if ReadConf(SiteConf, 'Gemtext', 'Header') else f"# {SiteName}\n\n" if SiteName else ''
|
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(OptionChoose('{}', Args.Sorting, ReadConf(SiteConf, 'Site', 'Sorting')))
|
||||||
|
|
||||||
MenuEntries = ReadConf(SiteConf, 'Menu')
|
MenuEntries = ReadConf(SiteConf, 'Menu')
|
||||||
if MenuEntries:
|
if MenuEntries:
|
||||||
|
@ -282,7 +286,7 @@ if __name__ == '__main__':
|
||||||
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('--FeedCategoryFilter', type=str)
|
Parser.add_argument('--FeedCategoryFilter', type=str)
|
||||||
Parser.add_argument('--ActivityPubTypeFilter', type=str)
|
Parser.add_argument('--ActivityPubTypeFilter', type=str, help=argparse.SUPPRESS)
|
||||||
Parser.add_argument('--ActivityPubHoursLimit', type=int)
|
Parser.add_argument('--ActivityPubHoursLimit', type=int)
|
||||||
Parser.add_argument('--AutoCategories', type=str)
|
Parser.add_argument('--AutoCategories', type=str)
|
||||||
Args = Parser.parse_args()
|
Args = Parser.parse_args()
|
||||||
|
|
|
@ -16,14 +16,19 @@ from Modules.Markdown import *
|
||||||
from Modules.Pug import *
|
from Modules.Pug import *
|
||||||
from Modules.Utils import *
|
from Modules.Utils import *
|
||||||
|
|
||||||
|
HTMLSectionTitleLine = '<h{Index} class="SectionHeading"><span class="SectionLink"><a href="#{DashTitle}"><span>»</span></a> </span><span class="SectionTitle" id="{DashTitle}">{Title}</span></h{Index}>'
|
||||||
|
#PugSectionTitleLine = "{Line[:Index]}{Line[Index:Index+2]}.SectionHeading #[span.SectionLink #[a(href='#{DashTitle}') #[span »]] ]#[span#{DashTitle}.SectionTitle {Line[Index+2:]}]"
|
||||||
|
|
||||||
def DashifyTitle(Title, Done=[]):
|
def DashifyTitle(Title, Done=[]):
|
||||||
return UndupeStr(DashifyStr(Title.lstrip(' ').rstrip(' ')), Done, '-')
|
return UndupeStr(DashifyStr(Title.lstrip(' ').rstrip(' ')), Done, '-')
|
||||||
|
|
||||||
def MakeLinkableTitle(Line, Title, DashTitle, Type):
|
def MakeLinkableTitle(Line, Title, DashTitle, Type):
|
||||||
if Type == 'md':
|
if Type == 'md':
|
||||||
Index = Title.split(' ')[0].count('#')
|
Index = Title.split(' ')[0].count('#')
|
||||||
#return f'<h{Index} id="{DashTitle}" class="SectionTitle"><a href="#{DashTitle}">{Title[Index+1:]}</a></h{Index}>'
|
return HTMLSectionTitleLine.format(
|
||||||
return f'<h{Index} class="SectionHeading"><span class="SectionLink"><a href="#{DashTitle}"><span>»</span></a> </span><span class="SectionTitle" id="{DashTitle}">{Title[Index+1:]}</span></h{Index}>'
|
Index=Index,
|
||||||
|
DashTitle=DashTitle,
|
||||||
|
Title=Title[Index+1:])
|
||||||
elif Type == 'pug':
|
elif Type == 'pug':
|
||||||
Index = Line.find('h')
|
Index = Line.find('h')
|
||||||
return f"{Line[:Index]}{Line[Index:Index+2]}.SectionHeading #[span.SectionLink #[a(href='#{DashTitle}') #[span »]] ]#[span#{DashTitle}.SectionTitle {Line[Index+2:]}]"
|
return f"{Line[:Index]}{Line[Index:Index+2]}.SectionHeading #[span.SectionLink #[a(href='#{DashTitle}') #[span »]] ]#[span#{DashTitle}.SectionTitle {Line[Index+2:]}]"
|
||||||
|
|
2
TODO
2
TODO
|
@ -1,5 +1,7 @@
|
||||||
- Check if external tools (pug-cli, html2gmi) are installed
|
- Check if external tools (pug-cli, html2gmi) are installed
|
||||||
- Fix and optimize differential building
|
- Fix and optimize differential building
|
||||||
|
- Static code syntax highlighing
|
||||||
|
- Override internal HTML snippets (with config file in Templates/NAME.ini)
|
||||||
- Specify input folder(s)
|
- Specify input folder(s)
|
||||||
- Customize HTML source code for Meta lines / page lists
|
- Customize HTML source code for Meta lines / page lists
|
||||||
- Show page size/words/time in meta line
|
- Show page size/words/time in meta line
|
||||||
|
|
Loading…
Reference in New Issue