summaryrefslogtreecommitdiff
path: root/haunt/jakob/utils/webmention.scm
diff options
context:
space:
mode:
Diffstat (limited to 'haunt/jakob/utils/webmention.scm')
-rw-r--r--haunt/jakob/utils/webmention.scm43
1 files changed, 30 insertions, 13 deletions
diff --git a/haunt/jakob/utils/webmention.scm b/haunt/jakob/utils/webmention.scm
index f30bb12..713ce39 100644
--- a/haunt/jakob/utils/webmention.scm
+++ b/haunt/jakob/utils/webmention.scm
@@ -27,6 +27,11 @@
#:export (render-comment-view
fetch-webmentions))
+(define (wm-not-null? value)
+ (and value
+ (not (eqv? 'null value))
+ (not (string= "" value))))
+
(define (format-comment webmention)
"Format `webmention', an alist, as SXML for a comment-type interaction"
(define (strip uri)
@@ -38,8 +43,16 @@
uri)))
(let* ((author (assoc-ref webmention "author"))
(author-name (assoc-ref author "name"))
- (author-photo (assoc-ref author "photo"))
(author-url (assoc-ref author "url"))
+ (author-url
+ (if (wm-not-null? author-url)
+ author-url
+ (assoc-ref webmention "wm-source")))
+ (author-photo (assoc-ref author "photo"))
+ (author-photo
+ (cond ((string-prefix? "https://lobste.rs/" author-url) "/static/image/lobsters.png")
+ ((wm-not-null? author-photo) author-photo)
+ (else "/static/image/default-icon.png")))
(content (assoc-ref webmention "content"))
(content-text (assoc-ref content "text"))
(published-time (assoc-ref webmention "published"))
@@ -51,10 +64,7 @@
(alt "Webmention logo")
(src "/static/image/webmention-logo.png")))
(div (@ (class "p-author h-card author"))
- (img (@ (class "u-photo")
- (src ,(if (string-prefix? author-url "https://lobste.rs/")
- "/static/image/lobsters.png"
- (or author-photo "/static/image/default-icon.png")))))
+ (img (@ (class "u-photo") (src ,author-photo)))
(a (@ (class "p-name u-url")
(href ,author-url))
,author-name)
@@ -76,19 +86,26 @@
"Format `webmention', an alist, as SXML for a rich interaction without content"
(let* ((author (assoc-ref webmention "author"))
(author-name (assoc-ref author "name"))
+ (author-url (assoc-ref author "url"))
+ (author-url
+ (if (wm-not-null? author-url)
+ author-url
+ (assoc-ref webmention "wm-source")))
(author-photo (assoc-ref author "photo"))
- (author-url (assoc-ref author "url")))
+ (author-photo
+ (cond ((string-prefix? "https://lobste.rs/" author-url) "/static/image/lobsters.png")
+ ((wm-not-null? author-photo) author-photo)
+ (else "/static/image/default-icon.png"))))
`(li (@ (class "p-comment h-cite interaction comment-source-webmention"))
(a (@ (href ,author-url))
- (img (@ (class "u-photo")
- (src ,(if (string-prefix? author-url "https://lobste.rs/")
- "/static/image/lobsters.png"
- (or author-photo "/static/image/default-icon.png"))))))
+ (img (@ (class "u-photo") (src ,author-photo))))
(div (@ (class "e-content p-name comment-content"))
(em
,(match (assoc-ref webmention "wm-property")
("repost-of" "Reposted this!")
("like-of" "Favorited this!")
+ ("bookmark-of" "Bookmarked this!")
+ ("mention-of" "Mentioned this!")
(_ "[No Text Provided]"))))
(img (@ (class "comment-source-identifier")
(alt "Webmention logo")
@@ -98,8 +115,8 @@
"Render `response', the output of `fetch-webmentions', as SXML"
(vector->list
(vector-map (lambda (_ x)
- (if (and (assoc-ref x "wm-property")
- (member (assoc-ref x "wm-property") '("in-reply-to" "mention-of")))
+ (if (and (assoc-ref x "content")
+ (not (string= (assoc-ref x "wm-property") "repost-of")))
(format-comment x)
(format-interaction x)))
(assoc-ref response "children"))))
@@ -112,7 +129,7 @@
(format #f "target[]=~a~a.html" pre slug))
prefixes))
(url (format #f "https://webmention.io/api/mentions.jf2?per-page=200&page=0&~a"
- (string-join targets-queries "&"))))
+ (string-join target-queries "&"))))
(receive (response-status response-body)
(http-request url)
(call-with-input-string (bytevector->string response-body "UTF-8") json->scm))))