2022-07-22 15:11:39 +00:00
|
|
|
(define (flatten l)
|
|
|
|
(cond
|
|
|
|
((not (list? l)) l)
|
|
|
|
((null? l) '())
|
|
|
|
((list? (car l)) (append (flatten (car l)) (flatten (cdr l))))
|
|
|
|
(#t (cons (car l) (flatten (cdr l))))))
|
|
|
|
|
2022-07-22 21:29:27 +00:00
|
|
|
(define (file-tree path)
|
2022-07-22 15:11:39 +00:00
|
|
|
(cond
|
|
|
|
((file-directory? path)
|
2022-07-22 21:29:27 +00:00
|
|
|
(map (lambda (item) (file-tree (string-append path "/" item))) (directory-list path)))
|
2022-07-22 15:11:39 +00:00
|
|
|
(#t path)))
|
|
|
|
|
2022-07-22 21:29:27 +00:00
|
|
|
(define (file-list path) (sort string<=? (flatten (file-tree path))))
|
|
|
|
|
2022-07-22 15:11:39 +00:00
|
|
|
(define (string-suffix s n)
|
|
|
|
(let ([strlen (string-length s)])
|
|
|
|
(substring s (- strlen n) strlen)))
|
|
|
|
|
2022-07-22 21:29:27 +00:00
|
|
|
(define (filter-ext fl ext)
|
|
|
|
(filter
|
|
|
|
(lambda (filename) (string=? ext (string-suffix filename (string-length ext))))
|
|
|
|
fl))
|
|
|
|
|
|
|
|
(define (jpg path) (filter-ext (file-list path) ".JPG"))
|
|
|
|
(define (webp path) (filter-ext (file-list path) ".webp"))
|
|
|
|
|
|
|
|
(define convert "/nix/store/rxxvsvf5p41p83k43cj0mibhymjzvkpk-imagemagick-7.1.0-37/bin/convert")
|
2022-07-22 15:11:39 +00:00
|
|
|
|
2022-07-22 21:29:27 +00:00
|
|
|
(define (import-picture src dest)
|
|
|
|
(system (string-append convert " " src " -resize 1600x1600\\> " dest)))
|
2022-07-22 15:11:39 +00:00
|
|
|
|
2022-07-22 21:29:27 +00:00
|
|
|
(define (import-pictures src-list dest-path album-slug . cnt)
|
|
|
|
(cond
|
|
|
|
((null? cnt) (import-pictures (reverse src-list) dest-path album-slug (length src-list)))
|
|
|
|
((null? src-list) '())
|
|
|
|
(#t (let ([newname (string-append dest-path "/" album-slug (format "~6,,,'0@A" (car cnt)) ".webp")])
|
|
|
|
(display (format "processing ~A ~%" (car src-list)))
|
|
|
|
(import-picture (car src-list) newname)
|
|
|
|
(cons newname (import-pictures
|
|
|
|
(cdr src-list)
|
|
|
|
dest-path
|
|
|
|
album-slug
|
|
|
|
(- (car cnt) 1)))
|
|
|
|
))))
|
|
|
|
|
|
|
|
(define (albumize pl)
|
2022-07-22 15:11:39 +00:00
|
|
|
`(html ()
|
|
|
|
(head ()
|
|
|
|
(meta (charset "utf-8"))
|
|
|
|
(style () "
|
|
|
|
img {
|
|
|
|
display:block;
|
2022-07-22 21:29:27 +00:00
|
|
|
max-width: calc(100% - 20px);
|
2022-07-22 15:11:39 +00:00
|
|
|
margin: auto;
|
|
|
|
padding: 10px;
|
|
|
|
}
|
|
|
|
"))
|
2022-07-22 21:29:27 +00:00
|
|
|
,(cons 'body (cons '() (map (lambda (filepath) `(img (src ,(path-last filepath) loading "lazy"))) pl)))))
|
2022-07-22 15:58:52 +00:00
|
|
|
|
|
|
|
(define (list->attr l)
|
|
|
|
(cond
|
|
|
|
((null? l) "")
|
|
|
|
(#t (string-append (format " ~A=\"~A\"" (car l) (cadr l)) (list->attr (cddr l))))))
|
|
|
|
|
|
|
|
(define (list->inner-html l)
|
|
|
|
(apply
|
|
|
|
string-append
|
|
|
|
(map
|
|
|
|
(lambda (v)
|
|
|
|
(cond
|
|
|
|
((list? v) (sexpr->html v))
|
|
|
|
(#t (format "~A" v))))
|
|
|
|
l)))
|
|
|
|
|
|
|
|
(define (sexpr->html s)
|
|
|
|
(cond
|
|
|
|
((null? (cddr s)) ; self-closing tag
|
|
|
|
(format "<~A~A/>~%" (car s) (list->attr (cadr s))))
|
|
|
|
(#t ; non self-closing tag
|
|
|
|
(string-append
|
|
|
|
; opening tag
|
|
|
|
(format "<~A~A>~%" (car s) (list->attr (cadr s)))
|
|
|
|
; inner content
|
|
|
|
(list->inner-html (cddr s))
|
|
|
|
; closing tag
|
|
|
|
(format "</~A>~%" (car s))))
|
|
|
|
))
|
|
|
|
|
2022-07-22 21:29:27 +00:00
|
|
|
(define (pic-list src out slug)
|
|
|
|
(cond
|
|
|
|
((file-exists? out) (webp out))
|
|
|
|
(#t (mkdir out) (reverse (import-pictures (jpg src) out slug)))))
|
|
|
|
|
|
|
|
(define (build src out slug)
|
|
|
|
(let ([pl (pic-list src out slug)])
|
|
|
|
(call-with-output-file
|
|
|
|
(string-append out "/index.html")
|
2022-07-22 15:58:52 +00:00
|
|
|
(lambda (p)
|
2022-07-22 21:29:27 +00:00
|
|
|
(display "<!doctype html>" p)
|
|
|
|
(newline p)
|
|
|
|
(display (sexpr->html (albumize pl)) p)
|
|
|
|
))))
|
2022-07-22 15:11:39 +00:00
|
|
|
|