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)
|
||||
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)
|
||||
BodyDescription, BodyImage = '', ''
|
||||
Parse = BeautifulSoup(Content, 'html.parser')
|
||||
|
@ -205,7 +205,7 @@ def PatchHTML(Base, PartsText, ContextParts, ContextPartsText, HTMLPagesList, Pa
|
|||
Description = GetDescription(Meta, BodyDescription, 'MetaDescription')
|
||||
Image = GetImage(Meta, BodyImage, 'MetaImage')
|
||||
|
||||
for Line in Base.splitlines():
|
||||
for Line in HTML.splitlines():
|
||||
Line = Line.lstrip().rstrip()
|
||||
if Line.startswith('[HTML:ContextPart:') and Line.endswith(']'):
|
||||
Path = Line[len('[HTML:ContextPart:'):-1]
|
||||
|
@ -220,34 +220,36 @@ def PatchHTML(Base, PartsText, ContextParts, ContextPartsText, HTMLPagesList, Pa
|
|||
Text = ContextPartsText['{}/{}'.format(Path, Part)]
|
||||
else:
|
||||
Text = ''
|
||||
Base = Base.replace('[HTML:ContextPart:{}]'.format(Path), Text)
|
||||
HTML = HTML.replace('[HTML:ContextPart:{}]'.format(Path), Text)
|
||||
for i in PartsText:
|
||||
Base = Base.replace('[HTML:Part:{}]'.format(i), PartsText[i])
|
||||
Base = Base.replace('[HTML:Page:LeftBox]', HTMLPagesList)
|
||||
Base = Base.replace('[HTML:Page:RightBox]', HTMLTitles)
|
||||
Base = Base.replace('[HTML:Page:Title]', Title)
|
||||
Base = Base.replace('[HTML:Page:Description]', Description)
|
||||
Base = Base.replace('[HTML:Page:Image]', Image)
|
||||
Base = Base.replace('[HTML:Page:Path]', PagePath)
|
||||
Base = Base.replace('[HTML:Page:Style]', Meta['Style'])
|
||||
Base = Base.replace('[HTML:Page:Content]', Content)
|
||||
Base = Base.replace('[HTML:Page:ContentHeader]', MakeContentHeader(Meta, Locale, MakeCategoryLine(Meta, Reserved)))
|
||||
Base = Base.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
||||
Base = Base.replace('[HTML:Site:RelativeRoot]', GetLevels(PagePath))
|
||||
HTML = HTML.replace('[HTML:Part:{}]'.format(i), PartsText[i])
|
||||
HTML = HTML.replace('[HTML:Page:LeftBox]', HTMLPagesList)
|
||||
HTML = HTML.replace('[HTML:Page:RightBox]', HTMLTitles)
|
||||
HTML = HTML.replace('[HTML:Page:Title]', Title)
|
||||
HTML = HTML.replace('[HTML:Page:Description]', Description)
|
||||
HTML = HTML.replace('[HTML:Page:Image]', Image)
|
||||
HTML = HTML.replace('[HTML:Page:Path]', PagePath)
|
||||
HTML = HTML.replace('[HTML:Page:Style]', Meta['Style'])
|
||||
HTML = HTML.replace('[HTML:Page:Content]', Content)
|
||||
HTML = HTML.replace('[HTML:Page:ContentHeader]', MakeContentHeader(Meta, Locale, MakeCategoryLine(Meta, Reserved)))
|
||||
HTML = HTML.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
||||
HTML = HTML.replace('[HTML:Site:RelativeRoot]', GetLevels(PagePath))
|
||||
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:
|
||||
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?
|
||||
Content = Content.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
||||
Content = Content.replace('[HTML:Site:RelativeRoot]', GetLevels(PagePath))
|
||||
ContentHTML = Content
|
||||
ContentHTML = ContentHTML.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
||||
ContentHTML = ContentHTML.replace('[HTML:Site:RelativeRoot]', GetLevels(PagePath))
|
||||
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:
|
||||
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):
|
||||
New = []
|
||||
|
@ -398,8 +400,8 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
|||
Content = markdown(Content, extensions=MarkdownExts)
|
||||
elif File.endswith('.pug'):
|
||||
Content = ReadFile(PagePath)
|
||||
HTML, HTMLContent, Description, Image = PatchHTML(
|
||||
Base=TemplatesText[Meta['Template']],
|
||||
HTML, ContentHTML, SlimHTML, Description, Image = PatchHTML(
|
||||
HTML=TemplatesText[Meta['Template']],
|
||||
PartsText=PartsText,
|
||||
ContextParts=ContextParts,
|
||||
ContextPartsText=ContextPartsText,
|
||||
|
@ -416,7 +418,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
|||
if Minify not in ('False', 'None'):
|
||||
HTML = DoMinify(HTML)
|
||||
WriteFile(PagePath, HTML)
|
||||
MadePages += [[File, Content, Titles, Meta, HTMLContent, Description, Image]]
|
||||
MadePages += [[File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image]]
|
||||
|
||||
return MadePages
|
||||
|
||||
|
@ -497,7 +499,7 @@ def Main(Args, FeedEntries):
|
|||
else:
|
||||
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))
|
||||
Content = ReadFile(File)
|
||||
Post = ''
|
||||
|
@ -513,7 +515,7 @@ def Main(Args, FeedEntries):
|
|||
|
||||
if Args.GemtextOut:
|
||||
print("[I] Generating Gemtext")
|
||||
GemtextCompileList(Pages)
|
||||
GemtextCompileList(Pages, SiteName)
|
||||
|
||||
DelTmp()
|
||||
os.system("cp -R Assets/* public/")
|
||||
|
|
|
@ -54,10 +54,10 @@ def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Local
|
|||
Session = MastodonGetSession(MastodonURL, MastodonToken)
|
||||
Posts = MastodonGetAllLinkPosts(Session, SiteDomain)
|
||||
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':
|
||||
Desc = ''
|
||||
Parse = BeautifulSoup(HTMLContent, 'html.parser')
|
||||
Parse = BeautifulSoup(ContentHTML, 'html.parser')
|
||||
Paragraphs = Parse.p.get_text().split('\n')
|
||||
Read = '...' + Locale['ReadFullPost'] + ':\n'
|
||||
URL = '{}/{}.html'.format(SiteDomain, StripExt(File))
|
||||
|
|
|
@ -30,7 +30,7 @@ def MakeFeed(Pages, SiteName, SiteTagline, SiteDomain, MaxEntries, Lang, Minify=
|
|||
MaxEntries -= 1
|
||||
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':
|
||||
Entry = Feed.add_entry()
|
||||
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.description(Description)
|
||||
Entry.link(href=Link, rel='alternate')
|
||||
Entry.content(HTMLContent, type='html')
|
||||
Entry.content(ContentHTML, type='html')
|
||||
if CreatedOn:
|
||||
Entry.pubDate(CreatedOn)
|
||||
EditedOn = EditedOn if EditedOn else CreatedOn if CreatedOn and not EditedOn else '1970-01-01T00:00+00:00'
|
||||
|
|
|
@ -23,11 +23,16 @@ OpenTags = (
|
|||
'img')
|
||||
"""
|
||||
|
||||
def GemtextCompileList(Pages):
|
||||
def GemtextCompileList(Pages, SiteName):
|
||||
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))
|
||||
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))
|
||||
Cmd += 'cat "{}" | html2gmi > "{}"; '.format(Src, Dst)
|
||||
os.system(Cmd)
|
||||
|
|
Loading…
Reference in New Issue