mirror of https://gitlab.com/octtspacc/staticoso
Minor code tweaks; Add: build time reporting, custom output path
This commit is contained in:
parent
93a725839e
commit
342b2e8163
|
@ -28,19 +28,19 @@ from Modules.Markdown import *
|
||||||
from Modules.Site import *
|
from Modules.Site import *
|
||||||
from Modules.Sitemap import *
|
from Modules.Sitemap import *
|
||||||
from Modules.Utils import *
|
from Modules.Utils import *
|
||||||
|
|
||||||
def ResetPublic():
|
def ResetPublic(OutputDir):
|
||||||
for i in ('public', 'public.gmi'):
|
for i in (OutputDir, f"{OutputDir}.gmi"):
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(i)
|
shutil.rmtree(i)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def DelTmp():
|
def DelTmp(OutputDir):
|
||||||
for Ext in FileExtensions['Tmp']:
|
for Ext in FileExtensions['Tmp']:
|
||||||
for File in Path('public').rglob(f"*.{Ext}"):
|
for File in Path(OutputDir).rglob(f"*.{Ext}"):
|
||||||
os.remove(File)
|
os.remove(File)
|
||||||
for Dir in ('public', 'public.gmi'):
|
for Dir in (OutputDir, f"{OutputDir}.gmi"):
|
||||||
for File in Path(Dir).rglob('*.tmp'):
|
for File in Path(Dir).rglob('*.tmp'):
|
||||||
os.remove(File)
|
os.remove(File)
|
||||||
|
|
||||||
|
@ -72,6 +72,10 @@ 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 = OutputDir.removesuffix('/')
|
||||||
|
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 ''
|
||||||
BlogName = Args.BlogName if Args.BlogName else ReadConf(SiteConf, 'Site', 'BlogName') if ReadConf(SiteConf, 'Site', 'BlogName') else ''
|
BlogName = Args.BlogName if Args.BlogName else ReadConf(SiteConf, 'Site', 'BlogName') if ReadConf(SiteConf, 'Site', 'BlogName') else ''
|
||||||
SiteTagline = Args.SiteTagline if Args.SiteTagline else ReadConf(SiteConf, 'Site', 'Tagline') if ReadConf(SiteConf, 'Site', 'Tagline') else ''
|
SiteTagline = Args.SiteTagline if Args.SiteTagline else ReadConf(SiteConf, 'Site', 'Tagline') if ReadConf(SiteConf, 'Site', 'Tagline') else ''
|
||||||
|
@ -101,25 +105,26 @@ def Main(Args, FeedEntries):
|
||||||
else:
|
else:
|
||||||
ConfMenu = []
|
ConfMenu = []
|
||||||
|
|
||||||
ResetPublic()
|
ResetPublic(OutputDir)
|
||||||
|
|
||||||
if os.path.isdir('Pages'):
|
if os.path.isdir('Pages'):
|
||||||
HavePages = True
|
HavePages = True
|
||||||
shutil.copytree('Pages', 'public')
|
shutil.copytree('Pages', OutputDir)
|
||||||
if GemtextOut:
|
if GemtextOut:
|
||||||
shutil.copytree('Pages', 'public.gmi', ignore=IgnoreFiles)
|
shutil.copytree('Pages', f"{OutputDir}.gmi", ignore=IgnoreFiles)
|
||||||
if os.path.isdir('Posts'):
|
if os.path.isdir('Posts'):
|
||||||
HavePosts = True
|
HavePosts = True
|
||||||
shutil.copytree('Posts', 'public/Posts')
|
shutil.copytree('Posts', f"{OutputDir}/Posts")
|
||||||
if GemtextOut:
|
if GemtextOut:
|
||||||
shutil.copytree('Posts', 'public.gmi/Posts', ignore=IgnoreFiles)
|
shutil.copytree('Posts', f"{OutputDir}.gmi/Posts", ignore=IgnoreFiles)
|
||||||
|
|
||||||
if not HavePages and not HavePosts:
|
if not (HavePages or HavePosts):
|
||||||
print("[E] No Pages or posts found. Nothing to do, exiting!")
|
print("[E] No Pages or posts found. Nothing to do, exiting!")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
print("[I] Generating HTML")
|
print("[I] Generating HTML")
|
||||||
Pages = MakeSite(
|
Pages = MakeSite(
|
||||||
|
OutputDir=OutputDir,
|
||||||
TemplatesText=LoadFromDir('Templates', ['*.htm', '*.html']),
|
TemplatesText=LoadFromDir('Templates', ['*.htm', '*.html']),
|
||||||
StaticPartsText=LoadFromDir('StaticParts', ['*.htm', '*.html']),
|
StaticPartsText=LoadFromDir('StaticParts', ['*.htm', '*.html']),
|
||||||
DynamicParts=DynamicParts,
|
DynamicParts=DynamicParts,
|
||||||
|
@ -146,6 +151,7 @@ def Main(Args, FeedEntries):
|
||||||
print("[I] Generating Feeds")
|
print("[I] Generating Feeds")
|
||||||
for FeedType in (True, False):
|
for FeedType in (True, False):
|
||||||
MakeFeed(
|
MakeFeed(
|
||||||
|
OutputDir=OutputDir,
|
||||||
CategoryFilter=FeedCategoryFilter,
|
CategoryFilter=FeedCategoryFilter,
|
||||||
Pages=Pages,
|
Pages=Pages,
|
||||||
SiteName=SiteName,
|
SiteName=SiteName,
|
||||||
|
@ -158,7 +164,7 @@ def Main(Args, FeedEntries):
|
||||||
|
|
||||||
if SitemapOut:
|
if SitemapOut:
|
||||||
print("[I] Generating Sitemap")
|
print("[I] Generating Sitemap")
|
||||||
MakeSitemap(Pages, SiteDomain)
|
MakeSitemap(OutputDir, Pages, SiteDomain)
|
||||||
|
|
||||||
if ActivityPub and MastodonURL and MastodonToken and SiteDomain:
|
if ActivityPub and MastodonURL and MastodonToken and SiteDomain:
|
||||||
print("[I] Mastodon Stuff")
|
print("[I] Mastodon Stuff")
|
||||||
|
@ -176,11 +182,11 @@ def Main(Args, FeedEntries):
|
||||||
MastodonPosts = []
|
MastodonPosts = []
|
||||||
|
|
||||||
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
||||||
File = 'public/{}.html'.format(StripExt(File))
|
File = f"{OutputDir}/{StripExt(File)}.html"
|
||||||
Content = ReadFile(File)
|
Content = ReadFile(File)
|
||||||
Post = ''
|
Post = ''
|
||||||
for p in MastodonPosts:
|
for p in MastodonPosts:
|
||||||
if p['Link'] == SiteDomain + '/' + File[len('public/'):]:
|
if p['Link'] == SiteDomain + '/' + File[len(f"{OutputDir}/"):]:
|
||||||
Post = '<br><h3>{StrComments}</h3><a href="{URL}" rel="noopener" target="_blank">{StrOpen} ↗️</a>'.format(
|
Post = '<br><h3>{StrComments}</h3><a href="{URL}" rel="noopener" target="_blank">{StrOpen} ↗️</a>'.format(
|
||||||
StrComments=Locale['Comments'],
|
StrComments=Locale['Comments'],
|
||||||
StrOpen=Locale['OpenInNewTab'],
|
StrOpen=Locale['OpenInNewTab'],
|
||||||
|
@ -192,19 +198,21 @@ def Main(Args, FeedEntries):
|
||||||
if GemtextOut:
|
if GemtextOut:
|
||||||
print("[I] Generating Gemtext")
|
print("[I] Generating Gemtext")
|
||||||
GemtextCompileList(
|
GemtextCompileList(
|
||||||
|
OutputDir,
|
||||||
Pages,
|
Pages,
|
||||||
Header=Args.GemtextHeader if Args.GemtextHeader else f"# {SiteName}\n\n" if SiteName else '')
|
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()
|
DelTmp(OutputDir)
|
||||||
|
|
||||||
print("[I] Copying Assets")
|
print("[I] Copying Assets")
|
||||||
os.system("cp -R Assets/* public/")
|
os.system(f"cp -R Assets/* {OutputDir}/")
|
||||||
|
|
||||||
print("[I] Done!")
|
print("[I] Done!")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
Parser = argparse.ArgumentParser()
|
Parser = argparse.ArgumentParser()
|
||||||
|
Parser.add_argument('--OutputDir', type=str)
|
||||||
Parser.add_argument('--Sorting', type=str)
|
Parser.add_argument('--Sorting', type=str)
|
||||||
Parser.add_argument('--SiteLang', type=str)
|
Parser.add_argument('--SiteLang', type=str)
|
||||||
Parser.add_argument('--SiteRoot', type=str)
|
Parser.add_argument('--SiteRoot', type=str)
|
||||||
|
|
|
@ -62,7 +62,7 @@ def MastodonShare(InstanceURL, Token, TypeFilter, CategoryFilter, HoursLimit, Pa
|
||||||
Parse = BeautifulSoup(ContentHTML, 'html.parser')
|
Parse = BeautifulSoup(ContentHTML, 'html.parser')
|
||||||
Paragraphs = Parse.p.get_text().split('\n')
|
Paragraphs = Parse.p.get_text().split('\n')
|
||||||
Read = '...' + Locale['ReadFullPost'] + ':\n'
|
Read = '...' + Locale['ReadFullPost'] + ':\n'
|
||||||
URL = '{}/{}.html'.format(SiteDomain, StripExt(File))
|
URL = f"{SiteDomain}/{StripExt(File)}.html"
|
||||||
for p in Paragraphs:
|
for p in Paragraphs:
|
||||||
if p and len(Read+Desc+p)+25 < 500:
|
if p and len(Read+Desc+p)+25 < 500:
|
||||||
Desc += p + '\n\n'
|
Desc += p + '\n\n'
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
from Libs.feedgen.feed import FeedGenerator
|
from Libs.feedgen.feed import FeedGenerator
|
||||||
from Modules.Utils import *
|
from Modules.Utils import *
|
||||||
|
|
||||||
def MakeFeed(CategoryFilter, Pages, SiteName, SiteTagline, SiteDomain, MaxEntries, Lang, FullSite=False, Minify=False):
|
def MakeFeed(OutputDir, CategoryFilter, Pages, SiteName, SiteTagline, SiteDomain, MaxEntries, Lang, FullSite=False, Minify=False):
|
||||||
Feed = FeedGenerator()
|
Feed = FeedGenerator()
|
||||||
Link = SiteDomain if SiteDomain else ' '
|
Link = SiteDomain if SiteDomain else ' '
|
||||||
Feed.id(Link)
|
Feed.id(Link)
|
||||||
|
@ -34,8 +34,8 @@ def MakeFeed(CategoryFilter, Pages, SiteName, SiteTagline, SiteDomain, MaxEntrie
|
||||||
if FullSite or (not FullSite and Meta['Type'] == 'Post' and (not CategoryFilter or (CategoryFilter and (CategoryFilter in Meta['Categories'] or CategoryFilter == '*')))):
|
if FullSite or (not FullSite and Meta['Type'] == 'Post' and (not CategoryFilter or (CategoryFilter and (CategoryFilter in Meta['Categories'] or CategoryFilter == '*')))):
|
||||||
Entry = Feed.add_entry()
|
Entry = Feed.add_entry()
|
||||||
FileName = File.split('/')[-1]
|
FileName = File.split('/')[-1]
|
||||||
File = '{}.html'.format(StripExt(File))
|
File = f"{StripExt(File)}.html"
|
||||||
Content = ReadFile('public/'+File)
|
Content = ReadFile(f"{OutputDir}/{File}")
|
||||||
Link = SiteDomain + '/' + File if SiteDomain else ' '
|
Link = SiteDomain + '/' + File if SiteDomain else ' '
|
||||||
CreatedOn = GetFullDate(Meta['CreatedOn'])
|
CreatedOn = GetFullDate(Meta['CreatedOn'])
|
||||||
EditedOn = GetFullDate(Meta['EditedOn'])
|
EditedOn = GetFullDate(Meta['EditedOn'])
|
||||||
|
@ -51,11 +51,8 @@ def MakeFeed(CategoryFilter, Pages, SiteName, SiteTagline, SiteDomain, MaxEntrie
|
||||||
EditedOn = EditedOn if EditedOn else CreatedOn if CreatedOn and not EditedOn else '1970-01-01T00:00+00:00'
|
EditedOn = EditedOn if EditedOn else CreatedOn if CreatedOn and not EditedOn else '1970-01-01T00:00+00:00'
|
||||||
Entry.updated(EditedOn)
|
Entry.updated(EditedOn)
|
||||||
|
|
||||||
if not os.path.exists('public/feed'):
|
if not os.path.exists(f"{OutputDir}/feed"):
|
||||||
os.mkdir('public/feed')
|
os.mkdir(f"{OutputDir}/feed")
|
||||||
if FullSite:
|
FeedType = 'site.' if FullSite else ''
|
||||||
FeedType = 'site.'
|
Feed.atom_file(f"{OutputDir}/feed/{FeedType}atom.xml", pretty=(not Minify))
|
||||||
else:
|
Feed.rss_file(f"{OutputDir}/feed/{FeedType}rss.xml", pretty=(not Minify))
|
||||||
FeedType = ''
|
|
||||||
Feed.atom_file('public/feed/' + FeedType + 'atom.xml', pretty=(not Minify))
|
|
||||||
Feed.rss_file('public/feed/' + FeedType + 'rss.xml', pretty=(not Minify))
|
|
||||||
|
|
|
@ -22,20 +22,20 @@ def FixGemlogDateLine(Line):
|
||||||
Line = Words[0] + '\n' + Words[1][1:] + ' ' + ' '.join(Words[2:])
|
Line = Words[0] + '\n' + Words[1][1:] + ' ' + ' '.join(Words[2:])
|
||||||
return Line
|
return Line
|
||||||
|
|
||||||
def GemtextCompileList(Pages, Header=''):
|
def GemtextCompileList(OutputDir, Pages, Header=''):
|
||||||
Cmd = ''
|
Cmd = ''
|
||||||
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
||||||
Src = 'public.gmi/{}.html.tmp'.format(StripExt(File))
|
Src = f"{OutputDir}.gmi/{StripExt(File)}.html.tmp"
|
||||||
Dst = 'public.gmi/{}.gmi'.format(StripExt(File))
|
Dst = f"{OutputDir}.gmi/{StripExt(File)}.gmi"
|
||||||
SlimHTML = StripAttrs(SlimHTML)
|
SlimHTML = StripAttrs(SlimHTML)
|
||||||
for i in ('ol', 'ul', 'li'):
|
for i in ('ol', 'ul', 'li'):
|
||||||
for j in ('<'+i+'>', '</'+i+'>'):
|
for j in ('<'+i+'>', '</'+i+'>'):
|
||||||
SlimHTML = SlimHTML.replace(j, '')
|
SlimHTML = SlimHTML.replace(j, '')
|
||||||
WriteFile(Src, SlimHTML.replace('</a>', '</a><br>').replace('.html', '.gmi')) # TODO: Adjust links properly..
|
WriteFile(Src, SlimHTML.replace('</a>', '</a><br>').replace('.html', '.gmi')) # TODO: Adjust links properly..
|
||||||
Cmd += 'cat "{}" | html2gmi > "{}"; '.format(Src, Dst)
|
Cmd += f'cat "{Src}" | html2gmi > "{Dst}"; '
|
||||||
os.system(Cmd)
|
os.system(Cmd)
|
||||||
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
||||||
Dst = 'public.gmi/{}.gmi'.format(StripExt(File))
|
Dst = f"{OutputDir}.gmi/{StripExt(File)}.gmi"
|
||||||
Gemtext = ''
|
Gemtext = ''
|
||||||
for Line in ReadFile(Dst).splitlines():
|
for Line in ReadFile(Dst).splitlines():
|
||||||
Line = FixGemlogDateLine(Line)
|
Line = FixGemlogDateLine(Line)
|
||||||
|
@ -52,43 +52,3 @@ def ParseTag(Content):
|
||||||
print(Content)
|
print(Content)
|
||||||
Parse = BeautifulSoup(str(Content), 'html.parser')
|
Parse = BeautifulSoup(str(Content), 'html.parser')
|
||||||
Tag = Parse.find()
|
Tag = Parse.find()
|
||||||
|
|
||||||
"""
|
|
||||||
def HTML2Gemtext(Pages, SiteName, SiteTagline):
|
|
||||||
#os.mkdir('public.gmi')
|
|
||||||
for File, Content, Titles, Meta, HTMLContent, Description, Image in Pages:
|
|
||||||
Gemtext = ''
|
|
||||||
Content = HTMLContent
|
|
||||||
print(File)
|
|
||||||
while len(Content) != 0:
|
|
||||||
BlockStart = Content.find('<')
|
|
||||||
TagEnd = Content.find('>')
|
|
||||||
Parse = BeautifulSoup(Content, 'html.parser')
|
|
||||||
Tag = Parse.find()
|
|
||||||
#if Tag.name in ('a'):
|
|
||||||
# if 'href' in Tag.attrs:
|
|
||||||
# pass
|
|
||||||
for i in Tag.contents:
|
|
||||||
ParseTag(i)
|
|
||||||
if Tag.name in ('h1', 'h2', 'h3'):
|
|
||||||
Gemtext += '#' * int(Tag.name[1]) + ' '
|
|
||||||
elif Tag.name in ('h4', 'h5', 'h6'):
|
|
||||||
Gemtext += '### '
|
|
||||||
elif Tag.name in ('li'):
|
|
||||||
Gemtext += '* '
|
|
||||||
Gemtext += str(Tag.get_text()) + '\n\n'
|
|
||||||
#print(File, Tag.name, len(Tag.contents))
|
|
||||||
if Tag.name in ClosedTags:
|
|
||||||
Str = '</{}>'.format(Tag.name)
|
|
||||||
elif Tag.name in OpenTags:
|
|
||||||
Str = '>'
|
|
||||||
BlockEnd = Content.find(Str) + len(Str)
|
|
||||||
Content = Content.replace(Content[BlockStart:TagEnd], '').replace(Content[BlockEnd-len(Str):BlockEnd], '')
|
|
||||||
#print(BlockStart, TagEnd, BlockEnd, Tag.contents)
|
|
||||||
#print(Content[BlockStart:BlockEnd])
|
|
||||||
#Gemtext += Content[BlockStart:BlockEnd]
|
|
||||||
Content = Content[BlockEnd:]
|
|
||||||
PagePath = 'public.gmi/{}.gmi'.format(StripExt(File))
|
|
||||||
WriteFile(PagePath, Gemtext)
|
|
||||||
#exit()
|
|
||||||
"""
|
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
import os
|
import os
|
||||||
from Modules.Utils import *
|
from Modules.Utils import *
|
||||||
|
|
||||||
def PugCompileList(Pages):
|
def PugCompileList(OutputDir, Pages):
|
||||||
# Pug-cli seems to shit itself with folder paths as input, so we pass ALL the files as arguments
|
# Pug-cli seems to shit itself with folder paths as input, so we pass ALL the files as arguments
|
||||||
Paths = ''
|
Paths = ''
|
||||||
for File, Content, Titles, Meta in Pages:
|
for File, Content, Titles, Meta in Pages:
|
||||||
if File.lower().endswith('.pug'):
|
if File.lower().endswith('.pug'):
|
||||||
Path = 'public/{}'.format(File)
|
Path = f'{OutputDir}/{File}'
|
||||||
WriteFile(Path, Content)
|
WriteFile(Path, Content)
|
||||||
Paths += '"{}" '.format(Path)
|
Paths += f'"{Path}" '
|
||||||
if Paths:
|
if Paths:
|
||||||
os.system('pug -P {} > /dev/null'.format(Paths))
|
os.system(f'pug -P {Paths} > /dev/null')
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
| Copyright (C) 2022, OctoSpacc |
|
| Copyright (C) 2022, OctoSpacc |
|
||||||
| ================================= """
|
| ================================= """
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from Libs import htmlmin
|
from Libs import htmlmin
|
||||||
from Libs.bs4 import BeautifulSoup
|
from Libs.bs4 import BeautifulSoup
|
||||||
from Modules.Config import *
|
from Modules.Config import *
|
||||||
|
@ -21,12 +22,12 @@ def DashifyTitle(Title, 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 '<h{} id="{}">{}</h{}>'.format(Index, DashTitle, Title[Index+1:], Index)
|
return f'<h{Index} id="{DashTitle}">{Title[Index+1:]}</h{Index}>'
|
||||||
elif Type == 'pug':
|
elif Type == 'pug':
|
||||||
NewLine = ''
|
NewLine = ''
|
||||||
Index = Line.find('h')
|
Index = Line.find('h')
|
||||||
NewLine += Line[:Index]
|
NewLine += Line[:Index]
|
||||||
NewLine += "{}(id='{}')".format(Line[Index:Index+2], DashTitle)
|
NewLine += f"{Line[Index:Index+2]}(id='{DashTitle}')"
|
||||||
NewLine += Line[Index+2:]
|
NewLine += Line[Index+2:]
|
||||||
return NewLine
|
return NewLine
|
||||||
|
|
||||||
|
@ -59,16 +60,16 @@ def MakeContentHeader(Meta, Locale, Categories=''):
|
||||||
Header = ''
|
Header = ''
|
||||||
for i in ['CreatedOn', 'EditedOn']:
|
for i in ['CreatedOn', 'EditedOn']:
|
||||||
if Meta[i]:
|
if Meta[i]:
|
||||||
Header += '{} {} \n'.format(Locale[i], Meta[i])
|
Header += f"{Locale[i]}: {Meta[i]} \n"
|
||||||
if Categories:
|
if Categories:
|
||||||
Header += '{}: {} \n'.format(Locale['Categories'], Categories)
|
Header += f"{Locale['Categories']}: {Categories} \n"
|
||||||
return markdown(Header.rstrip())
|
return markdown(Header.rstrip())
|
||||||
|
|
||||||
def MakeCategoryLine(File, Meta):
|
def MakeCategoryLine(File, Meta):
|
||||||
Categories = ''
|
Categories = ''
|
||||||
if Meta['Categories']:
|
if Meta['Categories']:
|
||||||
for i in Meta['Categories']:
|
for i in Meta['Categories']:
|
||||||
Categories += ' [{}]({}{}.html) '.format(i, GetPathLevels(File) + 'Categories/', i)
|
Categories += f" [{i}]({GetPathLevels(File)}Categories/{i}.html) "
|
||||||
return Categories
|
return Categories
|
||||||
|
|
||||||
def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page', Category=None, For='Menu', MarkdownExts=(), MenuStyle='Default'):
|
def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page', Category=None, For='Menu', MarkdownExts=(), MenuStyle='Default'):
|
||||||
|
@ -240,7 +241,7 @@ def MakeListTitle(File, Meta, Titles, Prefer, SiteRoot, BlogName, PathPrefix='')
|
||||||
'{}{}.html'.format(PathPrefix, StripExt(File)))
|
'{}{}.html'.format(PathPrefix, StripExt(File)))
|
||||||
if Meta['Type'] == 'Post':
|
if Meta['Type'] == 'Post':
|
||||||
CreatedOn = Meta['CreatedOn'] if Meta['CreatedOn'] else '?'
|
CreatedOn = Meta['CreatedOn'] if Meta['CreatedOn'] else '?'
|
||||||
Title = '[{}] {}'.format(CreatedOn, Title)
|
Title = f"[{CreatedOn}] {Title}"
|
||||||
return Title
|
return Title
|
||||||
|
|
||||||
def FormatTitles(Titles, Flatten=False):
|
def FormatTitles(Titles, Flatten=False):
|
||||||
|
@ -252,7 +253,7 @@ def FormatTitles(Titles, Flatten=False):
|
||||||
Title = t.lstrip('#')
|
Title = t.lstrip('#')
|
||||||
DashyTitle = DashifyTitle(Title, DashyTitles)
|
DashyTitle = DashifyTitle(Title, DashyTitles)
|
||||||
DashyTitles += [DashyTitle]
|
DashyTitles += [DashyTitle]
|
||||||
Title = '[{}](#{})'.format(Title, DashyTitle)
|
Title = f"[{Title}](#{DashyTitle})"
|
||||||
MDTitles += Heading + Title + '\n'
|
MDTitles += Heading + Title + '\n'
|
||||||
return markdown(MDTitles)
|
return markdown(MDTitles)
|
||||||
|
|
||||||
|
@ -329,6 +330,7 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP
|
||||||
HTML = ReplWithEsc(HTML, '[staticoso:Page:Style]', Meta['Style'])
|
HTML = ReplWithEsc(HTML, '[staticoso:Page:Style]', Meta['Style'])
|
||||||
HTML = ReplWithEsc(HTML, '[staticoso:Page:Content]', Content)
|
HTML = ReplWithEsc(HTML, '[staticoso:Page:Content]', Content)
|
||||||
HTML = ReplWithEsc(HTML, '[staticoso:Page:ContentInfo]', MakeContentHeader(Meta, Locale, MakeCategoryLine(File, Meta)))
|
HTML = ReplWithEsc(HTML, '[staticoso:Page:ContentInfo]', MakeContentHeader(Meta, Locale, MakeCategoryLine(File, Meta)))
|
||||||
|
HTML = ReplWithEsc(HTML, '[staticoso:BuildTime]', datetime.now().strftime('%Y-%m-%d %H:%M'))
|
||||||
HTML = ReplWithEsc(HTML, '[staticoso:Site:Name]', SiteName)
|
HTML = ReplWithEsc(HTML, '[staticoso:Site:Name]', SiteName)
|
||||||
HTML = ReplWithEsc(HTML, '[staticoso:Site:AbsoluteRoot]', SiteRoot)
|
HTML = ReplWithEsc(HTML, '[staticoso:Site:AbsoluteRoot]', SiteRoot)
|
||||||
HTML = ReplWithEsc(HTML, '[staticoso:Site:RelativeRoot]', GetPathLevels(PagePath))
|
HTML = ReplWithEsc(HTML, '[staticoso:Site:RelativeRoot]', GetPathLevels(PagePath))
|
||||||
|
@ -365,7 +367,7 @@ def DoMinifyHTML(HTML):
|
||||||
convert_charrefs=True,
|
convert_charrefs=True,
|
||||||
keep_pre=True)
|
keep_pre=True)
|
||||||
|
|
||||||
def MakeSite(TemplatesText, StaticPartsText, DynamicParts, DynamicPartsText, ConfMenu, GlobalMacros, SiteName, BlogName, SiteTagline, SiteTemplate, SiteDomain, SiteRoot, FolderRoots, SiteLang, Locale, Minify, NoScripts, ImgAltAndTitle, Sorting, MarkdownExts, AutoCategories):
|
def MakeSite(OutputDir, TemplatesText, StaticPartsText, DynamicParts, DynamicPartsText, ConfMenu, GlobalMacros, SiteName, BlogName, SiteTagline, SiteTemplate, SiteDomain, SiteRoot, FolderRoots, SiteLang, Locale, Minify, NoScripts, ImgAltAndTitle, Sorting, MarkdownExts, AutoCategories):
|
||||||
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
||||||
for Ext in FileExtensions['Pages']:
|
for Ext in FileExtensions['Pages']:
|
||||||
for File in Path('Pages').rglob(f"*.{Ext}"):
|
for File in Path('Pages').rglob(f"*.{Ext}"):
|
||||||
|
@ -395,7 +397,7 @@ def MakeSite(TemplatesText, StaticPartsText, DynamicParts, DynamicPartsText, Con
|
||||||
Pages += [[File, Content, Titles, Meta]]
|
Pages += [[File, Content, Titles, Meta]]
|
||||||
for Cat in Meta['Categories']:
|
for Cat in Meta['Categories']:
|
||||||
Categories.update({Cat:''})
|
Categories.update({Cat:''})
|
||||||
PugCompileList(Pages)
|
PugCompileList(OutputDir, Pages)
|
||||||
|
|
||||||
if Categories:
|
if Categories:
|
||||||
print("[I] Generating Category Lists")
|
print("[I] Generating Category Lists")
|
||||||
|
@ -413,7 +415,7 @@ def MakeSite(TemplatesText, StaticPartsText, DynamicParts, DynamicPartsText, Con
|
||||||
MenuStyle='Flat')
|
MenuStyle='Flat')
|
||||||
|
|
||||||
if AutoCategories:
|
if AutoCategories:
|
||||||
Dir = 'public/Categories'
|
Dir = f"{OutputDir}/Categories"
|
||||||
for Cat in Categories:
|
for Cat in Categories:
|
||||||
Exists = False
|
Exists = False
|
||||||
for File in Path(Dir).rglob(str(Cat)+'.*'):
|
for File in Path(Dir).rglob(str(Cat)+'.*'):
|
||||||
|
@ -421,7 +423,7 @@ def MakeSite(TemplatesText, StaticPartsText, DynamicParts, DynamicPartsText, Con
|
||||||
break
|
break
|
||||||
if not Exists:
|
if not Exists:
|
||||||
File = f"Categories/{Cat}.md"
|
File = f"Categories/{Cat}.md"
|
||||||
FilePath = f"public/{File}"
|
FilePath = f"{OutputDir}/{File}"
|
||||||
WriteFile(FilePath, f"""\
|
WriteFile(FilePath, f"""\
|
||||||
// Title: {Cat}
|
// Title: {Cat}
|
||||||
// Type: Page
|
// Type: Page
|
||||||
|
@ -442,7 +444,7 @@ def MakeSite(TemplatesText, StaticPartsText, DynamicParts, DynamicPartsText, Con
|
||||||
|
|
||||||
print("[I] Writing Pages")
|
print("[I] Writing Pages")
|
||||||
for File, Content, Titles, Meta in Pages:
|
for File, Content, Titles, Meta in Pages:
|
||||||
PagePath = 'public/{}.html'.format(StripExt(File))
|
PagePath = f"{OutputDir}/{StripExt(File)}.html"
|
||||||
if File.lower().endswith(FileExtensions['Markdown']):
|
if File.lower().endswith(FileExtensions['Markdown']):
|
||||||
Content = markdown(PagePostprocessor('md', Content, Meta), extensions=MarkdownExts)
|
Content = markdown(PagePostprocessor('md', Content, Meta), extensions=MarkdownExts)
|
||||||
elif File.lower().endswith(('.pug')):
|
elif File.lower().endswith(('.pug')):
|
||||||
|
@ -471,7 +473,7 @@ def MakeSite(TemplatesText, StaticPartsText, DynamicParts, DynamicPartsText, Con
|
||||||
DynamicParts=DynamicParts,
|
DynamicParts=DynamicParts,
|
||||||
DynamicPartsText=DynamicPartsText,
|
DynamicPartsText=DynamicPartsText,
|
||||||
HTMLPagesList=HTMLPagesList,
|
HTMLPagesList=HTMLPagesList,
|
||||||
PagePath=PagePath[len('public/'):],
|
PagePath=PagePath[len(f"{OutputDir}/"):],
|
||||||
Content=Content,
|
Content=Content,
|
||||||
Titles=Titles,
|
Titles=Titles,
|
||||||
Meta=Meta,
|
Meta=Meta,
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
from urllib.parse import quote as URLEncode
|
from urllib.parse import quote as URLEncode
|
||||||
from Modules.Utils import *
|
from Modules.Utils import *
|
||||||
|
|
||||||
def MakeSitemap(Pages, SiteDomain=''):
|
def MakeSitemap(OutputDir, Pages, SiteDomain=''):
|
||||||
Map = ''
|
Map = ''
|
||||||
|
Domain = SiteDomain + '/' if SiteDomain else ''
|
||||||
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
||||||
File = '{}.html'.format(StripExt(File))
|
File = f"{StripExt(File)}.html"
|
||||||
Domain = SiteDomain + '/' if SiteDomain else ' '
|
|
||||||
Map += Domain + URLEncode(File) + '\n'
|
Map += Domain + URLEncode(File) + '\n'
|
||||||
WriteFile('public/sitemap.txt', Map)
|
WriteFile(f"{OutputDir}/sitemap.txt", Map)
|
||||||
|
|
1
TODO
1
TODO
|
@ -1,6 +1,7 @@
|
||||||
- Handle file extensions with any case sensitivity, not just lowercase; currently the bulk of the issue is finding the files on disk
|
- Handle file extensions with any case sensitivity, not just lowercase; currently the bulk of the issue is finding the files on disk
|
||||||
- Test sorting by date for files not starting with date, and dated folders
|
- Test sorting by date for files not starting with date, and dated folders
|
||||||
- Fix arguments - some are only callable from CLI and not Site.ini - make them coherent with INI categories
|
- Fix arguments - some are only callable from CLI and not Site.ini - make them coherent with INI categories
|
||||||
|
- Accept Macros as CLI arguments
|
||||||
- Deprecate FolderRoots (Macros make it redundant)
|
- Deprecate FolderRoots (Macros make it redundant)
|
||||||
- Fix ordering menu in Site.ini (not working for inner pages)
|
- Fix ordering menu in Site.ini (not working for inner pages)
|
||||||
- Fix Python-Markdown is installed problem (to load our modules)
|
- Fix Python-Markdown is installed problem (to load our modules)
|
||||||
|
|
Loading…
Reference in New Issue