mirror of https://gitlab.com/octtspacc/staticoso
Some bad Gemtext patches
This commit is contained in:
parent
e44b4a0d84
commit
5fed1bd330
|
@ -192,7 +192,7 @@ def MakeCategoryLine(Meta, Reserved):
|
||||||
Categories += '[{}]({}{}.html) '.format(i, GetLevels(Reserved['Categories']) + Reserved['Categories'], i)
|
Categories += '[{}]({}{}.html) '.format(i, GetLevels(Reserved['Categories']) + Reserved['Categories'], i)
|
||||||
return Categories
|
return Categories
|
||||||
|
|
||||||
def PatchHTML(Base, PartsText, ContextParts, ContextPartsText, HTMLPagesList, PagePath, Content, Titles, Meta, SiteRoot, FolderRoots, Categories, Locale, Reserved):
|
def PatchHTML(HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesList, PagePath, Content, Titles, Meta, SiteRoot, FolderRoots, Categories, Locale, Reserved):
|
||||||
HTMLTitles = FormatTitles(Titles)
|
HTMLTitles = FormatTitles(Titles)
|
||||||
BodyDescription, BodyImage = '', ''
|
BodyDescription, BodyImage = '', ''
|
||||||
Parse = BeautifulSoup(Content, 'html.parser')
|
Parse = BeautifulSoup(Content, 'html.parser')
|
||||||
|
@ -205,7 +205,7 @@ def PatchHTML(Base, PartsText, ContextParts, ContextPartsText, HTMLPagesList, Pa
|
||||||
Description = GetDescription(Meta, BodyDescription, 'MetaDescription')
|
Description = GetDescription(Meta, BodyDescription, 'MetaDescription')
|
||||||
Image = GetImage(Meta, BodyImage, 'MetaImage')
|
Image = GetImage(Meta, BodyImage, 'MetaImage')
|
||||||
|
|
||||||
for Line in Base.splitlines():
|
for Line in HTML.splitlines():
|
||||||
Line = Line.lstrip().rstrip()
|
Line = Line.lstrip().rstrip()
|
||||||
if Line.startswith('[HTML:ContextPart:') and Line.endswith(']'):
|
if Line.startswith('[HTML:ContextPart:') and Line.endswith(']'):
|
||||||
Path = Line[len('[HTML:ContextPart:'):-1]
|
Path = Line[len('[HTML:ContextPart:'):-1]
|
||||||
|
@ -220,34 +220,36 @@ def PatchHTML(Base, PartsText, ContextParts, ContextPartsText, HTMLPagesList, Pa
|
||||||
Text = ContextPartsText['{}/{}'.format(Path, Part)]
|
Text = ContextPartsText['{}/{}'.format(Path, Part)]
|
||||||
else:
|
else:
|
||||||
Text = ''
|
Text = ''
|
||||||
Base = Base.replace('[HTML:ContextPart:{}]'.format(Path), Text)
|
HTML = HTML.replace('[HTML:ContextPart:{}]'.format(Path), Text)
|
||||||
for i in PartsText:
|
for i in PartsText:
|
||||||
Base = Base.replace('[HTML:Part:{}]'.format(i), PartsText[i])
|
HTML = HTML.replace('[HTML:Part:{}]'.format(i), PartsText[i])
|
||||||
Base = Base.replace('[HTML:Page:LeftBox]', HTMLPagesList)
|
HTML = HTML.replace('[HTML:Page:LeftBox]', HTMLPagesList)
|
||||||
Base = Base.replace('[HTML:Page:RightBox]', HTMLTitles)
|
HTML = HTML.replace('[HTML:Page:RightBox]', HTMLTitles)
|
||||||
Base = Base.replace('[HTML:Page:Title]', Title)
|
HTML = HTML.replace('[HTML:Page:Title]', Title)
|
||||||
Base = Base.replace('[HTML:Page:Description]', Description)
|
HTML = HTML.replace('[HTML:Page:Description]', Description)
|
||||||
Base = Base.replace('[HTML:Page:Image]', Image)
|
HTML = HTML.replace('[HTML:Page:Image]', Image)
|
||||||
Base = Base.replace('[HTML:Page:Path]', PagePath)
|
HTML = HTML.replace('[HTML:Page:Path]', PagePath)
|
||||||
Base = Base.replace('[HTML:Page:Style]', Meta['Style'])
|
HTML = HTML.replace('[HTML:Page:Style]', Meta['Style'])
|
||||||
Base = Base.replace('[HTML:Page:Content]', Content)
|
HTML = HTML.replace('[HTML:Page:Content]', Content)
|
||||||
Base = Base.replace('[HTML:Page:ContentHeader]', MakeContentHeader(Meta, Locale, MakeCategoryLine(Meta, Reserved)))
|
HTML = HTML.replace('[HTML:Page:ContentHeader]', MakeContentHeader(Meta, Locale, MakeCategoryLine(Meta, Reserved)))
|
||||||
Base = Base.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
HTML = HTML.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
||||||
Base = Base.replace('[HTML:Site:RelativeRoot]', GetLevels(PagePath))
|
HTML = HTML.replace('[HTML:Site:RelativeRoot]', GetLevels(PagePath))
|
||||||
for i in FolderRoots:
|
for i in FolderRoots:
|
||||||
Base = Base.replace('[HTML:Folder:{}:AbsoluteRoot]'.format(i), FolderRoots[i])
|
HTML = HTML.replace('[HTML:Folder:{}:AbsoluteRoot]'.format(i), FolderRoots[i])
|
||||||
for i in Categories:
|
for i in Categories:
|
||||||
Base = Base.replace('<span>[HTML:Category:{}]</span>'.format(i), Categories[i])
|
HTML = HTML.replace('<span>[HTML:Category:{}]</span>'.format(i), Categories[i])
|
||||||
|
|
||||||
# TODO: Clean this doubling?
|
# TODO: Clean this doubling?
|
||||||
Content = Content.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
ContentHTML = Content
|
||||||
Content = Content.replace('[HTML:Site:RelativeRoot]', GetLevels(PagePath))
|
ContentHTML = ContentHTML.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
||||||
|
ContentHTML = ContentHTML.replace('[HTML:Site:RelativeRoot]', GetLevels(PagePath))
|
||||||
for i in FolderRoots:
|
for i in FolderRoots:
|
||||||
Content = Content.replace('[HTML:Folder:{}:AbsoluteRoot]'.format(i), FolderRoots[i])
|
ContentHTML = ContentHTML.replace('[HTML:Folder:{}:AbsoluteRoot]'.format(i), FolderRoots[i])
|
||||||
for i in Categories:
|
for i in Categories:
|
||||||
Content = Content.replace('<span>[HTML:Category:{}]</span>'.format(i), Categories[i])
|
ContentHTML = ContentHTML.replace('<span>[HTML:Category:{}]</span>'.format(i), Categories[i])
|
||||||
|
SlimHTML = HTMLPagesList + ContentHTML
|
||||||
|
|
||||||
return Base, Content, Description, Image
|
return HTML, ContentHTML, SlimHTML, Description, Image
|
||||||
|
|
||||||
def OrderPages(Old):
|
def OrderPages(Old):
|
||||||
New = []
|
New = []
|
||||||
|
@ -398,8 +400,8 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
||||||
Content = markdown(Content, extensions=MarkdownExts)
|
Content = markdown(Content, extensions=MarkdownExts)
|
||||||
elif File.endswith('.pug'):
|
elif File.endswith('.pug'):
|
||||||
Content = ReadFile(PagePath)
|
Content = ReadFile(PagePath)
|
||||||
HTML, HTMLContent, Description, Image = PatchHTML(
|
HTML, ContentHTML, SlimHTML, Description, Image = PatchHTML(
|
||||||
Base=TemplatesText[Meta['Template']],
|
HTML=TemplatesText[Meta['Template']],
|
||||||
PartsText=PartsText,
|
PartsText=PartsText,
|
||||||
ContextParts=ContextParts,
|
ContextParts=ContextParts,
|
||||||
ContextPartsText=ContextPartsText,
|
ContextPartsText=ContextPartsText,
|
||||||
|
@ -416,7 +418,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
||||||
if Minify not in ('False', 'None'):
|
if Minify not in ('False', 'None'):
|
||||||
HTML = DoMinify(HTML)
|
HTML = DoMinify(HTML)
|
||||||
WriteFile(PagePath, HTML)
|
WriteFile(PagePath, HTML)
|
||||||
MadePages += [[File, Content, Titles, Meta, HTMLContent, Description, Image]]
|
MadePages += [[File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image]]
|
||||||
|
|
||||||
return MadePages
|
return MadePages
|
||||||
|
|
||||||
|
@ -497,7 +499,7 @@ def Main(Args, FeedEntries):
|
||||||
else:
|
else:
|
||||||
MastodonPosts = []
|
MastodonPosts = []
|
||||||
|
|
||||||
for File, Content, Titles, Meta, HTMLContent, Description, Image in Pages:
|
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
||||||
File = 'public/{}.html'.format(StripExt(File))
|
File = 'public/{}.html'.format(StripExt(File))
|
||||||
Content = ReadFile(File)
|
Content = ReadFile(File)
|
||||||
Post = ''
|
Post = ''
|
||||||
|
@ -513,7 +515,7 @@ def Main(Args, FeedEntries):
|
||||||
|
|
||||||
if Args.GemtextOut:
|
if Args.GemtextOut:
|
||||||
print("[I] Generating Gemtext")
|
print("[I] Generating Gemtext")
|
||||||
GemtextCompileList(Pages)
|
GemtextCompileList(Pages, SiteName)
|
||||||
|
|
||||||
DelTmp()
|
DelTmp()
|
||||||
os.system("cp -R Assets/* public/")
|
os.system("cp -R Assets/* public/")
|
||||||
|
|
|
@ -54,10 +54,10 @@ def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Local
|
||||||
Session = MastodonGetSession(MastodonURL, MastodonToken)
|
Session = MastodonGetSession(MastodonURL, MastodonToken)
|
||||||
Posts = MastodonGetAllLinkPosts(Session, SiteDomain)
|
Posts = MastodonGetAllLinkPosts(Session, SiteDomain)
|
||||||
Pages.sort()
|
Pages.sort()
|
||||||
for File, Content, Titles, Meta, HTMLContent, Description, Image in Pages:
|
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
||||||
if Meta['Type'] == 'Post':
|
if Meta['Type'] == 'Post':
|
||||||
Desc = ''
|
Desc = ''
|
||||||
Parse = BeautifulSoup(HTMLContent, '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 = '{}/{}.html'.format(SiteDomain, StripExt(File))
|
||||||
|
|
|
@ -30,7 +30,7 @@ def MakeFeed(Pages, SiteName, SiteTagline, SiteDomain, MaxEntries, Lang, Minify=
|
||||||
MaxEntries -= 1
|
MaxEntries -= 1
|
||||||
DoPages.reverse()
|
DoPages.reverse()
|
||||||
|
|
||||||
for File, Content, Titles, Meta, HTMLContent, Description, Image in DoPages:
|
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in DoPages:
|
||||||
if Meta['Type'] == 'Post':
|
if Meta['Type'] == 'Post':
|
||||||
Entry = Feed.add_entry()
|
Entry = Feed.add_entry()
|
||||||
File = '{}.html'.format(StripExt(File))
|
File = '{}.html'.format(StripExt(File))
|
||||||
|
@ -43,7 +43,7 @@ def MakeFeed(Pages, SiteName, SiteTagline, SiteDomain, MaxEntries, Lang, Minify=
|
||||||
Entry.title(Meta['Title'] if Meta['Title'] else ' ')
|
Entry.title(Meta['Title'] if Meta['Title'] else ' ')
|
||||||
Entry.description(Description)
|
Entry.description(Description)
|
||||||
Entry.link(href=Link, rel='alternate')
|
Entry.link(href=Link, rel='alternate')
|
||||||
Entry.content(HTMLContent, type='html')
|
Entry.content(ContentHTML, type='html')
|
||||||
if CreatedOn:
|
if CreatedOn:
|
||||||
Entry.pubDate(CreatedOn)
|
Entry.pubDate(CreatedOn)
|
||||||
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'
|
||||||
|
|
|
@ -23,11 +23,16 @@ OpenTags = (
|
||||||
'img')
|
'img')
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def GemtextCompileList(Pages):
|
def GemtextCompileList(Pages, SiteName):
|
||||||
Cmd = ''
|
Cmd = ''
|
||||||
for File, Content, Titles, Meta, HTMLContent, Description, Image in Pages:
|
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
||||||
Src = 'public.gmi/{}.html.tmp'.format(StripExt(File))
|
Src = 'public.gmi/{}.html.tmp'.format(StripExt(File))
|
||||||
WriteFile(Src, HTMLContent.replace('.html', '.gmi')) # TODO: Adjust links properly..
|
if SiteName:
|
||||||
|
SlimHTML = '<h1>' + SiteName + '</h1>' + SlimHTML
|
||||||
|
for i in ('ol', 'ul', 'li'):
|
||||||
|
for j in ('<'+i+'>', '</'+i+'>'):
|
||||||
|
SlimHTML = SlimHTML.replace(j, '')
|
||||||
|
WriteFile(Src, SlimHTML.replace('</a>', '</a><br>').replace('.html', '.gmi')) # TODO: Adjust links properly..
|
||||||
Dst = 'public.gmi/{}.gmi'.format(StripExt(File))
|
Dst = 'public.gmi/{}.gmi'.format(StripExt(File))
|
||||||
Cmd += 'cat "{}" | html2gmi > "{}"; '.format(Src, Dst)
|
Cmd += 'cat "{}" | html2gmi > "{}"; '.format(Src, Dst)
|
||||||
os.system(Cmd)
|
os.system(Cmd)
|
||||||
|
|
Loading…
Reference in New Issue