From 14e694641a6656744429a9fc826003329b6651fe Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Mon, 27 Jul 2020 16:51:04 -0400 Subject: [webmention.js] Handle missing information better. --- haunt/static/image/default-icon.png | Bin 0 -> 2034 bytes haunt/static/js/webmention.js | 28 ++++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 haunt/static/image/default-icon.png diff --git a/haunt/static/image/default-icon.png b/haunt/static/image/default-icon.png new file mode 100644 index 0000000..ffd12bf Binary files /dev/null and b/haunt/static/image/default-icon.png differ diff --git a/haunt/static/js/webmention.js b/haunt/static/js/webmention.js index 7793d7f..2267da8 100644 --- a/haunt/static/js/webmention.js +++ b/haunt/static/js/webmention.js @@ -74,7 +74,7 @@ function makeComment(comment) { "class": "u-photo", "src": comment.url.startsWith("https://lobste.rs/") ? "/static/image/lobsters.png" - : comment.author.photo + : comment.author.photo || "/static/image/default-icon.png" }); let authorName = element("a", { @@ -100,16 +100,32 @@ function makeComment(comment) { let contentContainer = element("div", { "class": "e-content p-name comment-content", }); - contentContainer.textContent = comment.hasOwnProperty("content") - ? comment.content.text - : "[No Text Provided]"; + + if (comment.hasOwnProperty("content")) { + contentContainer.textContent = comment.content.text; + } else { + let em = element("em", {}); + if (comment.hasOwnProperty("wm-property")) { + if ("repost-of" === comment["wm-property"]) { + em.textContent = "Reposted this!"; + } else if ("like-of" === comment["wm-property"]) { + em.textContent = "Favorited this!"; + } else { + em.textContent = "No text provided :("; + } + } else { + em.textContent = "No text provided :("; + } + contentContainer.appendChild(em); + } // Create the metaline section. + let pubTime = comment.published || comment["wm-received"]; let time = element("time", { "class": "dt-published", - "datetime": comment.published + "datetime": pubTime, }); - time.textContent = (new Date(comment.published)).toString(); + time.textContent = (new Date(pubTime)).toString(); let linkBack = element("a", { "class": "u-url", -- cgit v1.3