added enclosure rel to atom feed for photos; delay the memento lookup for 2 hours from publish; order the latest entries on home by publish date, not by category name

This commit is contained in:
Peter Molnar 2019-08-27 11:39:09 +01:00
parent 0cd5925620
commit 18e67c3733

52
nasg.py
View file

@ -1246,6 +1246,8 @@ class Singular(MarkdownDoc):
return return
if self.is_future: if self.is_future:
return return
if (self.published.timestamp + 7200) > arrow.utcnow().timestamp:
return
logger.info("archive.org .copy is missing for %s", self.name) logger.info("archive.org .copy is missing for %s", self.name)
if len(self.category) and not ( if len(self.category) and not (
settings.args.get("noservices") settings.args.get("noservices")
@ -1301,10 +1303,39 @@ class Singular(MarkdownDoc):
class Home(Singular): class Home(Singular):
def __init__(self, fpath): def __init__(self, fpath):
super().__init__(fpath) super().__init__(fpath)
self.posts = [] self.cdata = {}
self.pdata = {}
def add(self, category, post): def add(self, category, post):
self.posts.append((category.ctmplvars, post.jsonld)) if not len(category.name):
return
if category.name not in self.cdata:
self.cdata[category.name] = category
if category.name not in self.pdata:
self.pdata[category.name] = post
else:
current = arrow.get(self.pdata[category.name].datePublished)
if current > post.published:
return
else:
self.pdata[category.name] = post
return
@property
def posts(self):
flattened = []
order = {}
for cname, post in self.pdata.items():
order[post.published.timestamp] = cname
for mtime in sorted(order.keys(), reverse=True):
category = self.cdata[order[mtime]].ctmplvars
post = self.pdata[order[mtime]].jsonld
flattened.append((category, post))
return flattened
@property @property
def renderdir(self): def renderdir(self):
@ -1811,26 +1842,21 @@ class Category(dict):
fe.link(href=post.url) fe.link(href=post.url)
fe.content(post.html_content, type="CDATA") fe.content(post.html_content, type="CDATA")
# fe.description(post.txt_content, isSummary=True) # fe.description(post.txt_content, isSummary=True)
if post.is_photo:
fe.enclosure(
post.photo.href,
"%d" % post.photo.mime_size,
post.photo.mime_type,
)
elif self.feedformat == "atom": elif self.feedformat == "atom":
fe.link( fe.link(
href=post.url, href=post.url,
rel="alternate", rel="alternate",
type="text/html" type="text/html"
) )
fe.link(
href=post.photo.href,
rel="enclosure",
type=post.photo.mime_type,
)
fe.content(src=post.url, type="text/html") fe.content(src=post.url, type="text/html")
fe.summary(post.summary) fe.summary(post.summary)
if post.is_photo:
fe.enclosure(
post.photo.href,
"%d" % post.photo.mime_size,
post.photo.mime_type,
)
writepath(self.renderfile, fg.atom_str(pretty=True)) writepath(self.renderfile, fg.atom_str(pretty=True))
class Year(object): class Year(object):