asset: Filter out assets that do not pass the site file filter.

* haunt/asset.scm (directory-assets): Add 'keep?' argument.
  (static-directory): Use site file filter.
This commit is contained in:
David Thompson 2015-08-08 00:42:12 -04:00
parent 568b9b8be6
commit f5f24c57ce
2 changed files with 11 additions and 8 deletions

View File

@ -55,9 +55,9 @@ PREFIX."
(mkdir-p (dirname target*)) (mkdir-p (dirname target*))
(copy-file source target*))))) (copy-file source target*)))))
(define (directory-assets directory dest) (define (directory-assets directory keep? dest)
"Create a list of asset objects to be stored within DEST for all "Create a list of asset objects to be stored within DEST for all
files in DIRECTORY, recursively." files in DIRECTORY that match KEEP?, recursively."
(define enter? (const #t)) (define enter? (const #t))
;; In order to do accurate file name manipulation, every file name ;; In order to do accurate file name manipulation, every file name
@ -67,10 +67,12 @@ files in DIRECTORY, recursively."
(let ((base-length (length (file-name-components directory))) (let ((base-length (length (file-name-components directory)))
(dest* (file-name-components dest))) (dest* (file-name-components dest)))
(lambda (file-name stat memo) (lambda (file-name stat memo)
(let* ((file-name* (file-name-components file-name)) (if (keep? file-name)
(target (join-file-name-components (let* ((file-name* (file-name-components file-name))
(append dest* (drop file-name* base-length))))) (target (join-file-name-components
(cons (make-asset file-name target) memo))))) (append dest* (drop file-name* base-length)))))
(cons (make-asset file-name target) memo))
memo))))
(define (noop file-name stat memo) memo) (define (noop file-name stat memo) memo)

View File

@ -28,6 +28,7 @@
#:use-module (ice-9 ftw) #:use-module (ice-9 ftw)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (haunt asset) #:use-module (haunt asset)
#:use-module (haunt site)
#:export (static-directory)) #:export (static-directory))
(define* (static-directory directory #:optional (dest directory)) (define* (static-directory directory #:optional (dest directory))
@ -35,5 +36,5 @@
in DIRECTORY, a file names relative to a site's source directory, and in DIRECTORY, a file names relative to a site's source directory, and
copies them into DEST, a prefix relative to a site's target output copies them into DEST, a prefix relative to a site's target output
directory. By default, DEST is DIRECTORY." directory. By default, DEST is DIRECTORY."
(lambda _ (lambda (site posts)
(directory-assets directory dest))) (directory-assets directory (site-file-filter site) dest)))