diff --git a/nasg.py b/nasg.py index 40683bb..ca27f40 100644 --- a/nasg.py +++ b/nasg.py @@ -128,6 +128,8 @@ def writepath(fpath, content, mtime=0): with open(fpath, mode) as f: logger.info("writing file %s", fpath) f.write(content) + if mtime > 0: + os.utime(fpath, (mtime, mtime)) def maybe_copy(source, target): @@ -240,15 +242,14 @@ class Gone(object): return {"source": self.source} async def render(self): - """ this is disabled for now """ - return - - # if self.exists: - # return - # logger.info("rendering %s to %s", self.__class__, self.renderfile) - # writepath( - # self.renderfile, J2.get_template(self.template).render() - # ) + if self.exists: + return + logger.info( + "rendering %s to %s", self.__class__, self.renderfile + ) + writepath( + self.renderfile, J2.get_template(self.template).render() + ) class Redirect(Gone): @@ -2325,23 +2326,38 @@ class WebmentionIO(object): urlparse(webmention.get("target")).path.lstrip("/") )[0] + author = webmention.get("data", {}).get("author", None) + if not author: + logger.error( + "missing author info on webmention; skipping; webmention data is: %s", + webmention.get("source"), + ) + return + # ignore selfpings if slug == settings.site.get("name"): return + elif not len(slug): + logger.error( + "couldn't find post for incoming webmention: %s", + webmention.get("source"), + ) + fdir = glob.glob( os.path.join(settings.paths.get("content"), "*", slug) ) + if not len(fdir): logger.error( "couldn't find post for incoming webmention: %s", - webmention, + webmention.get("source"), ) return elif len(fdir) > 1: logger.error( "multiple posts found for incoming webmention: %s", - webmention, + webmention.get("source"), ) return @@ -2354,7 +2370,10 @@ class WebmentionIO(object): author = webmention.get("data", {}).get("author", None) if not author: - logger.error("missing author info on webmention; skipping") + logger.error( + "missing author info on webmention: %s", + webmention, + ) return meta = { "author": { @@ -2377,7 +2396,7 @@ class WebmentionIO(object): pass r = "---\n%s\n---\n\n%s\n" % (utfyamldump(meta), txt) - writepath(fpath, r) + writepath(fpath, r, mtime=dt.timestamp) def run(self): webmentions = requests.get(self.url, params=self.params) @@ -2483,10 +2502,12 @@ def make(): # make gone and redirect arrays for PHP for e in glob.glob(os.path.join(content, "*", "*.del")): post = Gone(e) + queue.put(post.render()) rules.add_gone(post.source) for e in glob.glob(os.path.join(content, "*", "*.url")): post = Redirect(e) rules.add_redirect(post.source, post.target) + queue.put(post.render()) # render 404 fallback PHP queue.put(rules.render()) diff --git a/settings.py b/settings.py index 86648ed..ce5f4cc 100644 --- a/settings.py +++ b/settings.py @@ -147,11 +147,11 @@ menu = nameddict( meta = nameddict( { "webmention": "https://webmention.io/petermolnar.net/webmention", - "pingback": "https://webmention.io/petermolnar.net/xmlrpc", + #"pingback": "https://webmention.io/petermolnar.net/xmlrpc", "hub": "https://petermolnar.superfeedr.com/", "authorization_endpoint": "https://indieauth.com/auth", "token_endpoint": "https://tokens.indieauth.com/token", - "micropub": "https://petermolnar.net/micropub.php", + "micropub": "https://hooks.zapier.com/hooks/catch/3982452/o3hpw1x/", #'microsub': 'https://aperture.p3k.io/microsub/83' } ) diff --git a/templates/Redirect.j2.html b/templates/Redirect.j2.html index 4509b3a..49aa0e3 100644 --- a/templates/Redirect.j2.html +++ b/templates/Redirect.j2.html @@ -3,7 +3,7 @@
- +