>From 410dc552de2e846f7eed9f98275acffba45f5be0 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 27 May 2016 15:46:31 +0200 Subject: [PATCH 2/6] ox-publish: Get property from file * lisp/ox-publish.el (org-publish-find-property): New function. (org-publish-find-title): Use new function. (org-publish-find-date): Use new function. --- lisp/ox-publish.el | 62 +++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el index d60562b..480c8de 100644 --- a/lisp/ox-publish.el +++ b/lisp/ox-publish.el @@ -799,28 +799,38 @@ Default for SITEMAP-FILENAME is `sitemap.org'." (org-publish-find-date file))) (?a . ,(or (plist-get project-plist :author) user-full-name))))) + +(defun org-publish-find-property (file property &optional reset) + "Find the PROPERTY of FILE in project. +PROPERTY can be a string or a symbol-property." + (unless (or (file-directory-p file) (directory-name-p file)) + (let ((prop (cond ((stringp property) + (intern (downcase (format ":%s" property)))) + (t property)))) + (and (not reset) (org-publish-cache-get-file-property file prop nil t)) + (let* ((org-inhibit-startup t) + (visiting (find-buffer-visiting file)) + (buffer (or visiting (find-file-noselect file))) + (case-fold-search t)) + (with-current-buffer buffer + ;; protect local variables in open buffers + (org-export-with-buffer-copy + (let* ((backends (append (list nil) + (mapcar 'org-export-backend-name + org-export-registered-backends))) + (value (cl-loop for backend in backends + when (org-no-properties + (org-element-interpret-data + (plist-get (org-export-get-environment backend) + prop))) + return it))) + (unless visiting (kill-buffer buffer)) + (org-publish-cache-set-file-property file prop value) + value))))))) + (defun org-publish-find-title (file &optional reset) "Find the title of FILE in project." - (or - (and (not reset) (org-publish-cache-get-file-property file :title nil t)) - (let* ((org-inhibit-startup t) - (visiting (find-buffer-visiting file)) - (buffer (or visiting (find-file-noselect file)))) - (with-current-buffer buffer - (let ((title - (let ((property - (plist-get - ;; protect local variables in open buffers - (if visiting - (org-export-with-buffer-copy (org-export-get-environment)) - (org-export-get-environment)) - :title))) - (if property - (org-no-properties (org-element-interpret-data property)) - (file-name-nondirectory (file-name-sans-extension file)))))) - (unless visiting (kill-buffer buffer)) - (org-publish-cache-set-file-property file :title title) - title))))) + (org-publish-find-property file :title reset)) (defun org-publish-find-date (file) "Find the date of FILE in project. @@ -829,17 +839,7 @@ If FILE is an Org file and provides a DATE keyword use it. In any other case use the file system's modification time. Return time in `current-time' format." (if (file-directory-p file) (nth 5 (file-attributes file)) - (let* ((org-inhibit-startup t) - (visiting (find-buffer-visiting file)) - (file-buf (or visiting (find-file-noselect file nil))) - (date (plist-get - (with-current-buffer file-buf - (if visiting - (org-export-with-buffer-copy - (org-export-get-environment)) - (org-export-get-environment))) - :date))) - (unless visiting (kill-buffer file-buf)) + (let* ((date (org-publish-find-property file :date t))) ;; DATE is a secondary string. If it contains a timestamp, ;; convert it to internal format. Otherwise, use FILE ;; modification time. -- 2.8.3