gallery.scm (1976B)
1 (define-module (duper builder gallery) 2 #:use-module (haunt artifact) 3 #:use-module (haunt html) 4 #:use-module (haunt post) 5 #:use-module (sxml match) 6 #:use-module (sxml xpath) 7 #:use-module (srfi srfi-1) 8 #:use-module (srfi srfi-26) 9 #:export (gallery)) 10 11 (define (sxml-filter tags) 12 (lambda (lst) 13 (map-union 14 (lambda (node) 15 (cond ((nodeset? node) ((sxml-filter tags) node)) 16 ((and ((node-typeof? '*) node) (memq (car node) tags)) 17 node) 18 (((node-typeof? '*) node) 19 ((sxml-filter tags) ((select-kids (const #t)) node))) 20 (else '()))) 21 lst))) 22 23 (define (default-section post medias) 24 `((hr) 25 (h2 ,(post-title post)) 26 ,@medias)) 27 28 (define* (gallery #:key 29 (file-name "gallery.html") 30 (media-tags '(img video)) 31 (section-template default-section) 32 (title "Gallery") 33 (filter posts/reverse-chronological) 34 (template (lambda (site title body) body))) 35 "Return a builder procedure that renders every images from a list of posts 36 within a single HTML file, eventually wrapped by the TEMPLATE procedure. 37 38 FILE-NAME: The page file name. 39 40 MEDIA-TAGS: This is a list of HTML tags that should be included as media to 41 render in the gallery. 42 43 SECTION: This procedure takes two argument: the post object and a list of SXML 44 nodes corresponding to the medias within this post. 45 46 FILTER: The procedure called to manipulate the posts list before rendering. 47 48 TEMPLATE: This procedure takes three arguments: the site object, the page title 49 string, and an SXML tree of the page body. It returns one value: a new SXML tree 50 representing complete HTML page that presumably wraps the page body." 51 (lambda (site posts) 52 (serialized-artifact file-name 53 (filter-map (lambda (p) 54 (let ((m ((sxml-filter media-tags) 55 (post-sxml p)))) 56 (if (null? m) 57 #f 58 (section-template p m)))) 59 (filter posts)) 60 (lambda (body port) 61 (sxml->html (template site title body) port)))))