site: Change post-filter to file-filter.

Genericized name because the predicate procedure may be used on any
file, not just posts.

* haunt/site.scm (<site>)[post-filter]: Delete.
  [file-filter]: New field.
  (site): Replace #:post-filter with #:file-filter.
  (build-site): Use 'site-post-filter'.
  (make-file-name-filter): Delete.
  (make-file-filter): New procedure.
  (default-file-name-filter): Delete.
  (default-file-filter): New procedure.
* haunt/reader.scm (read-posts): Flip predicate around.
This commit is contained in:
David Thompson 2015-08-08 00:34:05 -04:00
parent 35f23fb4f8
commit 568b9b8be6
2 changed files with 25 additions and 24 deletions

View File

@ -63,19 +63,19 @@ metadata with DEFAULT-METADATA."
(append metadata default-metadata) (append metadata default-metadata)
sxml))) sxml)))
(define* (read-posts directory ignore? readers #:optional (default-metadata '())) (define* (read-posts directory keep? readers #:optional (default-metadata '()))
"Read all of the files in DIRECTORY that do not match IGNORE? as "Read all of the files in DIRECTORY that match KEEP? as post
post objects. The READERS list must contain a matching reader for objects. The READERS list must contain a matching reader for every
every post." post."
(define enter? (const #t)) (define enter? (const #t))
(define (leaf file-name stat memo) (define (leaf file-name stat memo)
(if (ignore? file-name) (if (keep? file-name)
memo
(let ((reader (find (cut reader-match? <> file-name) readers))) (let ((reader (find (cut reader-match? <> file-name) readers)))
(if reader (if reader
(cons (read-post reader file-name default-metadata) memo) (cons (read-post reader file-name default-metadata) memo)
(error "no reader available for post: " file-name))))) (error "no reader available for post: " file-name)))
memo))
(define (noop file-name stat result) (define (noop file-name stat result)
result) result)

View File

@ -38,7 +38,7 @@
site-title site-title
site-domain site-domain
site-posts-directory site-posts-directory
site-post-filter site-file-filter
site-build-directory site-build-directory
site-default-metadata site-default-metadata
site-make-slug site-make-slug
@ -47,17 +47,17 @@
site-post-slug site-post-slug
build-site build-site
make-file-name-filter make-file-filter
default-file-name-filter)) default-file-filter))
(define-record-type <site> (define-record-type <site>
(make-site title domain posts-directory post-filter build-directory (make-site title domain posts-directory file-filter build-directory
default-metadata make-slug readers builders) default-metadata make-slug readers builders)
site? site?
(title site-title) (title site-title)
(domain site-domain) (domain site-domain)
(posts-directory site-posts-directory) (posts-directory site-posts-directory)
(post-filter site-post-filter) (file-filter site-file-filter)
(build-directory site-build-directory) (build-directory site-build-directory)
(default-metadata site-default-metadata) (default-metadata site-default-metadata)
(make-slug site-make-slug) (make-slug site-make-slug)
@ -68,7 +68,7 @@
(title "This Place is Haunted") (title "This Place is Haunted")
(domain "example.com") (domain "example.com")
(posts-directory "posts") (posts-directory "posts")
(post-filter default-file-name-filter) (file-filter default-file-filter)
(build-directory "site") (build-directory "site")
(default-metadata '()) (default-metadata '())
(make-slug post-slug) (make-slug post-slug)
@ -78,15 +78,16 @@
TITLE: The name of the site TITLE: The name of the site
POSTS-DIRECTORY: The directory where posts are found POSTS-DIRECTORY: The directory where posts are found
POST-FILTER: A predicate procedure that returns #t when a post file FILE-FILTER: A predicate procedure that returns #f when a post file
should be ignored (ignores Emacs temp files by default) should be ignored, and #f otherwise. Emacs temp files are ignored by
default.
BUILD-DIRECTORY: The directory that generated pages are stored in BUILD-DIRECTORY: The directory that generated pages are stored in
DEFAULT-METADATA: An alist of arbitrary default metadata for posts DEFAULT-METADATA: An alist of arbitrary default metadata for posts
whose keys are symbols whose keys are symbols
MAKE-SLUG: A procedure generating a file name slug from a post MAKE-SLUG: A procedure generating a file name slug from a post
READERS: A list of reader objects for processing posts READERS: A list of reader objects for processing posts
BUILDERS: A list of procedures for building pages from posts" BUILDERS: A list of procedures for building pages from posts"
(make-site title domain posts-directory post-filter build-directory (make-site title domain posts-directory file-filter build-directory
default-metadata make-slug readers builders)) default-metadata make-slug readers builders))
(define (site-post-slug site post) (define (site-post-slug site post)
@ -97,7 +98,7 @@ BUILDERS: A list of procedures for building pages from posts"
"Build SITE in the appropriate build directory." "Build SITE in the appropriate build directory."
(let ((posts (if (file-exists? (site-posts-directory site)) (let ((posts (if (file-exists? (site-posts-directory site))
(read-posts (site-posts-directory site) (read-posts (site-posts-directory site)
(site-post-filter site) (site-file-filter site)
(site-readers site) (site-readers site)
(site-default-metadata site)) (site-default-metadata site))
'())) '()))
@ -118,14 +119,14 @@ BUILDERS: A list of procedures for building pages from posts"
(error "unrecognized site object: " obj))) (error "unrecognized site object: " obj)))
(flat-map (cut <> site posts) (site-builders site))))) (flat-map (cut <> site posts) (site-builders site)))))
(define (make-file-name-filter patterns) (define (make-file-filter patterns)
(let ((patterns (map make-regexp patterns))) (let ((patterns (map make-regexp patterns)))
(lambda (file-name) (lambda (file-name)
(any (lambda (regexp) (not (any (lambda (regexp)
(regexp-match? (regexp-match?
(regexp-exec regexp (basename file-name)))) (regexp-exec regexp (basename file-name))))
patterns)))) patterns)))))
;; Filter out Emacs temporary files by default. ;; Filter out Emacs temporary files by default.
(define default-file-name-filter (define default-file-filter
(make-file-name-filter '("^\\." "^#"))) (make-file-filter '("^\\." "^#")))