From 634d852dd5c7e1f4bbf127c3275e2f13ea77e4ff Mon Sep 17 00:00:00 2001 From: Peter Molnar Date: Tue, 28 May 2019 14:27:34 +0200 Subject: [PATCH] - re-added oembed - symbol cleanup - re-added tip list - minibanners are hidden at the bottom for now --- nasg.py | 79 ++++++++++++++++++++++++++++++++++---- settings.py | 59 ++++++++++++++++++---------- templates/Singular.j2.html | 2 + templates/base.j2.html | 19 +++++++++ templates/style.css | 14 ++++++- templates/symbols.svg | 5 ++- 6 files changed, 148 insertions(+), 30 deletions(-) diff --git a/nasg.py b/nasg.py index 1cc03b5..f98d570 100644 --- a/nasg.py +++ b/nasg.py @@ -32,6 +32,7 @@ import frontmatter from feedgen.feed import FeedGenerator from slugify import slugify import requests +import lxml.etree as etree from pandoc import PandocMD2HTML, PandocMD2TXT, PandocHTML2TXT from meta import Exif @@ -907,6 +908,53 @@ class Singular(MarkdownDoc): self.content, ]) + @cached_property + def oembed_xml(self): + oembed = etree.Element("oembed", version="1.0") + xmldoc = etree.ElementTree(oembed) + for k, v in self.oembed_json.items(): + x = etree.SubElement(oembed, k) + t = "%s" % (v) + if "html" == k: + x.text = etree.CDATA(t) + else: + x.text = t + s = etree.tostring( + xmldoc, + encoding='utf-8', + xml_declaration=True, + pretty_print=True + ) + return s + + @cached_property + def oembed_json(self): + r = { + "version": "1.0", + "url": self.url, + "provider_name": settings.site.name, + "provider_url": settings.site.url, + "author_name": settings.author.name, + "author_url": settings.author.url, + "title": self.title, + "type": "link", + "html": self.html_content, + } + img = None + if self.is_photo: + img = self.photo + elif not self.is_photo and len(self.images): + img = list(self.images.values())[0] + if img: + r.update({ + "type": "rich", + "thumbnail_url": img.jsonld.thumbnail.url, + "thumbnail_width": img.jsonld.thumbnail.width, + "thumbnail_height": img.jsonld.thumbnail.height + }) + return r + + async def copyfiles(self): exclude = [ '.md', @@ -916,7 +964,8 @@ class Singular(MarkdownDoc): '.ping', '.url', '.del', - '.copy'] + '.copy' + ] files = glob.glob( os.path.join( os.path.dirname(self.fpath), @@ -974,6 +1023,16 @@ class Singular(MarkdownDoc): json.dumps(j, indent=4, ensure_ascii=False) ) del(j) + # oembed + writepath( + os.path.join(self.renderdir, 'oembed.json'), + json.dumps(self.oembed_json, indent=4, ensure_ascii=False) + ) + writepath( + os.path.join(self.renderdir, 'oembed.xml'), + self.oembed_xml + ) + class Home(Singular): def __init__(self, fpath): @@ -2196,6 +2255,16 @@ class WebmentionIO(object): # logger.error('failed to query granary.io: %s', e) # pass +def dat(): + for url in settings.site.sameAs: + if "dat://" in url: + p = os.path.join(settings.paths.build, '.well-known') + if not os.path.isdir(p): + os.makedirs(p) + p = os.path.join(settings.paths.build, '.well-known', 'dat') + if not os.path.exists(p): + writepath(p, "%s\nTTL=3600" % (url)) + def make(): start = int(round(time.time() * 1000)) @@ -2301,12 +2370,8 @@ def make(): continue cp(e, t) - # ... - #for url in settings.site.sameAs: - #if "dat://" in url: - #p = os.path.join(settings.paths.build, '.well-known', 'dat') - #if not os.path.exists(p): - #writepath(p, "%s\nTTL=3600" % (url)) + # dat data + dat() end = int(round(time.time() * 1000)) logger.info('process took %d ms' % (end - start)) diff --git a/settings.py b/settings.py index 8ba949c..d83cf72 100644 --- a/settings.py +++ b/settings.py @@ -48,9 +48,9 @@ site = struct({ "name": "petermolnar.net", "image": "https://petermolnar.net/favicon.ico", "license": "https://spdx.org/licenses/%s.html" % (licence['_default']), - #"sameAs": [ - #"dat://8d03735af11d82fff82028e0f830f9ac470f5e9fbe10ab5eb6feb877232714a2" - #], + "sameAs": [ + "dat://7efecc3c33baf69d6fecf801e15ede92b369f4944f766489b156263119220939" + ], "author": { "@context": "http://schema.org", "@type": "Person", @@ -64,6 +64,7 @@ site = struct({ "xmpp:mail@petermolnar.net", "https://wa.me/447592011721", "https://t.me/petermolnar", + "https://twitter.com/petermolnar" ], "follows": "https://petermolnar.net/following.opml" }, @@ -93,24 +94,30 @@ site = struct({ "url": "https://petermolnar.net/follow/", "name": "follow" }, - #{ - #"@context": "http://schema.org", - #"@type": "DonateAction", - #"description": "Monzo (only in the UK or via Google Pay)", - #"name": "monzo", - #"price": "3GBP", - #"url": "https://monzo.me/petermolnar/3", - #"recipient": author - #}, - #{ - #"@context": "http://schema.org", - #"@type": "DonateAction", - #"description": "Paypal", - #"name": "paypal", - #"price": "3GBP", - #"url": "https://paypal.me/petermolnar/3GBP", - #"recipient": author - #} + { + "@context": "http://schema.org", + "@type": "DonateAction", + "description": "Monzo", + "name": "monzo", + "url": "https://monzo.me/petermolnar/", + "recipient": author + }, + { + "@context": "http://schema.org", + "@type": "DonateAction", + "description": "Paypal", + "name": "paypal", + "url": "https://paypal.me/petermolnar/", + "recipient": author + }, + { + "@context": "http://schema.org", + "@type": "DonateAction", + "description": "Cash App", + "name": "cash", + "url": "https://cash.app/%C2%A3pmlnr", + "recipient": author + } ] }) @@ -184,6 +191,16 @@ photo = struct({ 'earlyyears': 2014 }) +#symlinks = { + #'files/a-view-from-barbican-1280x720.jpg': 'a-view-from-barbican/a-view-from-barbican_b.jpg', + #'files/hills_from_beachy_head-540x226.jpg': 'hills-from-beachy-head/hills-from-beachy-head.jpg', + #'files/seven_sisters_from_beachy_head-540x304.jpg': 'seven-sisters-from-beachy-head/seven-sisters-from-beachy-head.jpg', + #'files/the_countryside-540x304.jpg': 'the-countryside/the-countryside.jpg', + #'files/MGP0538-540x358.jpg': '', + #'files/IMGP0539-540x358.jpg': '', + #'files/IMGP0538-540x358.jpg': '', +#} + tmpdir = os.path.join(gettempdir(),'nasg') if not os.path.isdir(tmpdir): os.makedirs(tmpdir) diff --git a/templates/Singular.j2.html b/templates/Singular.j2.html index eb3bf87..d5c11fc 100644 --- a/templates/Singular.j2.html +++ b/templates/Singular.j2.html @@ -10,6 +10,8 @@ + + diff --git a/templates/base.j2.html b/templates/base.j2.html index 3058b74..28651f3 100644 --- a/templates/base.j2.html +++ b/templates/base.j2.html @@ -133,6 +133,24 @@ +
+ Leave me a tip! + +
+