From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ruben Maher Subject: [Feature Request] Let publishing-function decide :output-file and whether publishing is needed Date: Sat, 25 Jul 2015 18:08:16 +0930 Message-ID: <87oaj0d43r.fsf@ayanami.rkm.id.au> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50361) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIuyU-0001sH-7l for emacs-orgmode@gnu.org; Sat, 25 Jul 2015 04:38:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZIuyQ-0006pf-5v for emacs-orgmode@gnu.org; Sat, 25 Jul 2015 04:38:30 -0400 Received: from sakura.rkm.id.au ([103.4.18.101]:41555) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIuyP-0006pR-9v for emacs-orgmode@gnu.org; Sat, 25 Jul 2015 04:38:26 -0400 Received: from ayanami.rkm.id.au (ppp121-45-126-199.lns20.adl6.internode.on.net [121.45.126.199]) by sakura.rkm.id.au (Postfix) with ESMTPSA id 16BD1620005 for ; Sat, 25 Jul 2015 18:07:34 +0930 (ACST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hi list, I've been working on a derived exporter to publish a static blog, and I've run into some issues. Say that `:publishing-directory' is "~/public_html" and I have `:base-directory' with an Org file foo.org. foo.org has option keywords like this: #+title: foo.org #+date: <2015-07-25 Sat 17:21:41> My derived exporter visits each Org file to get information from the keywords, and would export foo.org like so: foo.org -> ~/public_html/2015/07/25/foo/index.html, using something like #+begin_src elisp (let ((pub-dir (file-name-as-directory (concat (expand-file-name pub-dir) (format-time-string "%Y/%m/%d/" date) (file-name-base filename))))) (org-publish-org-to 'rkm-html filename (concat "." (or (plist-get plist :html-extension) org-html-extension "html")) (org-combine-plists plist '(:output-file "index")) pub-dir)) #+end_src I have achieved this using the attached diff, which tells `org-export-output-file-name' to respect the property `:output-file' in the communications channel. This works pretty well, except that now `org-publish-needed-p' will always return t when called by `org-publish-file' in ox-publish.el. As far as I can tell this would be less trivial to change. The call to org-publish-needed-p would have to move from here (in `org-publish-file'): #+begin_src elisp ;; Allow chain of publishing functions. (dolist (f publishing-function) (when (org-publish-needed-p filename pub-dir f tmp-pub-dir base-dir) (let ((output (funcall f project-plist filename tmp-pub-dir))) (org-publish-update-timestamp filename pub-dir f base-dir) (run-hook-with-args 'org-publish-after-publishing-hook filename output)))) #+end_src ...to the actual publishing function. I believe a change like this would go a ways to making publishing backends more extensible for Org users. Please tell me your thoughts. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-export-output-file-name-respect-output-file.patch >From 13c92b87b728da134a73ef173be8957453ef90a6 Mon Sep 17 00:00:00 2001 From: Ruben Maher Date: Sat, 25 Jul 2015 16:54:28 +0930 Subject: [PATCH] org-export-output-file-name: respect :output-file There is a property :output-file defined in the communications channel but it is ignored by `org-export-output-file-name'. * lisp/ox.el (org-export-output-file-name): Add optional argument EXT-PLIST, and try to get `base-name' from its property `:output-file' if SUBTREEP is nil or there was no EXPORT_FILE_NAME at point. * lisp/ox-publish.el (org-publish-org-to): Provide PLIST when calling `org-export-output-file-name'. --- --- lisp/ox-publish.el | 2 +- lisp/ox.el | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el index 951f0fe..25086cd 100644 --- a/lisp/ox-publish.el +++ b/lisp/ox-publish.el @@ -579,7 +579,7 @@ Return output file name." (work-buffer (or visitingp (find-file-noselect filename)))) (prog1 (with-current-buffer work-buffer (let ((output-file - (org-export-output-file-name extension nil pub-dir)) + (org-export-output-file-name extension nil pub-dir plist)) (body-p (plist-get plist :body-only))) (org-export-to-file backend output-file nil nil nil body-p diff --git a/lisp/ox.el b/lisp/ox.el index b06211b..110094b 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -5892,7 +5892,8 @@ or FILE." (or (and (functionp post-process) (funcall post-process file)) file)))))) -(defun org-export-output-file-name (extension &optional subtreep pub-dir) +(defun org-export-output-file-name + (extension &optional subtreep pub-dir ext-plist) "Return output file's name according to buffer specifications. EXTENSION is a string representing the output file extension, @@ -5905,6 +5906,9 @@ of subtree at point. When optional argument PUB-DIR is set, use it as the publishing directory. +With optional argument SUBTREEP nil and EXT-PLIST non-nil, try to get +the value of `:output-file' from EXT-PLIST. + Return file name as a string." (let* ((visited-file (buffer-file-name (buffer-base-buffer))) (base-name @@ -5917,6 +5921,10 @@ Return file name as a string." (save-excursion (ignore-errors (org-back-to-heading) (point))) "EXPORT_FILE_NAME" t)) + ;; SUBTREEP is nil or there was no EXPORT_FILE_NAME at + ;; point. Try to get the file name from EXT-PLIST if + ;; it is there. + (plist-get ext-plist :output-file) ;; File name may be extracted from buffer's associated ;; file, if any. (and visited-file (file-name-nondirectory visited-file)) -- 2.4.5 --=-=-=--