Function: org-publish-file

org-publish-file is a byte-compiled function defined in ox-publish.el.gz.

Signature

(org-publish-file FILENAME &optional PROJECT NO-CACHE)

Documentation

Publish file FILENAME from PROJECT.

If NO-CACHE is not nil, do not initialize org-publish-cache. This is needed, since this function is used to publish single files, when entire projects are published (see org-publish-projects).

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-publish.el.gz
;;; Publishing files, sets of files

(defun org-publish-file (filename &optional project no-cache)
  "Publish file FILENAME from PROJECT.
If NO-CACHE is not nil, do not initialize `org-publish-cache'.
This is needed, since this function is used to publish single
files, when entire projects are published (see
`org-publish-projects')."
  (let* ((project
	  (or project
	      (org-publish-get-project-from-filename filename)
	      (user-error "File %S is not part of any known project"
			  (abbreviate-file-name filename))))
	 (project-plist (cdr project))
	 (publishing-function
	  (pcase (org-publish-property :publishing-function project
                                       'org-html-publish-to-html)
	    (`nil (user-error "No publishing function chosen"))
	    ((and f (pred listp)) f)
	    (f (list f))))
	 (base-dir
	  (file-name-as-directory
	   (or (org-publish-property :base-directory project)
	       (user-error "Project %S does not have :base-directory defined"
			   (car project)))))
	 (pub-base-dir
	  (file-name-as-directory
	   (or (org-publish-property :publishing-directory project)
	       (user-error
		"Project %S does not have :publishing-directory defined"
		(car project)))))
	 (pub-dir
	  (file-name-directory
	   (expand-file-name (file-relative-name filename base-dir)
			     pub-base-dir))))

    (unless no-cache (org-publish-initialize-cache (car project)))

    ;; Allow chain of publishing functions.
    (dolist (f publishing-function)
      (when (org-publish-needed-p filename pub-base-dir f pub-dir base-dir)
	(let ((output (funcall f project-plist filename pub-dir)))
	  (org-publish-update-timestamp filename pub-base-dir f base-dir)
	  (run-hook-with-args 'org-publish-after-publishing-hook
			      filename
			      output))))
    ;; Make sure to write cache to file after successfully publishing
    ;; a file, so as to minimize impact of a publishing failure.
    (org-publish-write-cache-file)))