diff options
author | Arun Isaac | 2020-07-31 02:52:57 +0530 |
---|---|---|
committer | Arun Isaac | 2020-07-31 03:06:43 +0530 |
commit | c86aabf53bdbce9819360ebb1caae2d80fc0f685 (patch) | |
tree | e4a0c887c34549f40c12b78d4c18b01756178dda | |
parent | 79355db341d6c37b2b70a733621fd5b286d67ca0 (diff) | |
download | ennum-c86aabf53bdbce9819360ebb1caae2d80fc0f685.tar.gz ennum-c86aabf53bdbce9819360ebb1caae2d80fc0f685.tar.lz ennum-c86aabf53bdbce9819360ebb1caae2d80fc0f685.zip |
Introduce ennum-directory-files.
ennum-directory-files is a more convenient around directory-files and
directory-files-recursively.
* ennum.el (ennum-directory-files): New function.
(ennum-posts, ennum-video-poster, ennum-publish): Use
ennum-directory-files.
(ennum-publish-generic): Accept files that are not prefixed by
other-files-directory.
-rw-r--r-- | ennum.el | 54 |
1 files changed, 34 insertions, 20 deletions
@@ -25,11 +25,11 @@ inputs outputs publish) (defun ennum-posts (posts-directory) - (sort (seq-map 'ennum-read-post - (file-expand-wildcards - (concat (file-name-as-directory - (ennum-setting :posts-directory)) - "*.org"))) + (sort (ennum--filter-map (lambda (file) + (when (string= (file-name-extension file) "org") + (ennum-read-post + (ennum--expand-relative file (ennum-setting :posts-directory))))) + (ennum-directory-files (ennum-setting :posts-directory))) 'ennum-later-post-p)) (defun ennum-later-post-p (post1 post2) @@ -105,6 +105,23 @@ last form in BODY." (insert-file-contents ,file) ,@body)) +(defun ennum-directory-files (directory &optional full include-directories) + "Return recursively the list of all files under DIRECTORY. Files are +returned in depth first order. + +If FULL is non-nil, absolute file names are returned. Else, the +file names are relative to DIRECTORY. If INCLUDE-DIRECTORIES is +non-nil, include directories in the output." + (let ((files (directory-files-recursively + directory (rx anything) include-directories))) + (if full + files + (seq-map (apply-partially 'string-remove-prefix + ;; Expand directory in case it is a + ;; relative path. + (file-name-as-directory (expand-file-name directory))) + files)))) + (defun ennum--org-output-filename (filename) (concat (file-name-sans-extension filename) ".html")) @@ -155,25 +172,24 @@ last form in BODY." (defun ennum-publish-generic (other-files-directory file) (ennum-make-operation - :inputs (list file) + :inputs (list (ennum--expand-relative file other-files-directory)) :outputs - (list (string-remove-prefix - (file-name-as-directory other-files-directory) - (pcase (file-name-extension file) - ("org" (ennum--org-output-filename file)) - (_ file)))) + (list (pcase (file-name-extension file) + ("org" (ennum--org-output-filename file)) + (_ file))) :publish (lambda (output-file) (pcase (file-name-extension file) ("org" (ennum-with-file-contents file (org-export-to-file 'html output-file))) - (_ (ennum-copy file output-file)))))) + (_ (ennum-copy (ennum--expand-relative file other-files-directory) + output-file)))))) (defun ennum-video-poster (video) - (pcase (directory-files (ennum-setting :images-directory) nil - (concat (file-name-sans-extension video) - "\\.\\(jpg\\|png\\)$")) - (`(,poster . ,_) poster) - (`() (user-error "Poster for %s not found" video)))) + (or (seq-find (lambda (file) + (string= (file-name-base file) + (file-name-base video))) + (ennum-directory-files (ennum-setting :images-directory))) + (user-error "Poster for %s not found" video))) (defun ennum-add-tongue-suffix (filename tongue) (pcase tongue @@ -500,9 +516,7 @@ as keys. Keys are compared using `equal'." ;; Publish other files (when-let ((other-files-directory (ennum-setting :other-files-directory))) (seq-map (apply-partially 'ennum-publish-generic other-files-directory) - (seq-map (apply-partially 'string-remove-prefix - (file-name-as-directory (expand-file-name default-directory))) - (directory-files-recursively other-files-directory ".")))))) + (ennum-directory-files other-files-directory))))) ;; Replace old output directory (let ((output (ennum-setting :output-directory))) (delete-directory output t) |