From b4fdc3017b9c05734b92151d7aa2e0353682fc09 Mon Sep 17 00:00:00 2001
From: Jakob L. Kreuze
Date: Sat, 20 Jul 2019 17:07:39 -0400
Subject: Stage everything. Bleh, I'll commit to a clean history from now on
---
haunt/jakob/builder/blog.scm | 91 +++++----------------
haunt/jakob/builder/outbox.scm | 150 +++++++++++++++++++++++++++++------
haunt/jakob/builder/static-pages.scm | 4 +-
3 files changed, 147 insertions(+), 98 deletions(-)
(limited to 'haunt/jakob/builder')
diff --git a/haunt/jakob/builder/blog.scm b/haunt/jakob/builder/blog.scm
index f8a8d6e..7457010 100644
--- a/haunt/jakob/builder/blog.scm
+++ b/haunt/jakob/builder/blog.scm
@@ -23,6 +23,7 @@
#:use-module (ice-9 match)
#:use-module (jakob theme)
#:use-module (jakob utils)
+ #:use-module (jakob utils pagination)
#:use-module (jakob utils sxml)
#:use-module (jakob utils tags)
#:use-module (srfi srfi-1)
@@ -56,7 +57,21 @@
(post-ref post 'tags))
", "))
(article
- ,(post-sxml post))))
+ ,(post-sxml post))
+ (section
+ (@ (id "webmention"))
+ (h2 ,(hyperlink "https://indieweb.org/Webmention" "Webmentions")
+ " for this Page")
+ (ul (@ (id "webmention-container")))
+ (form
+ (@ (action "https://webmention.io/jakob.space/webmention")
+ (method "post"))
+ (label "Have you written a "
+ ,(hyperlink "https://indieweb.org/responses" "response")
+ " to this? Let me know the URL:")
+ (input (@ (name "source") (type "url")))
+ (input (@ (value "Send Webmention") (type "submit"))))
+ ,(script "webmention.js"))))
(define (render-preview post)
"Return the SHTML for a preview of POST."
@@ -77,22 +92,9 @@
(p ,(first-paragraph post))
,(hyperlink (or crosspost-uri local-uri) "read more 🢩"))))
-(define (render-listing posts title previous-page next-page)
- "Return SHTML presenting previews for POSTS, with the header TITLE and links
-to PREVIOUS-PAGE and NEXT-PAGE."
- `((h1 ,title)
- ,@(map render-preview posts)
- (nav
- (@ (id "pagination"))
- ,@(maybe-list
- (when previous-page
- (hyperlink previous-page "🢨 Previous Page"))
- (when next-page
- (hyperlink next-page "Next Page 🢩"))))))
-
;;;
-;;; Creation of permalink pages for individual posts.
+;;; Creation of permalink pages for individual lposts.
;;;
;; Subdirectory for permalink pages.
@@ -115,54 +117,6 @@ to PREVIOUS-PAGE and NEXT-PAGE."
#:content (render-article post))
sxml->html))
-
-;;;
-;;; Implementation of pagination.
-;;;
-
-(define %posts-per-page 10)
-
-(define* (paginate posts #:optional (posts-per-page %posts-per-page))
- "Partition POSTS into list of no more than POSTS-PER-PAGE posts, of the
-form (index, posts)."
- (let loop ((index 1)
- (lst posts)
- (result '()))
- (if (null? lst)
- result
- (let ((how-many (min %posts-per-page (length lst))))
- (loop (1+ index)
- (drop lst how-many)
- (cons (list index (take lst how-many))
- result))))))
-
-(define (post-list->pages base-title base-file-name posts)
- "Return a list of Haunt pages for POSTS, with headers containing BASE-TITLE
-and output file names beginning with BASE-FILE-NAME."
- (define (index->file-name index)
- (if (= index 1)
- (format #f "~a.html" base-file-name)
- (format #f "~a-~a.html" base-file-name index)))
- (map (match-lambda
- ((index subset)
- (let ((title (if (= index 1)
- base-title
- (format #f "~a — Page ~a" base-title index)))
- (previous-page (if (>= (1- index) 1)
- (index->file-name (1- index))
- #f))
- (next-page (if (<= (1+ index) (ceiling/ (length posts)
- %posts-per-page))
- (index->file-name (1+ index))
- #f)))
- (make-page (index->file-name index)
- (theme #:title title
- #:content
- (render-listing subset title
- previous-page next-page))
- sxml->html))))
- (paginate posts)))
-
;;;
;;; Navigation based on post tags.
@@ -176,9 +130,9 @@ and output file names beginning with BASE-FILE-NAME."
only the posts tagged with that tag."
(flat-map (match-lambda
((tag . posts)
- (post-list->pages (format #f "Posts tagged as \"~a\"" tag)
- (tag-uri %tag-prefix tag "")
- posts)))
+ (items->pages render-preview posts
+ (format #f "Posts tagged as \"~a\"" tag)
+ (tag-uri %tag-prefix tag ""))))
(group-by-tag posts (cut post-ref <> 'tags))))
(define (all-tags posts)
@@ -210,9 +164,8 @@ of the 'post' objects associated with the site."
(map post->page posts)
;; Main post navigation.
- (post-list->pages
- "Recent Posts" "index"
- (posts/reverse-chronological posts))
+ (items->pages render-preview (posts/reverse-chronological posts)
+ "Recent Posts" "index")
;; Tag-based navigation.
(list (all-tags posts))
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 @@
;;; .
(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
-;;; 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))))
-
-;; (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))))
-
-;; (lambda (site posts)
-;; (make-page ".htaccess" contents htaccess-writer)))
+;; Prefix for all pages representing Webmention interactions.
+(define %outbox-prefix "/outbox")
+
+
+;;;
+;;; 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
+ (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)
+
+ ;; Outbox listing.
+ (items->pages render-preview replies
+ "Webmentions" (string-append %outbox-prefix "/" "index"))))))
diff --git a/haunt/jakob/builder/static-pages.scm b/haunt/jakob/builder/static-pages.scm
index 9089789..e869b94 100644
--- a/haunt/jakob/builder/static-pages.scm
+++ b/haunt/jakob/builder/static-pages.scm
@@ -34,9 +34,7 @@
file-name))
(name (first (string-split (basename dest) #\.)))
(sxml (primitive-load file-name))
- ;; (contents (with-layout theme site name sxml))
- (contents sxml)
- )
+ (contents sxml))
(cons (make-page dest contents sxml->html) memo)))
(define (noop file-name stat result)
--
cgit v1.3