- (buffer (or visiting (find-file-noselect file)))
- title)
- (with-current-buffer buffer
- (let* ((opt-plist (org-combine-plists (org-default-export-plist)
- (org-infile-export-plist))))
- (setq title
- (or (plist-get opt-plist :title)
- (and (not
- (plist-get opt-plist :skip-before-1st-heading))
- (org-export-grab-title-from-buffer))
- (file-name-nondirectory (file-name-sans-extension file))))))
- (unless visiting
- (kill-buffer buffer))
- (org-publish-cache-set-file-property file :title title)
- title)))
+ (buffer (or visiting (find-file-noselect file)))
+ title)
+ (with-current-buffer buffer
+ (let* ((opt-plist (org-combine-plists (org-default-export-plist)
+ (org-infile-export-plist))))
+ (setq title
+ (or (plist-get opt-plist :title)
+ (and (not
+ (plist-get opt-plist :skip-before-1st-heading))
+ (org-export-grab-title-from-buffer))
+ (file-name-nondirectory (file-name-sans-extension file))))))
+ (unless visiting
+ (kill-buffer buffer))
+ (org-publish-cache-set-file-property file :title title)
+ title)))
+
+(defun org-publish-find-date (file)
+ "Find the date of FILE in project.
+If FILE provides a #+date keyword use it else use the file
+system's modification time.
+
+It returns time in `current-time' format."
+ (let ((visiting (find-buffer-visiting file)))
+ (save-excursion
+ (org-pop-to-buffer-same-window (or visiting (find-file-noselect file nil t)))
+ (let* ((plist (org-infile-export-plist))
+ (date (plist-get plist :date)))
+ (unless visiting
+ (kill-buffer (current-buffer)))
+ (if date
+ (org-time-string-to-time date)
+ (when (file-exists-p file)
+ (nth 5 (file-attributes file))))))))