webmention added to ping fed.brid.gy and brid.gy/flickr the proper way

This commit is contained in:
Peter Molnar 2019-02-03 16:40:34 +00:00
parent d19efb6c68
commit e730f53da8

80
nasg.py
View file

@ -155,13 +155,14 @@ class AQ:
consumer = asyncio.ensure_future(self.consume()) consumer = asyncio.ensure_future(self.consume())
self.loop.run_until_complete(consumer) self.loop.run_until_complete(consumer)
class Webmention(object): class Webmention(object):
def __init__(self, parent): def __init__(self, source, target, dpath, mtime=0):
self.dpath = os.path.dirname(parent.fpath) self.dpath = dpath
self.source = parent.url self.source = source
self.target = parent.is_reply self.target = target
self.mtime = parent.mtime if not mtime:
mtime = arrow.utcnow().timestamp
self.mtime = mtime
@property @property
def fpath(self): def fpath(self):
@ -572,8 +573,28 @@ class Singular(MarkdownDoc):
@property @property
def to_ping(self): def to_ping(self):
urls = [] urls = []
w = Webmention(
self.url,
'https://fed.brid.gy',
os.path.dirname(self.fpath),
self.dt
)
urls.append(w)
if self.is_reply: if self.is_reply:
w = Webmention(self) w = Webmention(
self.url,
self.is_reply,
os.path.dirname(self.fpath),
self.dt
)
urls.append(w)
elif self.is_photo:
w = Webmention(
self.url,
'https://brid.gy/publish/flickr',
os.path.dirname(self.fpath),
self.dt
)
urls.append(w) urls.append(w)
return urls return urls
@ -654,6 +675,47 @@ class Singular(MarkdownDoc):
}) })
return event return event
@cached_property
def jsonld(self):
r = {
"@context": "http://schema.org",
"@type": "BlogPosting",
"headline": self.title,
"url": self.url,
"mainEntityOfPage": self.url,
"articleBody": self.html_content,
"description": self.html_summary,
"dateModified": self.published.format(settings.dateformat.get('iso')),
"datePublished": self.published.format(settings.dateformat.get('iso')),
"license": self.licence,
"image": settings.author.get('avatar'),
"author": {
"@context": "http://schema.org",
"@type": "Person",
"image": settings.author.get('avatar'),
"url": settings.author.get('url'),
"name": settings.author.get('name'),
"email": settings.author.get('url'),
},
"publisher": {
"@context": "http://schema.org",
"@type": "Organization",
"logo": {
"@context": "http://schema.org",
"@type": "ImageObject",
"url": settings.author.get('avatar'),
},
"url": settings.author.get('url'),
"name": settings.author.get('name'),
"email": settings.author.get('url'),
},
}
if (self.is_photo):
r.update({
'image': self.enclosure.get('url'),
})
return json.dumps(r)
@cached_property @cached_property
def tmplvars(self): def tmplvars(self):
v = { v = {
@ -678,6 +740,7 @@ class Singular(MarkdownDoc):
'review': self.review, 'review': self.review,
'has_code': self.has_code, 'has_code': self.has_code,
'event': self.event, 'event': self.event,
'is_photo': self.is_photo,
} }
if (self.is_photo): if (self.is_photo):
v.update({ v.update({
@ -775,6 +838,7 @@ class Singular(MarkdownDoc):
'tips': settings.tips, 'tips': settings.tips,
}) })
writepath(self.renderfile, r) writepath(self.renderfile, r)
#writepath(self.renderfile.replace('.html', '.json'), self.jsonld)
class Home(Singular): class Home(Singular):
@ -859,7 +923,7 @@ class WebImage(object):
'caption': self.caption, 'caption': self.caption,
'exif': self.exif, 'exif': self.exif,
'is_photo': self.is_photo, 'is_photo': self.is_photo,
'is_mainimg': self.is_mainimg, #'is_mainimg': self.is_mainimg,
} }
def __str__(self): def __str__(self):