pull/169/head
Matthew Butterick 7 years ago
parent e10de61aa2
commit dfa9eb4713

@ -1 +1 @@
1516654917 1516657395

@ -56,9 +56,7 @@
;; And with render, they would be rendered repeatedly. ;; And with render, they would be rendered repeatedly.
;; Using reset-modification-dates is sort of like session control. ;; Using reset-modification-dates is sort of like session control.
(reset-mod-date-hash!) (reset-mod-date-hash!)
(for-each (λ (x) ((if (pagetree-source? x) (for-each render-from-source-or-output-path xs))
render-pagenodes
render-from-source-or-output-path) x)) xs))
(define+provide/contract (render-pagenodes pagetree-or-path) (define+provide/contract (render-pagenodes pagetree-or-path)
@ -67,17 +65,22 @@
pagetree-or-path pagetree-or-path
(cached-doc pagetree-or-path))) (cached-doc pagetree-or-path)))
(parameterize ([current-directory (current-project-root)]) (parameterize ([current-directory (current-project-root)])
(for-each render-from-source-or-output-path (map ->complete-path (pagetree->list pagetree))))) (apply render-batch (map ->complete-path (pagetree->list pagetree)))))
(define+provide/contract (render-from-source-or-output-path so-pathish) (define+provide/contract (render-from-source-or-output-path so-pathish)
(pathish? . -> . void?) (pathish? . -> . void?)
(let ([so-path (->complete-path so-pathish)]) ; so-path = source or output path (could be either) (define so-path (->complete-path so-pathish)) ; so-path = source or output path (could be either)
(cond (cond
[(ormap (λ (test) (test so-path)) (list has/is-null-source? has/is-preproc-source? has/is-markup-source? has/is-scribble-source? has/is-markdown-source?)) [(for/or ([pred (in-list (list has/is-null-source?
(let-values ([(source-path output-path) (->source+output-paths so-path)]) has/is-preproc-source?
(render-to-file-if-needed source-path #f output-path))] has/is-markup-source?
[(pagetree-source? so-path) (render-pagenodes so-path)])) has/is-scribble-source?
has/is-markdown-source?))])
(pred so-path))
(define-values (source-path output-path) (->source+output-paths so-path))
(render-to-file-if-needed source-path #f output-path)]
[(pagetree-source? so-path) (render-pagenodes so-path)])
(void)) (void))
(define render-ram-cache (make-hash)) (define render-ram-cache (make-hash))
@ -202,12 +205,11 @@
(time (parameterize ([current-directory (->complete-path (dirname source-path))]) (time (parameterize ([current-directory (->complete-path (dirname source-path))])
(render-through-eval (syntax->datum (render-through-eval (syntax->datum
(with-syntax ([SOURCE-PATH source-path]) (with-syntax ([SOURCE-PATH source-path])
#`(begin (require pollen/cache) #'(begin (require pollen/cache)
(cached-doc 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 source-dir (dirname source-path))
(define output-path (or maybe-output-path (->output-path source-path))) (define output-path (or maybe-output-path (->output-path source-path)))
(unless output-path (unless output-path
(raise-argument-error 'render-markup-or-markdown-source "valid output path" output-path)) (raise-argument-error 'render-markup-or-markdown-source "valid output path" output-path))
@ -242,7 +244,7 @@
DOC-ID DOC-ID
(include-template #:command-char COMMAND-CHAR (file TEMPLATE-PATH)))))))) (include-template #:command-char COMMAND-CHAR (file TEMPLATE-PATH))))))))
;; set current-directory because include-template wants to work relative to source location ;; set current-directory because include-template wants to work relative to source location
(time (parameterize ([current-directory (->complete-path source-dir)]) (time (parameterize ([current-directory (->complete-path (dirname source-path))])
(render-through-eval expr-to-eval)))) (render-through-eval expr-to-eval))))
@ -259,18 +261,19 @@
p))) p)))
(define (get-template) (define (get-template)
(define source-dir (dirname source-path))
(define output-path (or maybe-output-path (->output-path source-path))) (define output-path (or maybe-output-path (->output-path source-path)))
(define output-path-ext (or (get-ext output-path) (current-poly-target))) ; output-path may not have an extension (define output-path-ext (or (get-ext output-path) (current-poly-target))) ; output-path may not have an extension
(define (get-template-from-metas) (define (get-template-from-metas)
(with-handlers ([exn:fail:contract? (λ (e) #f)]) ; in case source-path doesn't work with cached-require (with-handlers ([exn:fail:contract? (λ (e) #f)]) ; in case source-path doesn't work with cached-require
(parameterize ([current-directory (current-project-root)]) (parameterize ([current-directory (current-project-root)])
(let* ([source-metas (cached-metas source-path)] (define source-metas (cached-metas source-path))
[template-name-or-names (select-from-metas (setup:template-meta-key source-path) source-metas)] ; #f or atom or list (define template-name-or-names ; #f or atom or list
[template-name (if (list? template-name-or-names) (select-from-metas (setup:template-meta-key source-path) source-metas))
(define template-name (if (list? template-name-or-names)
(findf (λ (tn) (eq? (get-ext tn) output-path-ext)) template-name-or-names) (findf (λ (tn) (eq? (get-ext tn) output-path-ext)) template-name-or-names)
template-name-or-names)]) template-name-or-names))
(and template-name (build-path source-dir template-name)))))) (and template-name (build-path (dirname source-path) template-name)))))
(define (get-default-template) (define (get-default-template)
(and output-path-ext (and output-path-ext

Loading…
Cancel
Save