commit b60faf5b5302dc218943d952556f0af826c397be
parent e655af75eea31d6b77b791db9c36263e3e6596b5
Author: Adriel Dumas--Jondeau <leirda@disroot.org>
Date: Fri, 21 Jun 2024 22:17:23 +0200
Ajoute un constructeur pour une gallerie photo
Diffstat:
1 file changed, 55 insertions(+), 0 deletions(-)
diff --git a/duper/builder/gallery.scm b/duper/builder/gallery.scm
@@ -0,0 +1,55 @@
+(define-module (duper builder gallery)
+ #:use-module (haunt artifact)
+ #:use-module (haunt html)
+ #:use-module (haunt post)
+ #:use-module (sxml match)
+ #:use-module (sxml xpath)
+ #:use-module (srfi srfi-26)
+ #:export (gallery))
+
+(define (sxml-filter tags)
+ (lambda (lst)
+ (map-union
+ (lambda (node)
+ (cond ((nodeset? node) ((sxml-filter tags) node))
+ ((and ((node-typeof? '*) node) (memq (car node) tags))
+ node)
+ (else '())))
+ lst)))
+
+(define (default-section post medias)
+ `((hr)
+ (h2 ,(post-title post))
+ ,@medias))
+
+(define* (gallery #:key
+ (file-name "gallery.html")
+ (media-tags '(img video))
+ (section-template default-section)
+ (title "Gallery")
+ (filter posts/reverse-chronological)
+ (template (lambda (site title body) body)))
+ "Return a builder procedure that renders every images from a list of posts
+within a single HTML file, eventually wrapped by the TEMPLATE procedure.
+
+FILE-NAME: The page file name.
+
+MEDIA-TAGS: This is a list of HTML tags that should be included as media to
+render in the gallery.
+
+SECTION: This procedure takes two argument: the post object and a list of SXML
+nodes corresponding to the medias within this post.
+
+FILTER: The procedure called to manipulate the posts list before rendering.
+
+TEMPLATE: This procedure takes three arguments: the site object, the page title
+string, and an SXML tree of the page body. It returns one value: a new SXML tree
+representing complete HTML page that presumably wraps the page body."
+ (lambda (site posts)
+ (serialized-artifact file-name
+ (map (lambda (p)
+ (section-template p ((sxml-filter media-tags)
+ (post-sxml p))))
+ (filter posts))
+ (lambda (body port)
+ (sxml->html (template site title body) port)))))