diff options
| author | Jakob L. Kreuze | 2019-07-20 17:07:39 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze | 2019-07-20 17:07:39 -0400 |
| commit | b4fdc3017b9c05734b92151d7aa2e0353682fc09 (patch) | |
| tree | a056a6a6e379bcae01b22c6dca203218c609cac3 /haunt/jakob/builder/outbox.scm | |
| parent | aed8c20a9488f1ed4f4e316068cbafb07e8676ff (diff) | |
Stage everything. Bleh, I'll commit to a clean history from now on
Diffstat (limited to 'haunt/jakob/builder/outbox.scm')
| -rw-r--r-- | haunt/jakob/builder/outbox.scm | 146 |
1 files changed, 122 insertions, 24 deletions
diff --git a/haunt/jakob/builder/outbox.scm b/haunt/jakob/builder/outbox.scm index 851ed88..8e3a050 100644 --- a/haunt/jakob/builder/outbox.scm +++ b/haunt/jakob/builder/outbox.scm @@ -15,37 +15,135 @@ ;;; <http://www.gnu.org/licenses/>. (define-module (jakob builder outbox) + #:use-module (haunt html) #:use-module (haunt page) + #:use-module (ice-9 format) + #:use-module (ice-9 match) + #:use-module (jakob theme) + #:use-module (jakob utils pagination) + #:use-module (jakob utils sxml) + #:use-module (srfi srfi-9) + #:use-module (srfi srfi-19) #:export (outbox)) ;;; Commentary: ;;; -;;; Implementation of a multi-page Webmention outbox. See -;;; <https://webmention.net/> for details. +;;; [TODO] ;;; ;;; Code: -;; `((doctype "html") -;; (meta (@ (charset "utf-8"))) -;; (title ,title) -;; (div (@ (class "h-entry")) -;; (img (@ (src ,profile-picture) (class "u-photo") (width "40"))) -;; (a (@ (href ,profile-url) (class "u-url p-name")) ,profile-name)) -;; (p "in reply to:" (a (@ (href ,target-url) (class "u-in-reply-to")) -;; ,target-handle)) -;; (p (@ (class "e-content")) ,content) -;; (p (a (@ (href "self") (class "u-url")) -;; (time (@ (datetime ,datetime) (class "dt-published")) -;; ,datetime-pretty)))) +;; Prefix for all pages representing Webmention interactions. +(define %outbox-prefix "/outbox") -;; (define* (htaccess #:key profile-url -;; profile-name -;; profile-picture -;; (comment-dir "webmentions")) -;; "Create a multi-page Webmention outbox, reading comments from COMMENT-DIR." -;; (define contents -;; `(,(if handler-404 -;; (format #f "ErrorDocument 404 ~a" handler-404)))) + +;;; +;;; Profile. +;;; + +(define %h-card + `(div (@ (class "u-author h-card")) + (img (@ (class "u-photo") + (src "/static/image/profile-picture.jpg") + (width "40"))) + (a (@ (class "u-url p-name") + (href "http://jakob.space")) + "Jakob L. Kreuze"))) + + +;;; +;;; Common rendering code. +;;; + +(define (datetime uri date) + `(p (a (@ (class "u-url") (href uri)) + (time (@ (class "dt-published") + (datetime ,(date->string date "~4"))) + ,(date->string date "~B ~e, ~Y"))))) + + +;;; +;;; Record type for replies -- by far, my most frequently-used type of +;;; Webmention response. +;;; + +(define-record-type <reply> + (make-reply content date target-uri target-handle) + reply? + (content reply-content) + (date reply-date) + (target-uri reply-target-uri) + (target-handle reply-target-handle)) + +(define (reply-uri reply) + (let* ((date (date->string (reply-date reply) "~Y-~m-~d-~H:~M:~S")) + (target (reply-target-handle reply)) + (slug (format #f "reply-~a-~a" target date))) + (string-append %outbox-prefix "/" slug ".html"))) + +(define reply + (match-lambda + ((target-uri target-handle date-string content) + (let ((date (string->date date-string "~Y-~m-~dT~H:~M:~S~z"))) + (make-reply content date target-uri target-handle))))) + + +;;; +;;; Reply rendering. +;;; + +(define (render-reply reply) + (let ((content (cons* (car (reply-content reply)) + `(@ (class "e-content")) + (cdr (reply-content reply))))) + `(div (@ (class "h-entry")) + ,%h-card + (p "In reply to: " + (a (@ (class "u-in-reply-to") + (href ,(reply-target-uri reply))) + ,(reply-target-handle reply))) + ,content + ,(datetime (reply-uri reply) (reply-date reply))))) + +(define (render-preview reply) + (let* ((simple-text? (eqv? 'p (car (reply-content reply)))) + (truncated? (and simple-text? + (> (length (cdr (reply-content reply))) 80))) + (preview (if simple-text? + (if truncated? + (format #f "~a..." + (substring (cdr (reply-content reply)) + 0 80)) + (cdr (reply-content reply))) + "[No preview available...]"))) + `(section + (h2 ,(hyperlink + (reply-uri reply) + (format #f "Reply directed towards ~a on ~a" + (reply-target-handle reply) + (date->string (reply-date reply) "~B ~e, ~Y")))) + (p ,preview)))) + +(define (reply->page reply) + (let ((title (format #f "Reply to ~a" (reply-target-handle reply)))) + (make-page (reply-uri reply) + (theme #:title title + ;; #:description (first-paragraph post) + ;; #:keywords (post-ref post 'tags) + #:content (render-reply reply)) + sxml->html))) + + +;;; +;;; Builder. +;;; + +(define (outbox) + (let ((replies (map reply (primitive-load "data/replies.scm")))) + (lambda (site posts) + (append + ;; Permalinks. + (map reply->page replies) -;; (lambda (site posts) -;; (make-page ".htaccess" contents htaccess-writer))) + ;; Outbox listing. + (items->pages render-preview replies + "Webmentions" (string-append %outbox-prefix "/" "index")))))) |