|
|
@ -21,11 +21,12 @@
|
|
|
|
"setup.rkt")
|
|
|
|
"setup.rkt")
|
|
|
|
|
|
|
|
|
|
|
|
;; used to track renders according to modification dates of component files
|
|
|
|
;; used to track renders according to modification dates of component files
|
|
|
|
(define mod-date-hash (make-hash))
|
|
|
|
(define mod-date-hash #false)
|
|
|
|
|
|
|
|
|
|
|
|
;; when you want to generate everything fresh.
|
|
|
|
;; when you want to generate everything fresh.
|
|
|
|
;; render functions will always go when no mod-date is found.
|
|
|
|
;; render functions will always go when no mod-date is found.
|
|
|
|
(define (reset-mod-date-hash!) (set! mod-date-hash (make-hash)))
|
|
|
|
(define (reset-mod-date-hash!) (set! mod-date-hash (make-hash)))
|
|
|
|
|
|
|
|
(reset-mod-date-hash!)
|
|
|
|
|
|
|
|
|
|
|
|
(module-test-internal
|
|
|
|
(module-test-internal
|
|
|
|
(require racket/runtime-path)
|
|
|
|
(require racket/runtime-path)
|
|
|
@ -46,8 +47,6 @@
|
|
|
|
(define (mod-date-missing-or-changed? source-path template-path)
|
|
|
|
(define (mod-date-missing-or-changed? source-path template-path)
|
|
|
|
(not (hash-has-key? mod-date-hash (paths->key source-path template-path))))
|
|
|
|
(not (hash-has-key? mod-date-hash (paths->key source-path template-path))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (list-of-pathish? x) (and (list? x) (andmap pathish? x)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (parallel-render source-paths job-count-arg)
|
|
|
|
(define (parallel-render source-paths job-count-arg)
|
|
|
|
(define job-count
|
|
|
|
(define job-count
|
|
|
|
(min
|
|
|
|
(min
|
|
|
@ -145,7 +144,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
(define+provide/contract (render-batch #:parallel [wants-parallel-render? #false]
|
|
|
|
(define+provide/contract (render-batch #:parallel [wants-parallel-render? #false]
|
|
|
|
#:dry-run [wants-dry-run? #false] . paths-in)
|
|
|
|
#:dry-run [wants-dry-run? #false] . paths-in)
|
|
|
|
((#:parallel any/c) (#:dry-run boolean?) #:rest list-of-pathish? . ->* . void?)
|
|
|
|
((#:parallel any/c) (#:dry-run boolean?) #: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.
|
|
|
@ -168,11 +167,10 @@
|
|
|
|
[jobs-arg (parallel-render expanded-source-paths jobs-arg)]))]))
|
|
|
|
[jobs-arg (parallel-render expanded-source-paths jobs-arg)]))]))
|
|
|
|
|
|
|
|
|
|
|
|
(define (pagetree->paths pagetree-or-path)
|
|
|
|
(define (pagetree->paths pagetree-or-path)
|
|
|
|
(define pagetree (if (pagetree? pagetree-or-path)
|
|
|
|
|
|
|
|
pagetree-or-path
|
|
|
|
|
|
|
|
(cached-doc pagetree-or-path)))
|
|
|
|
|
|
|
|
(parameterize ([current-directory (current-project-root)])
|
|
|
|
(parameterize ([current-directory (current-project-root)])
|
|
|
|
(map ->complete-path (pagetree->list pagetree))))
|
|
|
|
(map ->complete-path (pagetree->list (match pagetree-or-path
|
|
|
|
|
|
|
|
[(? pagetree? pt) pt]
|
|
|
|
|
|
|
|
[_ (cached-doc pagetree-or-path)])))))
|
|
|
|
|
|
|
|
|
|
|
|
(define+provide/contract (render-pagenodes pagetree-or-path)
|
|
|
|
(define+provide/contract (render-pagenodes pagetree-or-path)
|
|
|
|
((or/c pagetree? pathish?) . -> . void?)
|
|
|
|
((or/c pagetree? pathish?) . -> . void?)
|
|
|
@ -195,10 +193,14 @@
|
|
|
|
maybe-template-path)
|
|
|
|
maybe-template-path)
|
|
|
|
(unless (file-exists? source-path)
|
|
|
|
(unless (file-exists? source-path)
|
|
|
|
(raise-argument-error caller "existing source path" source-path))
|
|
|
|
(raise-argument-error caller "existing source path" source-path))
|
|
|
|
(define output-path (or maybe-output-path (->output-path source-path)))
|
|
|
|
(define output-path (cond
|
|
|
|
(unless output-path
|
|
|
|
[maybe-output-path]
|
|
|
|
(raise-argument-error caller "valid output path" output-path))
|
|
|
|
[(->output-path source-path)]
|
|
|
|
(define template-path (or maybe-template-path (get-template-for source-path output-path)))
|
|
|
|
[else (raise-argument-error caller "valid output path" output-path)]))
|
|
|
|
|
|
|
|
(define template-path (cond
|
|
|
|
|
|
|
|
[maybe-template-path]
|
|
|
|
|
|
|
|
[(get-template-for source-path output-path)]
|
|
|
|
|
|
|
|
[else #false]))
|
|
|
|
(define render-cache-activated? (setup:render-cache-active source-path))
|
|
|
|
(define render-cache-activated? (setup:render-cache-active source-path))
|
|
|
|
(define render-needed?
|
|
|
|
(define render-needed?
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
@ -208,10 +210,11 @@
|
|
|
|
[(not render-cache-activated?) 'render-cache-deactivated]
|
|
|
|
[(not render-cache-activated?) 'render-cache-deactivated]
|
|
|
|
[else #false]))
|
|
|
|
[else #false]))
|
|
|
|
(when render-needed?
|
|
|
|
(when render-needed?
|
|
|
|
|
|
|
|
(define render-thunk (λ () (render source-path template-path output-path))) ; returns either string or bytes
|
|
|
|
(define render-result
|
|
|
|
(define render-result
|
|
|
|
(let ([key (paths->key source-path template-path output-path)]
|
|
|
|
(cond
|
|
|
|
[render-thunk (λ () (render source-path template-path output-path))]) ; returns either string or bytes
|
|
|
|
[render-cache-activated?
|
|
|
|
(if render-cache-activated?
|
|
|
|
(define key (paths->key source-path template-path output-path))
|
|
|
|
(hash-ref! render-ram-cache
|
|
|
|
(hash-ref! render-ram-cache
|
|
|
|
;; within a session, this will prevent repeat players like "template.html.p"
|
|
|
|
;; within a session, this will prevent repeat players like "template.html.p"
|
|
|
|
;; from hitting the file cache repeatedly
|
|
|
|
;; from hitting the file cache repeatedly
|
|
|
@ -222,8 +225,8 @@
|
|
|
|
#:notify-cache-use
|
|
|
|
#:notify-cache-use
|
|
|
|
(λ (str)
|
|
|
|
(λ (str)
|
|
|
|
(message (format "from cache /~a"
|
|
|
|
(message (format "from cache /~a"
|
|
|
|
(find-relative-path (current-project-root) output-path))))))
|
|
|
|
(find-relative-path (current-project-root) output-path))))))]
|
|
|
|
(render-thunk))))
|
|
|
|
[else (render-thunk)]))
|
|
|
|
(display-to-file render-result
|
|
|
|
(display-to-file render-result
|
|
|
|
output-path
|
|
|
|
output-path
|
|
|
|
#:exists 'replace
|
|
|
|
#:exists 'replace
|
|
|
@ -241,10 +244,10 @@
|
|
|
|
((complete-path?) ((or/c #f complete-path?) (or/c #f complete-path?)) . ->* . (or/c string? bytes?))
|
|
|
|
((complete-path?) ((or/c #f complete-path?) (or/c #f complete-path?)) . ->* . (or/c string? bytes?))
|
|
|
|
(unless (file-exists? source-path)
|
|
|
|
(unless (file-exists? source-path)
|
|
|
|
(raise-argument-error 'render "existing source path" source-path))
|
|
|
|
(raise-argument-error 'render "existing source path" source-path))
|
|
|
|
(define output-path (or maybe-output-path (->output-path source-path)))
|
|
|
|
(define output-path (cond
|
|
|
|
(unless output-path
|
|
|
|
[maybe-output-path]
|
|
|
|
(raise-argument-error 'render "valid output path" output-path))
|
|
|
|
[(->output-path source-path)]
|
|
|
|
|
|
|
|
[else (raise-argument-error 'render "valid output path" output-path)]))
|
|
|
|
(define render-proc
|
|
|
|
(define render-proc
|
|
|
|
(match source-path
|
|
|
|
(match source-path
|
|
|
|
[(? has/is-null-source?) render-null-source]
|
|
|
|
[(? has/is-null-source?) render-null-source]
|
|
|
@ -254,11 +257,14 @@
|
|
|
|
[(? has/is-markdown-source?) render-markup-or-markdown-source]
|
|
|
|
[(? has/is-markdown-source?) render-markup-or-markdown-source]
|
|
|
|
[_ (raise-argument-error 'render (format "valid rendering function for ~a" source-path) #false)]))
|
|
|
|
[_ (raise-argument-error 'render (format "valid rendering function for ~a" source-path) #false)]))
|
|
|
|
|
|
|
|
|
|
|
|
(define template-path (or maybe-template-path (get-template-for source-path output-path)))
|
|
|
|
(define template-path (cond
|
|
|
|
|
|
|
|
[maybe-template-path]
|
|
|
|
|
|
|
|
[(get-template-for source-path output-path)]
|
|
|
|
|
|
|
|
[else #false]))
|
|
|
|
|
|
|
|
|
|
|
|
;; output-path and template-path may not have an extension, so check them in order with fallback
|
|
|
|
;; output-path and template-path may not have an extension, so check them in order with fallback
|
|
|
|
|
|
|
|
|
|
|
|
(match-define-values ((cons render-result _) _ real _)
|
|
|
|
(match-define-values ((cons render-result _) _ ms _)
|
|
|
|
(parameterize ([current-directory (->complete-path (dirname source-path))]
|
|
|
|
(parameterize ([current-directory (->complete-path (dirname source-path))]
|
|
|
|
[current-poly-target (->symbol (or (get-ext output-path)
|
|
|
|
[current-poly-target (->symbol (or (get-ext output-path)
|
|
|
|
(and template-path (get-ext template-path))
|
|
|
|
(and template-path (get-ext template-path))
|
|
|
@ -270,11 +276,9 @@
|
|
|
|
(time-apply render-proc (list source-path template-path output-path))))
|
|
|
|
(time-apply render-proc (list source-path template-path output-path))))
|
|
|
|
;; wait till last possible moment to store mod dates, because render-proc may also trigger its own subrenders
|
|
|
|
;; wait till last possible moment to store mod dates, because render-proc may also trigger its own subrenders
|
|
|
|
;; e.g., of a template.
|
|
|
|
;; e.g., of a template.
|
|
|
|
(message (format "rendered /~a ~a"
|
|
|
|
(message (apply format "rendered /~a (~a ~a)"
|
|
|
|
(find-relative-path (current-project-root) output-path)
|
|
|
|
(find-relative-path (current-project-root) output-path)
|
|
|
|
(if (< real 1000)
|
|
|
|
(if (< ms 1000) (list ms "ms") (list (/ ms 1000.0) "s"))))
|
|
|
|
(format "(~a ms)" real)
|
|
|
|
|
|
|
|
(format "(~a s)" (/ real 1000.0)))))
|
|
|
|
|
|
|
|
(update-mod-date-hash! source-path template-path)
|
|
|
|
(update-mod-date-hash! source-path template-path)
|
|
|
|
render-result)
|
|
|
|
render-result)
|
|
|
|
|
|
|
|
|
|
|
@ -303,25 +307,37 @@
|
|
|
|
;; BTW this next action has side effects: scribble will copy in its core files if they don't exist.
|
|
|
|
;; BTW this next action has side effects: scribble will copy in its core files if they don't exist.
|
|
|
|
[(? part? doc) (scribble-render (list doc) (list source-path))]
|
|
|
|
[(? part? doc) (scribble-render (list doc) (list source-path))]
|
|
|
|
[_ (void)]))
|
|
|
|
[_ (void)]))
|
|
|
|
|
|
|
|
(define op (->output-path source-path))
|
|
|
|
(begin0 ; because render promises the data, not the side effect
|
|
|
|
(begin0 ; because render promises the data, not the side effect
|
|
|
|
(file->string (->output-path source-path))
|
|
|
|
(file->string op)
|
|
|
|
(delete-file (->output-path source-path))))
|
|
|
|
(delete-file op)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (render-preproc-source source-path . _)
|
|
|
|
(define (render-preproc-source source-path . _)
|
|
|
|
(cached-doc (->string source-path)))
|
|
|
|
(cached-doc source-path))
|
|
|
|
|
|
|
|
|
|
|
|
(define (render-markup-or-markdown-source source-path [maybe-template-path #f] [maybe-output-path #f])
|
|
|
|
(define (render-markup-or-markdown-source source-path [maybe-template-path #f] [maybe-output-path #f])
|
|
|
|
(define output-path (or maybe-output-path (->output-path source-path)))
|
|
|
|
(define output-path
|
|
|
|
(unless output-path
|
|
|
|
(cond
|
|
|
|
(raise-argument-error 'render-markup-or-markdown-source "valid output path" output-path))
|
|
|
|
[maybe-output-path]
|
|
|
|
(define template-path (or maybe-template-path (get-template-for source-path output-path)))
|
|
|
|
[(->output-path source-path)]
|
|
|
|
(unless template-path
|
|
|
|
[else (raise-argument-error 'render-markup-or-markdown-source "valid output path" output-path)]))
|
|
|
|
(raise-argument-error 'render-markup-or-markdown-source (format "valid template path~a" (if (has-inner-poly-ext? source-path) (format " for target ~a" (current-poly-target)) "")) template-path))
|
|
|
|
(define template-path
|
|
|
|
|
|
|
|
(cond
|
|
|
|
|
|
|
|
[maybe-template-path]
|
|
|
|
|
|
|
|
[(get-template-for source-path output-path)]
|
|
|
|
|
|
|
|
[else (raise-argument-error 'render-markup-or-markdown-source
|
|
|
|
|
|
|
|
(format "valid template path~a"
|
|
|
|
|
|
|
|
(if (has-inner-poly-ext? source-path)
|
|
|
|
|
|
|
|
(format " for target ~a" (current-poly-target))
|
|
|
|
|
|
|
|
""))
|
|
|
|
|
|
|
|
template-path)]))
|
|
|
|
|
|
|
|
|
|
|
|
;; use a temp file so that multiple (possibly parallel) renders
|
|
|
|
;; use a temp file so that multiple (possibly parallel) renders
|
|
|
|
;; do not compete for write access to the same template
|
|
|
|
;; do not compete for write access to the same template
|
|
|
|
(define temp-template (make-temporary-file "pollentmp~a"
|
|
|
|
(define temp-template (make-temporary-file "pollentmp~a" (cond
|
|
|
|
(or (->source-path template-path) template-path)))
|
|
|
|
[(->source-path template-path)]
|
|
|
|
|
|
|
|
[template-path]
|
|
|
|
|
|
|
|
[else #false])))
|
|
|
|
(render-from-source-or-output-path temp-template) ; because template might have its own preprocessor source
|
|
|
|
(render-from-source-or-output-path temp-template) ; because template might have its own preprocessor source
|
|
|
|
(parameterize ([current-output-port (current-error-port)]
|
|
|
|
(parameterize ([current-output-port (current-error-port)]
|
|
|
|
[current-namespace (make-base-namespace)])
|
|
|
|
[current-namespace (make-base-namespace)])
|
|
|
@ -340,9 +356,6 @@
|
|
|
|
result)))
|
|
|
|
result)))
|
|
|
|
(delete-file temp-template))))
|
|
|
|
(delete-file temp-template))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (templated-source? path)
|
|
|
|
|
|
|
|
(or (markup-source? path) (markdown-source? path)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (file-exists-or-has-source? path) ; path could be #f
|
|
|
|
(define (file-exists-or-has-source? path) ; path could be #f
|
|
|
|
(and path (for/first ([proc (in-list (list values ->preproc-source-path ->null-source-path))]
|
|
|
|
(and path (for/first ([proc (in-list (list values ->preproc-source-path ->null-source-path))]
|
|
|
|
#:when (file-exists? (proc path)))
|
|
|
|
#:when (file-exists? (proc path)))
|
|
|
@ -371,13 +384,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
(define+provide/contract (get-template-for source-path [maybe-output-path #f])
|
|
|
|
(define+provide/contract (get-template-for source-path [maybe-output-path #f])
|
|
|
|
((complete-path?)((or/c #f complete-path?)) . ->* . (or/c #f complete-path?))
|
|
|
|
((complete-path?)((or/c #f complete-path?)) . ->* . (or/c #f complete-path?))
|
|
|
|
(and (templated-source? source-path)
|
|
|
|
(match source-path
|
|
|
|
(let ()
|
|
|
|
[(or (? markup-source?) (? markdown-source?))
|
|
|
|
(define output-path (or maybe-output-path (->output-path source-path)))
|
|
|
|
(define output-path (cond
|
|
|
|
|
|
|
|
[maybe-output-path]
|
|
|
|
|
|
|
|
[(->output-path source-path)]
|
|
|
|
|
|
|
|
[else #false]))
|
|
|
|
;; output-path may not have an extension
|
|
|
|
;; output-path may not have an extension
|
|
|
|
(define output-path-ext (or (get-ext output-path) (current-poly-target)))
|
|
|
|
(define output-path-ext (cond
|
|
|
|
|
|
|
|
[(get-ext output-path)]
|
|
|
|
|
|
|
|
[(current-poly-target)]
|
|
|
|
|
|
|
|
[else #false]))
|
|
|
|
(for/or ([proc (list get-template-from-metas get-default-template get-fallback-template)])
|
|
|
|
(for/or ([proc (list get-template-from-metas get-default-template get-fallback-template)])
|
|
|
|
(file-exists-or-has-source? (proc source-path output-path-ext))))))
|
|
|
|
(file-exists-or-has-source? (proc source-path output-path-ext)))]
|
|
|
|
|
|
|
|
[_ #false]))
|
|
|
|
|
|
|
|
|
|
|
|
(module-test-external
|
|
|
|
(module-test-external
|
|
|
|
(require pollen/setup sugar/file sugar/coerce)
|
|
|
|
(require pollen/setup sugar/file sugar/coerce)
|
|
|
|