emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Feature Request] Let publishing-function decide :output-file and whether publishing is needed
@ 2015-07-25  8:38 Ruben Maher
  2015-07-28 13:21 ` Rasmus
  2015-08-02 16:24 ` Nicolas Goaziou
  0 siblings, 2 replies; 5+ messages in thread
From: Ruben Maher @ 2015-07-25  8:38 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1978 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-export-output-file-name-respect-output-file.patch --]
[-- Type: text/x-diff, Size: 2723 bytes --]

From 13c92b87b728da134a73ef173be8957453ef90a6 Mon Sep 17 00:00:00 2001
From: Ruben Maher <r@rkm.id.au>
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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-08-22  1:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-25  8:38 [Feature Request] Let publishing-function decide :output-file and whether publishing is needed Ruben Maher
2015-07-28 13:21 ` Rasmus
2015-08-22  1:29   ` Ruben Maher
2015-08-02 16:24 ` Nicolas Goaziou
2015-08-22  1:32   ` Ruben Maher

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).