diff options
| author | Jakob L. Kreuze | 2019-05-11 16:07:42 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze | 2019-05-11 16:07:42 -0400 |
| commit | 3a8f3c3dac0151436a8400de9837173fdbef93b7 (patch) | |
| tree | 71fd185a854d71819079ae6e2e510e5af7fae163 /haunt/js/webmention.js | |
| parent | 9e0edbe4140753ea739f022c4847837a7a1f373c (diff) | |
Implement per-page webmention inboxes
Diffstat (limited to 'haunt/js/webmention.js')
| -rw-r--r-- | haunt/js/webmention.js | 33 |
1 files 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 @@ * <http://www.gnu.org/licenses/>. */ -// 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); + })}); |