From 3a8f3c3dac0151436a8400de9837173fdbef93b7 Mon Sep 17 00:00:00 2001 From: Jakob L. Kreuze Date: Sat, 11 May 2019 16:07:42 -0400 Subject: Implement per-page webmention inboxes --- haunt/js/webmention.js | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/haunt/js/webmention.js b/haunt/js/webmention.js index 5986628..085f525 100644 --- a/haunt/js/webmention.js +++ b/haunt/js/webmention.js @@ -17,14 +17,24 @@ * . */ -// TODO: Page-specific comments. -// TODO: Build up from aliases, etc. -const REFURI = "jakob.space"; -const APIURI = [ - "https://webmention.io/api/mentions.jf2?", - `target[]=http://${REFURI}&`, - `&target[]=https://${REFURI}` -].join(""); +function buildApiUri() { + const snip = /https?:\/\/.*?\//.exec(window.location.href); + const page = window.location.href.substring(snip[0].length); + + // TODO: Build up from aliases, etc. + const aliases = [page]; + + return Array.concat( + ["https://webmention.io/api/mentions.jf2?"], + aliases.flatMap((alias) => { + const ref = "jakob.space"; + return [ + `target[]=http://${ref}/${alias}`, + `target[]=https://${ref}/${alias}` + ]; + }).join("&") + ).join(""); +} function getData(url, callback) { if (fetch) { @@ -121,3 +131,10 @@ function makeComment(comment) { return wrapper; } + +getData(buildApiUri(), (json) => { + json.children + .map(makeComment) + .forEach((elem) => { + document.getElementById("webmention-container").appendChild(elem); + })}); -- cgit v1.3