Working feed

This commit is contained in:
octospacc 2022-06-24 20:00:38 +02:00
parent aaa937f1c9
commit d1445da3d9
2 changed files with 34 additions and 17 deletions

View File

@ -33,7 +33,7 @@ Feel free to experiment with all of this stuff!
- [ ] Differential recompile (to optimize resource waste on non-ephemeral servers) - [ ] Differential recompile (to optimize resource waste on non-ephemeral servers)
- [ ] Hot-recompile (for website development) - [ ] Hot-recompile (for website development)
- [ ] XML sitemap generation - [ ] XML sitemap generation
- [ ] Atom + RSS feed generation for posts - [x] Atom + RSS feed generation for posts
- [x] Generation of website page tree in left sidebar - [x] Generation of website page tree in left sidebar
- [x] Generation of titles in right sidebar with clickable links - [x] Generation of titles in right sidebar with clickable links
- [x] Detections of titles in a page - [x] Detections of titles in a page

View File

@ -12,6 +12,7 @@ import json
import os import os
import shutil import shutil
from ast import literal_eval from ast import literal_eval
from datetime import datetime
from Libs import htmlmin from Libs import htmlmin
from Libs.bs4 import BeautifulSoup from Libs.bs4 import BeautifulSoup
from Libs.feedgen.feed import FeedGenerator from Libs.feedgen.feed import FeedGenerator
@ -430,10 +431,17 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
Categories=Categories, Categories=Categories,
Locale=Locale, Locale=Locale,
Reserved=Reserved) Reserved=Reserved)
if Minify != 'False' and Minify != 'None': if Minify not in ('False', 'None'):
HTML = DoMinify(HTML) HTML = DoMinify(HTML)
WriteFile(PagePath, HTML) WriteFile(PagePath, HTML)
return Pages
def GetFullDate(Date):
if not Date:
return None
return datetime.strftime(datetime.strptime(Date, '%Y-%m-%d'), '%Y-%m-%dT%H:%M+00:00')
def SetReserved(Reserved): def SetReserved(Reserved):
for i in ['Categories']: for i in ['Categories']:
if i not in Reserved: if i not in Reserved:
@ -452,25 +460,33 @@ def SetSorting(Sorting):
Sorting.update({i:Default[i]}) Sorting.update({i:Default[i]})
return Sorting return Sorting
def MakeFeed(SiteName, SiteTagline, SiteDomain, MaxEntries, Lang, Minify=False): def MakeFeed(Pages, SiteName, SiteTagline, SiteDomain, MaxEntries, Lang, Minify=False):
Feed = FeedGenerator() Feed = FeedGenerator()
Feed.id(SiteDomain if SiteDomain else ' ') Link = SiteDomain if SiteDomain else ' '
Feed.id(Link)
Feed.title(SiteName if SiteName else ' ') Feed.title(SiteName if SiteName else ' ')
Feed.link(href=SiteDomain if SiteDomain else ' ', rel='alternate') Feed.link(href=Link, rel='alternate')
Feed.subtitle(SiteTagline if SiteTagline else ' ') Feed.subtitle(SiteTagline if SiteTagline else ' ')
if SiteDomain: if SiteDomain:
Feed.logo('SiteDomain/favicon.png') Feed.logo(SiteDomain.rstrip('/') + '/favicon.png')
Feed.language(Lang) Feed.language(Lang)
#Feed.updated('2022-01-01T00:00+00:00')
#Feed.lastBuildDate('2022-01-01T00:00+00:00')
#Feed.pubDate('2022-01-01T00:00+00:00')
Entry = Feed.add_entry() for File, Content, Titles, Meta in Pages:
Entry.id('PageURL') #print(Meta['Image'])
Entry.title('PageTitle') #print(Meta['Title'])
Entry.link(href='PageURL', rel='alternate') #print(Meta['Description'])
Entry.updated('2022-01-01T00:00+00:00') if Meta['Type'] == 'Post':
Entry.pubDate('2022-01-01T00:00+00:00') Entry = Feed.add_entry()
Link = '{}/{}.html'.format(SiteDomain, StripExt(File)) if SiteDomain else ' '
CreatedOn = GetFullDate(Meta['CreatedOn'])
EditedOn = GetFullDate(Meta['EditedOn'])
Entry.id(Link)
Entry.title(Meta['Title'] if Meta['Title'] else ' ')
Entry.link(href=Link, rel='alternate')
if CreatedOn:
Entry.pubDate(CreatedOn)
EditedOn = EditedOn if EditedOn else CreatedOn if CreatedOn and not EditedOn else '1970-01-01T00:00+00:00'
Entry.updated(EditedOn)
os.mkdir('public/feed') os.mkdir('public/feed')
Feed.atom_file('public/feed/atom.xml', pretty=(not Minify)) Feed.atom_file('public/feed/atom.xml', pretty=(not Minify))
@ -489,7 +505,7 @@ def Main(Args):
if os.path.isdir('Posts'): if os.path.isdir('Posts'):
shutil.copytree('Posts', 'public/Posts') shutil.copytree('Posts', 'public/Posts')
MakeSite( Pages = MakeSite(
TemplatesText=LoadFromDir('Templates', '*.html'), TemplatesText=LoadFromDir('Templates', '*.html'),
PartsText=LoadFromDir('Parts', '*.html'), PartsText=LoadFromDir('Parts', '*.html'),
ContextParts=literal_eval(Args.ContextParts) if Args.ContextParts else {}, ContextParts=literal_eval(Args.ContextParts) if Args.ContextParts else {},
@ -506,12 +522,13 @@ def Main(Args):
if FeedEntries != 0: if FeedEntries != 0:
MakeFeed( MakeFeed(
Pages=Pages,
SiteName=SiteName, SiteName=SiteName,
SiteTagline=SiteTagline, SiteTagline=SiteTagline,
SiteDomain=SiteDomain, SiteDomain=SiteDomain,
MaxEntries=FeedEntries, MaxEntries=FeedEntries,
Lang=SiteLang, Lang=SiteLang,
Minify=True if Args.Minify and Args.Minify != 'False' and Args.Minify != 'None' else False) Minify=True if Args.Minify and Args.Minify not in ('False', 'None') else False)
DelTmp() DelTmp()
os.system("cp -R Assets/* public/") os.system("cp -R Assets/* public/")