From 9c8a8d8feac2aa2850aee69466a5c8e176a6c46d Mon Sep 17 00:00:00 2001 From: Ruijie Yu Date: Sat, 15 Apr 2023 18:29:41 +0800 Subject: [PATCH 16/16] * publish.sh: Avoid reinventing wheel, and facilitate direct loading (file-name-with-extension): Created equivalent function for older Emacsen, to be used in the `dolist' form. (dolist): Replaced ad-hoc use of `file-name-with-extension' into calling this function; replaced use of `default-directory' and `file-relative-name' with just passing "." to `directory-files-recursively'; replaced `find-file' with `find-file-noselect' because otherwise directly loading this elisp script from within Emacs show all these files in a buffer; reindentations. --- publish.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/publish.sh b/publish.sh index 00184ff..2b6d4f9 100755 --- a/publish.sh +++ b/publish.sh @@ -13,6 +13,13 @@ (setq make-backup-files nil debug-on-error t) +(unless (fboundp 'file-name-with-extension) ; >= 28.1 + (defalias 'file-name-with-extension + (lambda (fname ext) + (concat (file-name-directory fname) + (file-name-base fname) + "." ext)))) + (defun get-postamble (root-dname) (with-temp-buffer (insert-file-contents-literally @@ -31,14 +38,13 @@ `(("en" ,(get-postamble ".")) ("zh-CN" ,(get-postamble "zh-CN")))) -(dolist (org-file (directory-files-recursively default-directory "\\.org$")) - (let ((html-file (concat (file-name-directory org-file) - (file-name-base org-file) ".html"))) +(dolist (org-file (directory-files-recursively "." "\\.org$")) + (let ((html-file (file-name-with-extension org-file "html"))) (if (and (file-exists-p html-file) (file-newer-than-file-p html-file org-file)) - (message " [skipping] unchanged %s" org-file) - (message "[exporting] %s" (file-relative-name org-file default-directory)) - (with-current-buffer (find-file org-file) - (condition-case err + (message " [skipping] unchanged %s" org-file) + (message "[exporting] %s" org-file) + (with-current-buffer (find-file-noselect org-file) + (condition-case err (org-html-export-to-html) (error (message (error-message-string err)))))))) -- 2.40.0