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 | |
| parent | aed8c20a9488f1ed4f4e316068cbafb07e8676ff (diff) | |
Stage everything. Bleh, I'll commit to a clean history from now on
Diffstat (limited to 'haunt/jakob')
| -rw-r--r-- | haunt/jakob/builder/blog.scm | 91 | ||||
| -rw-r--r-- | haunt/jakob/builder/outbox.scm | 146 | ||||
| -rw-r--r-- | haunt/jakob/builder/static-pages.scm | 4 | ||||
| -rw-r--r-- | haunt/jakob/theme.scm | 6 | ||||
| -rw-r--r-- | haunt/jakob/utils/pagination.scm | 103 | ||||
| -rw-r--r-- | haunt/jakob/utils/sxml.scm | 11 |
6 files changed, 260 insertions, 101 deletions
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. @@ -117,54 +119,6 @@ to PREVIOUS-PAGE and NEXT-PAGE." ;;; -;;; 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 @@ ;;; <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")))))) 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) diff --git a/haunt/jakob/theme.scm b/haunt/jakob/theme.scm index 23d3929..3bd60db 100644 --- a/haunt/jakob/theme.scm +++ b/haunt/jakob/theme.scm @@ -32,7 +32,7 @@ ("pingback" "https://webmention.io/jakob.space/xmlrpc") ("pgpkey authn" "/gpg.txt"))) (define %nav-bar-tabs '(("About" "/pages/about.html") - ("Projects" "/pages/projects.html") + ;; ("Projects" "/pages/projects.html") ("Tags" "/tag.html") ("Atom" "/feed.xml"))) @@ -63,7 +63,9 @@ International") ,(hyperlink "http://haunt.dthompson.us/" "Haunt") ", a static site generator written in " ,(hyperlink "https://gnu.org/software/guile" "Guile Scheme") - "."))) + ".") + (p (a (@ (href "/pages/weblabels.html") (rel "jslicense")) + "JavaScript license information")))) (define* (theme #:key (title '()) diff --git a/haunt/jakob/utils/pagination.scm b/haunt/jakob/utils/pagination.scm new file mode 100644 index 0000000..5560685 --- /dev/null +++ b/haunt/jakob/utils/pagination.scm @@ -0,0 +1,103 @@ +;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays@sdf.lonestar.org> +;;; +;;; This program is free software; you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation; either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see +;;; <http://www.gnu.org/licenses/>. + +;;; Commentary: +;;; +;;; Common procedures for splitting up large numbers of items across pages. +;;; +;;; Code: + +(define-module (jakob utils pagination) + #:use-module (haunt html) + #:use-module (haunt page) + #:use-module (ice-9 match) + #:use-module (srfi srfi-1) + #:use-module (jakob theme) + #:use-module (jakob utils) + #:use-module (jakob utils sxml) + #:export (paginate + + render-listing + items->pages)) + +(define %items-per-page 10) + + +;;; +;;; Partitioning. +;;; + +(define* (paginate items #:key (items-per-page %items-per-page)) + "Partition ITEMS into list of no more than ITEMS-PER-PAGE items, returning +lists of the form (index, items)." + (let loop ((index 1) + (lst items) + (result '())) + (if (null? lst) + result + (let ((how-many (min %items-per-page (length lst)))) + (loop (1+ index) + (drop lst how-many) + (cons (list index (take lst how-many)) + result)))))) + + +;;; +;;; Rendering. +;;; + +(define (render-listing content title previous-page next-page) + "Return an SHTML document showing CONTENT, with the header TITLE and links to +PREVIOUS-PAGE and NEXT-PAGE." + `((h1 ,title) + ,@content + (nav + (@ (id "pagination")) + ,@(maybe-list + (when previous-page + (hyperlink previous-page "🢨 Previous Page")) + (when next-page + (hyperlink next-page "Next Page 🢩")))))) + +(define* (items->pages render-item items base-title base-file-name + #:key (items-par-page %items-per-page)) + "Return a list of Haunt pages for ITEMS with no more than ITEMS-PER-PAGE items +to a page, with headers containing BASE-TITLE and output file names beginning +with BASE-FILE-NAME. RENDER-ITEM is a procedure returning a SXML rendering of +the item from ITEMS passed as a parameter." + (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 items) + %items-per-page)) + (index->file-name (1+ index)) + #f))) + (make-page (index->file-name index) + (theme #:title title + #:content + (render-listing (map render-item subset) title + previous-page next-page)) + sxml->html)))) + (paginate items))) diff --git a/haunt/jakob/utils/sxml.scm b/haunt/jakob/utils/sxml.scm index c4ce33d..0bde0fe 100644 --- a/haunt/jakob/utils/sxml.scm +++ b/haunt/jakob/utils/sxml.scm @@ -23,16 +23,21 @@ (define-module (jakob utils sxml) #:export (hyperlink image - stylesheet)) + stylesheet + script)) (define (hyperlink target text) `(a (@ (href ,target)) ,text)) -(define* (image filename #:optional description) - (let ((src (string-append "/static/image/" filename))) +(define* (image file-name #:optional description) + (let ((src (string-append "/static/image/" file-name))) (if description `(img (@ (src ,src) (alt ,description) (title ,description))) `(img (@ (src ,src)))))) (define (stylesheet file-name) `(link (@ (rel "stylesheet") (href ,(format #f "/static/css/~a" file-name))))) + +(define (script file-name) + (let ((src (string-append "/static/js/" file-name))) + `(script (@ (src ,src))))) |