render-batch: add explicit `output-paths` keyword argument

dev-gang-render
Matthew Butterick 3 years ago
parent 00a96f4fda
commit 446c5fd39f

@ -1 +1 @@
1644451419 1645490697

@ -181,8 +181,12 @@
(define current-null-output? (make-parameter #f)) (define current-null-output? (make-parameter #f))
(define+provide/contract (render-batch #:parallel [wants-parallel-render? #false] (define+provide/contract (render-batch #:parallel [wants-parallel-render? #false]
#:special [special-output #false] . paths-in) #:special [special-output #false]
((#:parallel any/c) (#:special (or/c boolean? symbol?)) #:rest (listof pathish?) . ->* . void?) #:output-paths [output-paths-in #false] . paths-in)
(() (#:parallel any/c
#:special (or/c boolean? symbol?)
#:output-paths (or/c #false (listof pathish?)))
#:rest (listof pathish?) . ->* . void?)
;; Why not just (for-each render ...)? ;; Why not just (for-each render ...)?
;; Because certain files will pass through multiple times (e.g., templates) ;; Because certain files will pass through multiple times (e.g., templates)
;; And with render, they would be rendered repeatedly. ;; And with render, they would be rendered repeatedly.
@ -202,27 +206,34 @@
;; but the path arguments might also include pagetrees, ;; but the path arguments might also include pagetrees,
;; which expand to multiple files. ;; which expand to multiple files.
;; so this keeps everything correlated correctly. ;; so this keeps everything correlated correctly.
(let loop ([paths paths-in] [sps null] [ops null]) (cond
(match paths [(and output-paths-in (= (length paths-in) (length output-paths-in)))
[(? null?) ;; explicit list of paths: create jobs directly
;; it's possible that we have multiple output names for one poly file (for/list ([path (in-list paths-in)]
;; so after we expand, we only remove duplicates where both the source and dest in the pair [output-path (in-list output-paths-in)])
;; are the same ($job path output-path))]
(let* ([pairs (remove-duplicates (map cons sps ops))] [else
[pairs (sort pairs path<? #:key car)] (let loop ([paths paths-in] [sps null] [ops null])
[pairs (sort pairs path<? #:key cdr)]) (match paths
(for/list ([pr (in-list pairs)]) [(? null?)
($job (car pr) (cdr pr))))] ;; it's possible that we have multiple output names for one poly file
[(cons path rest) ;; so after we expand, we only remove duplicates where both the source and dest in the pair
(match (->complete-path path) ;; are the same
[(? pagetree-source? pt) (let* ([pairs (remove-duplicates (map cons sps ops))]
(loop (append (pagetree->paths pt) rest) sps ops)] [pairs (sort pairs path<? #:key car)]
[(app ->source-path sp) #:when (and sp (file-exists? sp)) [pairs (sort pairs path<? #:key cdr)])
(define op (match path (for/list ([pr (in-list pairs)])
[(== (->output-path path)) path] ($job (car pr) (cdr pr))))]
[_ (->output-path sp)])) [(cons path rest)
(loop rest (cons sp sps) (cons op ops))] (match (->complete-path path)
[_ (loop rest sps ops)])]))) [(? pagetree-source? pt)
(loop (append (pagetree->paths pt) rest) sps ops)]
[(app ->source-path sp) #:when (and sp (file-exists? sp))
(define op (match path
[(== (->output-path path)) path]
[_ (->output-path sp)]))
(loop rest (cons sp sps) (cons op ops))]
[_ (loop rest sps ops)])]))]))
(cond (cond
[(null? all-jobs) (message "[no paths to render]")] [(null? all-jobs) (message "[no paths to render]")]
[(eq? special-output 'dry-run) (for-each message (map $job-source all-jobs))] [(eq? special-output 'dry-run) (for-each message (map $job-source all-jobs))]

Loading…
Cancel
Save