Merge branch 'maint'
[org-mode.git] / lisp / ox-publish.el
blob9669bf0fd94ecac125edc9516c0c2069f0eebd25
1 ;;; ox-publish.el --- Publish Related Org Mode Files as a Website
2 ;; Copyright (C) 2006-2014 Free Software Foundation, Inc.
4 ;; Author: David O'Toole <dto@gnu.org>
5 ;; Maintainer: Carsten Dominik <carsten DOT dominik AT gmail DOT com>
6 ;; Keywords: hypermedia, outlines, wp
8 ;; This file is part of GNU Emacs.
9 ;;
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; This program allow configurable publishing of related sets of
26 ;; Org mode files as a complete website.
28 ;; ox-publish.el can do the following:
30 ;; + Publish all one's Org files to a given export back-end
31 ;; + Upload HTML, images, attachments and other files to a web server
32 ;; + Exclude selected private pages from publishing
33 ;; + Publish a clickable sitemap of pages
34 ;; + Manage local timestamps for publishing only changed files
35 ;; + Accept plugin functions to extend range of publishable content
37 ;; Documentation for publishing is in the manual.
39 ;;; Code:
41 (eval-when-compile (require 'cl))
42 (require 'format-spec)
43 (require 'ox)
47 ;;; Variables
49 (defvar org-publish-temp-files nil
50 "Temporary list of files to be published.")
52 ;; Here, so you find the variable right before it's used the first time:
53 (defvar org-publish-cache nil
54 "This will cache timestamps and titles for files in publishing projects.
55 Blocks could hash sha1 values here.")
57 (defvar org-publish-after-publishing-hook nil
58 "Hook run each time a file is published.
59 Every function in this hook will be called with two arguments:
60 the name of the original file and the name of the file
61 produced.")
63 (defgroup org-publish nil
64 "Options for publishing a set of Org-mode and related files."
65 :tag "Org Publishing"
66 :group 'org)
68 (defcustom org-publish-project-alist nil
69 "Association list to control publishing behavior.
70 Each element of the alist is a publishing 'project.' The CAR of
71 each element is a string, uniquely identifying the project. The
72 CDR of each element is in one of the following forms:
74 1. A well-formed property list with an even number of elements,
75 alternating keys and values, specifying parameters for the
76 publishing process.
78 \(:property value :property value ... )
80 2. A meta-project definition, specifying of a list of
81 sub-projects:
83 \(:components (\"project-1\" \"project-2\" ...))
85 When the CDR of an element of org-publish-project-alist is in
86 this second form, the elements of the list after `:components'
87 are taken to be components of the project, which group together
88 files requiring different publishing options. When you publish
89 such a project with \\[org-publish], the components all publish.
91 When a property is given a value in `org-publish-project-alist',
92 its setting overrides the value of the corresponding user
93 variable (if any) during publishing. However, options set within
94 a file override everything.
96 Most properties are optional, but some should always be set:
98 `:base-directory'
100 Directory containing publishing source files.
102 `:base-extension'
104 Extension (without the dot!) of source files. This can be
105 a regular expression. If not given, \"org\" will be used as
106 default extension.
108 `:publishing-directory'
110 Directory (possibly remote) where output files will be
111 published.
113 The `:exclude' property may be used to prevent certain files from
114 being published. Its value may be a string or regexp matching
115 file names you don't want to be published.
117 The `:include' property may be used to include extra files. Its
118 value may be a list of filenames to include. The filenames are
119 considered relative to the base directory.
121 When both `:include' and `:exclude' properties are given values,
122 the exclusion step happens first.
124 One special property controls which back-end function to use for
125 publishing files in the project. This can be used to extend the
126 set of file types publishable by `org-publish', as well as the
127 set of output formats.
129 `:publishing-function'
131 Function to publish file. Each back-end may define its
132 own (i.e. `org-latex-publish-to-pdf',
133 `org-html-publish-to-html'). May be a list of functions, in
134 which case each function in the list is invoked in turn.
136 Another property allows you to insert code that prepares
137 a project for publishing. For example, you could call GNU Make
138 on a certain makefile, to ensure published files are built up to
139 date.
141 `:preparation-function'
143 Function to be called before publishing this project. This
144 may also be a list of functions.
146 `:completion-function'
148 Function to be called after publishing this project. This
149 may also be a list of functions.
151 Some properties control details of the Org publishing process,
152 and are equivalent to the corresponding user variables listed in
153 the right column. Back-end specific properties may also be
154 included. See the back-end documentation for more information.
156 :author `user-full-name'
157 :creator `org-export-creator-string'
158 :email `user-mail-address'
159 :exclude-tags `org-export-exclude-tags'
160 :headline-levels `org-export-headline-levels'
161 :language `org-export-default-language'
162 :preserve-breaks `org-export-preserve-breaks'
163 :section-numbers `org-export-with-section-numbers'
164 :select-tags `org-export-select-tags'
165 :time-stamp-file `org-export-time-stamp-file'
166 :with-archived-trees `org-export-with-archived-trees'
167 :with-author `org-export-with-author'
168 :with-creator `org-export-with-creator'
169 :with-date `org-export-with-date'
170 :with-drawers `org-export-with-drawers'
171 :with-email `org-export-with-email'
172 :with-emphasize `org-export-with-emphasize'
173 :with-entities `org-export-with-entities'
174 :with-fixed-width `org-export-with-fixed-width'
175 :with-footnotes `org-export-with-footnotes'
176 :with-inlinetasks `org-export-with-inlinetasks'
177 :with-latex `org-export-with-latex'
178 :with-priority `org-export-with-priority'
179 :with-properties `org-export-with-properties'
180 :with-smart-quotes `org-export-with-smart-quotes'
181 :with-special-strings `org-export-with-special-strings'
182 :with-statistics-cookies' `org-export-with-statistics-cookies'
183 :with-sub-superscript `org-export-with-sub-superscripts'
184 :with-toc `org-export-with-toc'
185 :with-tables `org-export-with-tables'
186 :with-tags `org-export-with-tags'
187 :with-tasks `org-export-with-tasks'
188 :with-timestamps `org-export-with-timestamps'
189 :with-planning `org-export-with-planning'
190 :with-todo-keywords `org-export-with-todo-keywords'
192 The following properties may be used to control publishing of
193 a site-map of files or summary page for a given project.
195 `:auto-sitemap'
197 Whether to publish a site-map during
198 `org-publish-current-project' or `org-publish-all'.
200 `:sitemap-filename'
202 Filename for output of sitemap. Defaults to \"sitemap.org\".
204 `:sitemap-title'
206 Title of site-map page. Defaults to name of file.
208 `:sitemap-function'
210 Plugin function to use for generation of site-map. Defaults
211 to `org-publish-org-sitemap', which generates a plain list of
212 links to all files in the project.
214 `:sitemap-style'
216 Can be `list' (site-map is just an itemized list of the
217 titles of the files involved) or `tree' (the directory
218 structure of the source files is reflected in the site-map).
219 Defaults to `tree'.
221 `:sitemap-sans-extension'
223 Remove extension from site-map's file-names. Useful to have
224 cool URIs (see http://www.w3.org/Provider/Style/URI).
225 Defaults to nil.
227 If you create a site-map file, adjust the sorting like this:
229 `:sitemap-sort-folders'
231 Where folders should appear in the site-map. Set this to
232 `first' (default) or `last' to display folders first or last,
233 respectively. Any other value will mix files and folders.
235 `:sitemap-sort-files'
237 The site map is normally sorted alphabetically. You can
238 change this behaviour setting this to `anti-chronologically',
239 `chronologically', or nil.
241 `:sitemap-ignore-case'
243 Should sorting be case-sensitive? Default nil.
245 The following property control the creation of a concept index.
247 `:makeindex'
249 Create a concept index. The file containing the index has to
250 be called \"theindex.org\". If it doesn't exist in the
251 project, it will be generated. Contents of the index are
252 stored in the file \"theindex.inc\", which can be included in
253 \"theindex.org\".
255 Other properties affecting publication.
257 `:body-only'
259 Set this to t to publish only the body of the documents."
260 :group 'org-export-publish
261 :type 'alist)
263 (defcustom org-publish-use-timestamps-flag t
264 "Non-nil means use timestamp checking to publish only changed files.
265 When nil, do no timestamp checking and always publish all files."
266 :group 'org-export-publish
267 :type 'boolean)
269 (defcustom org-publish-timestamp-directory
270 (convert-standard-filename "~/.org-timestamps/")
271 "Name of directory in which to store publishing timestamps."
272 :group 'org-export-publish
273 :type 'directory)
275 (defcustom org-publish-list-skipped-files t
276 "Non-nil means show message about files *not* published."
277 :group 'org-export-publish
278 :type 'boolean)
280 (defcustom org-publish-sitemap-sort-files 'alphabetically
281 "Method to sort files in site-maps.
282 Possible values are `alphabetically', `chronologically',
283 `anti-chronologically' and nil.
285 If `alphabetically', files will be sorted alphabetically. If
286 `chronologically', files will be sorted with older modification
287 time first. If `anti-chronologically', files will be sorted with
288 newer modification time first. nil won't sort files.
290 You can overwrite this default per project in your
291 `org-publish-project-alist', using `:sitemap-sort-files'."
292 :group 'org-export-publish
293 :type 'symbol)
295 (defcustom org-publish-sitemap-sort-folders 'first
296 "A symbol, denoting if folders are sorted first in sitemaps.
297 Possible values are `first', `last', and nil.
298 If `first', folders will be sorted before files.
299 If `last', folders are sorted to the end after the files.
300 Any other value will not mix files and folders.
302 You can overwrite this default per project in your
303 `org-publish-project-alist', using `:sitemap-sort-folders'."
304 :group 'org-export-publish
305 :type 'symbol)
307 (defcustom org-publish-sitemap-sort-ignore-case nil
308 "Non-nil when site-map sorting should ignore case.
310 You can overwrite this default per project in your
311 `org-publish-project-alist', using `:sitemap-ignore-case'."
312 :group 'org-export-publish
313 :type 'boolean)
315 (defcustom org-publish-sitemap-date-format "%Y-%m-%d"
316 "Format for printing a date in the sitemap.
317 See `format-time-string' for allowed formatters."
318 :group 'org-export-publish
319 :type 'string)
321 (defcustom org-publish-sitemap-file-entry-format "%t"
322 "Format string for site-map file entry.
323 You could use brackets to delimit on what part the link will be.
325 %t is the title.
326 %a is the author.
327 %d is the date formatted using `org-publish-sitemap-date-format'."
328 :group 'org-export-publish
329 :type 'string)
333 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
334 ;;; Timestamp-related functions
336 (defun org-publish-timestamp-filename (filename &optional pub-dir pub-func)
337 "Return path to timestamp file for filename FILENAME."
338 (setq filename (concat filename "::" (or pub-dir "") "::"
339 (format "%s" (or pub-func ""))))
340 (concat "X" (if (fboundp 'sha1) (sha1 filename) (md5 filename))))
342 (defun org-publish-needed-p
343 (filename &optional pub-dir pub-func true-pub-dir base-dir)
344 "Non-nil if FILENAME should be published in PUB-DIR using PUB-FUNC.
345 TRUE-PUB-DIR is where the file will truly end up. Currently we
346 are not using this - maybe it can eventually be used to check if
347 the file is present at the target location, and how old it is.
348 Right now we cannot do this, because we do not know under what
349 file name the file will be stored - the publishing function can
350 still decide about that independently."
351 (let ((rtn (if (not org-publish-use-timestamps-flag) t
352 (org-publish-cache-file-needs-publishing
353 filename pub-dir pub-func base-dir))))
354 (if rtn (message "Publishing file %s using `%s'" filename pub-func)
355 (when org-publish-list-skipped-files
356 (message "Skipping unmodified file %s" filename)))
357 rtn))
359 (defun org-publish-update-timestamp
360 (filename &optional pub-dir pub-func base-dir)
361 "Update publishing timestamp for file FILENAME.
362 If there is no timestamp, create one."
363 (let ((key (org-publish-timestamp-filename filename pub-dir pub-func))
364 (stamp (org-publish-cache-ctime-of-src filename)))
365 (org-publish-cache-set key stamp)))
367 (defun org-publish-remove-all-timestamps ()
368 "Remove all files in the timestamp directory."
369 (let ((dir org-publish-timestamp-directory)
370 files)
371 (when (and (file-exists-p dir) (file-directory-p dir))
372 (mapc 'delete-file (directory-files dir 'full "[^.]\\'"))
373 (org-publish-reset-cache))))
377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
378 ;;; Getting project information out of `org-publish-project-alist'
380 (defun org-publish-expand-projects (projects-alist)
381 "Expand projects in PROJECTS-ALIST.
382 This splices all the components into the list."
383 (let ((rest projects-alist) rtn p components)
384 (while (setq p (pop rest))
385 (if (setq components (plist-get (cdr p) :components))
386 (setq rest (append
387 (mapcar (lambda (x) (assoc x org-publish-project-alist))
388 components)
389 rest))
390 (push p rtn)))
391 (nreverse (delete-dups (delq nil rtn)))))
393 (defvar org-publish-sitemap-sort-files)
394 (defvar org-publish-sitemap-sort-folders)
395 (defvar org-publish-sitemap-ignore-case)
396 (defvar org-publish-sitemap-requested)
397 (defvar org-publish-sitemap-date-format)
398 (defvar org-publish-sitemap-file-entry-format)
399 (defun org-publish-compare-directory-files (a b)
400 "Predicate for `sort', that sorts folders and files for sitemap."
401 (let ((retval t))
402 (when (or org-publish-sitemap-sort-files org-publish-sitemap-sort-folders)
403 ;; First we sort files:
404 (when org-publish-sitemap-sort-files
405 (case org-publish-sitemap-sort-files
406 (alphabetically
407 (let* ((adir (file-directory-p a))
408 (aorg (and (string-match "\\.org$" a) (not adir)))
409 (bdir (file-directory-p b))
410 (borg (and (string-match "\\.org$" b) (not bdir)))
411 (A (if aorg (concat (file-name-directory a)
412 (org-publish-find-title a)) a))
413 (B (if borg (concat (file-name-directory b)
414 (org-publish-find-title b)) b)))
415 (setq retval (if org-publish-sitemap-ignore-case
416 (not (string-lessp (upcase B) (upcase A)))
417 (not (string-lessp B A))))))
418 ((anti-chronologically chronologically)
419 (let* ((adate (org-publish-find-date a))
420 (bdate (org-publish-find-date b))
421 (A (+ (lsh (car adate) 16) (cadr adate)))
422 (B (+ (lsh (car bdate) 16) (cadr bdate))))
423 (setq retval
424 (if (eq org-publish-sitemap-sort-files 'chronologically) (<= A B)
425 (>= A B)))))))
426 ;; Directory-wise wins:
427 (when org-publish-sitemap-sort-folders
428 ;; a is directory, b not:
429 (cond
430 ((and (file-directory-p a) (not (file-directory-p b)))
431 (setq retval (equal org-publish-sitemap-sort-folders 'first)))
432 ;; a is not a directory, but b is:
433 ((and (not (file-directory-p a)) (file-directory-p b))
434 (setq retval (equal org-publish-sitemap-sort-folders 'last))))))
435 retval))
437 (defun org-publish-get-base-files-1
438 (base-dir &optional recurse match skip-file skip-dir)
439 "Set `org-publish-temp-files' with files from BASE-DIR directory.
440 If RECURSE is non-nil, check BASE-DIR recursively. If MATCH is
441 non-nil, restrict this list to the files matching the regexp
442 MATCH. If SKIP-FILE is non-nil, skip file matching the regexp
443 SKIP-FILE. If SKIP-DIR is non-nil, don't check directories
444 matching the regexp SKIP-DIR when recursing through BASE-DIR."
445 (mapc (lambda (f)
446 (let ((fd-p (file-directory-p f))
447 (fnd (file-name-nondirectory f)))
448 (if (and fd-p recurse
449 (not (string-match "^\\.+$" fnd))
450 (if skip-dir (not (string-match skip-dir fnd)) t))
451 (org-publish-get-base-files-1
452 f recurse match skip-file skip-dir)
453 (unless (or fd-p ;; this is a directory
454 (and skip-file (string-match skip-file fnd))
455 (not (file-exists-p (file-truename f)))
456 (not (string-match match fnd)))
458 (pushnew f org-publish-temp-files)))))
459 (let ((all-files (if (not recurse) (directory-files base-dir t match)
460 ;; If RECURSE is non-nil, we want all files
461 ;; matching MATCH and sub-directories.
462 (org-remove-if-not
463 (lambda (file)
464 (or (file-directory-p file)
465 (and match (string-match match file))))
466 (directory-files base-dir t)))))
467 (if (not org-publish-sitemap-requested) all-files
468 (sort all-files 'org-publish-compare-directory-files)))))
470 (defun org-publish-get-base-files (project &optional exclude-regexp)
471 "Return a list of all files in PROJECT.
472 If EXCLUDE-REGEXP is set, this will be used to filter out
473 matching filenames."
474 (let* ((project-plist (cdr project))
475 (base-dir (file-name-as-directory
476 (plist-get project-plist :base-directory)))
477 (include-list (plist-get project-plist :include))
478 (recurse (plist-get project-plist :recursive))
479 (extension (or (plist-get project-plist :base-extension) "org"))
480 ;; sitemap-... variables are dynamically scoped for
481 ;; org-publish-compare-directory-files:
482 (org-publish-sitemap-requested
483 (plist-get project-plist :auto-sitemap))
484 (sitemap-filename
485 (or (plist-get project-plist :sitemap-filename) "sitemap.org"))
486 (org-publish-sitemap-sort-folders
487 (if (plist-member project-plist :sitemap-sort-folders)
488 (plist-get project-plist :sitemap-sort-folders)
489 org-publish-sitemap-sort-folders))
490 (org-publish-sitemap-sort-files
491 (cond ((plist-member project-plist :sitemap-sort-files)
492 (plist-get project-plist :sitemap-sort-files))
493 ;; For backward compatibility:
494 ((plist-member project-plist :sitemap-alphabetically)
495 (if (plist-get project-plist :sitemap-alphabetically)
496 'alphabetically nil))
497 (t org-publish-sitemap-sort-files)))
498 (org-publish-sitemap-ignore-case
499 (if (plist-member project-plist :sitemap-ignore-case)
500 (plist-get project-plist :sitemap-ignore-case)
501 org-publish-sitemap-sort-ignore-case))
502 (match (if (eq extension 'any) "^[^\\.]"
503 (concat "^[^\\.].*\\.\\(" extension "\\)$"))))
504 ;; Make sure `org-publish-sitemap-sort-folders' has an accepted
505 ;; value.
506 (unless (memq org-publish-sitemap-sort-folders '(first last))
507 (setq org-publish-sitemap-sort-folders nil))
509 (setq org-publish-temp-files nil)
510 (if org-publish-sitemap-requested
511 (pushnew (expand-file-name (concat base-dir sitemap-filename))
512 org-publish-temp-files))
513 (org-publish-get-base-files-1 base-dir recurse match
514 ;; FIXME distinguish exclude regexp
515 ;; for skip-file and skip-dir?
516 exclude-regexp exclude-regexp)
517 (mapc (lambda (f)
518 (pushnew
519 (expand-file-name (concat base-dir f))
520 org-publish-temp-files))
521 include-list)
522 org-publish-temp-files))
524 (defun org-publish-get-project-from-filename (filename &optional up)
525 "Return the project that FILENAME belongs to."
526 (let* ((filename (expand-file-name filename))
527 project-name)
529 (catch 'p-found
530 (dolist (prj org-publish-project-alist)
531 (unless (plist-get (cdr prj) :components)
532 ;; [[info:org:Selecting%20files]] shows how this is supposed to work:
533 (let* ((r (plist-get (cdr prj) :recursive))
534 (b (expand-file-name (file-name-as-directory
535 (plist-get (cdr prj) :base-directory))))
536 (x (or (plist-get (cdr prj) :base-extension) "org"))
537 (e (plist-get (cdr prj) :exclude))
538 (i (plist-get (cdr prj) :include))
539 (xm (concat "^" b (if r ".+" "[^/]+") "\\.\\(" x "\\)$")))
540 (when
541 (or (and i
542 (member filename
543 (mapcar (lambda (file)
544 (expand-file-name file b))
545 i)))
546 (and (not (and e (string-match e filename)))
547 (string-match xm filename)))
548 (setq project-name (car prj))
549 (throw 'p-found project-name))))))
550 (when up
551 (dolist (prj org-publish-project-alist)
552 (if (member project-name (plist-get (cdr prj) :components))
553 (setq project-name (car prj)))))
554 (assoc project-name org-publish-project-alist)))
558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
559 ;;; Tools for publishing functions in back-ends
561 (defun org-publish-org-to (backend filename extension plist &optional pub-dir)
562 "Publish an Org file to a specified back-end.
564 BACKEND is a symbol representing the back-end used for
565 transcoding. FILENAME is the filename of the Org file to be
566 published. EXTENSION is the extension used for the output
567 string, with the leading dot. PLIST is the property list for the
568 given project.
570 Optional argument PUB-DIR, when non-nil is the publishing
571 directory.
573 Return output file name."
574 (unless (or (not pub-dir) (file-exists-p pub-dir)) (make-directory pub-dir t))
575 ;; Check if a buffer visiting FILENAME is already open.
576 (let* ((org-inhibit-startup t)
577 (visitingp (find-buffer-visiting filename))
578 (work-buffer (or visitingp (find-file-noselect filename))))
579 (prog1 (with-current-buffer work-buffer
580 (let ((output-file
581 (org-export-output-file-name extension nil pub-dir))
582 (body-p (plist-get plist :body-only)))
583 (org-export-to-file backend output-file
584 nil nil nil body-p
585 ;; Add `org-publish-collect-numbering' and
586 ;; `org-publish-collect-index' to final output
587 ;; filters. The latter isn't dependent on
588 ;; `:makeindex', since we want to keep it up-to-date
589 ;; in cache anyway.
590 (org-combine-plists
591 plist
592 `(:filter-final-output
593 ,(cons 'org-publish-collect-numbering
594 (cons 'org-publish-collect-index
595 (plist-get plist :filter-final-output))))))))
596 ;; Remove opened buffer in the process.
597 (unless visitingp (kill-buffer work-buffer)))))
599 (defun org-publish-attachment (plist filename pub-dir)
600 "Publish a file with no transformation of any kind.
602 FILENAME is the filename of the Org file to be published. PLIST
603 is the property list for the given project. PUB-DIR is the
604 publishing directory.
606 Return output file name."
607 (unless (file-directory-p pub-dir)
608 (make-directory pub-dir t))
609 (let ((output (expand-file-name (file-name-nondirectory filename) pub-dir)))
610 (or (equal (expand-file-name (file-name-directory filename))
611 (file-name-as-directory (expand-file-name pub-dir)))
612 (copy-file filename output t))
613 ;; Return file name.
614 output))
618 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
619 ;;; Publishing files, sets of files, and indices
621 (defun org-publish-file (filename &optional project no-cache)
622 "Publish file FILENAME from PROJECT.
623 If NO-CACHE is not nil, do not initialize org-publish-cache and
624 write it to disk. This is needed, since this function is used to
625 publish single files, when entire projects are published.
626 See `org-publish-projects'."
627 (let* ((project
628 (or project
629 (or (org-publish-get-project-from-filename filename)
630 (error "File %s not part of any known project"
631 (abbreviate-file-name filename)))))
632 (project-plist (cdr project))
633 (ftname (expand-file-name filename))
634 (publishing-function
635 (let ((fun (plist-get project-plist :publishing-function)))
636 (cond ((null fun) (error "No publishing function chosen"))
637 ((listp fun) fun)
638 (t (list fun)))))
639 (base-dir
640 (file-name-as-directory
641 (expand-file-name
642 (or (plist-get project-plist :base-directory)
643 (error "Project %s does not have :base-directory defined"
644 (car project))))))
645 (pub-dir
646 (file-name-as-directory
647 (file-truename
648 (or (eval (plist-get project-plist :publishing-directory))
649 (error "Project %s does not have :publishing-directory defined"
650 (car project))))))
651 tmp-pub-dir)
653 (unless no-cache (org-publish-initialize-cache (car project)))
655 (setq tmp-pub-dir
656 (file-name-directory
657 (concat pub-dir
658 (and (string-match (regexp-quote base-dir) ftname)
659 (substring ftname (match-end 0))))))
660 ;; Allow chain of publishing functions.
661 (dolist (f publishing-function)
662 (when (org-publish-needed-p filename pub-dir f tmp-pub-dir base-dir)
663 (let ((output (funcall f project-plist filename tmp-pub-dir)))
664 (org-publish-update-timestamp filename pub-dir f base-dir)
665 (run-hook-with-args 'org-publish-after-publishing-hook
666 filename
667 output))))
668 (unless no-cache (org-publish-write-cache-file))))
670 (defun org-publish-projects (projects)
671 "Publish all files belonging to the PROJECTS alist.
672 If `:auto-sitemap' is set, publish the sitemap too. If
673 `:makeindex' is set, also produce a file theindex.org."
674 (mapc
675 (lambda (project)
676 ;; Each project uses its own cache file:
677 (org-publish-initialize-cache (car project))
678 (let* ((project-plist (cdr project))
679 (exclude-regexp (plist-get project-plist :exclude))
680 (sitemap-p (plist-get project-plist :auto-sitemap))
681 (sitemap-filename (or (plist-get project-plist :sitemap-filename)
682 "sitemap.org"))
683 (sitemap-function (or (plist-get project-plist :sitemap-function)
684 'org-publish-org-sitemap))
685 (org-publish-sitemap-date-format
686 (or (plist-get project-plist :sitemap-date-format)
687 org-publish-sitemap-date-format))
688 (org-publish-sitemap-file-entry-format
689 (or (plist-get project-plist :sitemap-file-entry-format)
690 org-publish-sitemap-file-entry-format))
691 (preparation-function
692 (plist-get project-plist :preparation-function))
693 (completion-function (plist-get project-plist :completion-function))
694 (files (org-publish-get-base-files project exclude-regexp))
695 (theindex
696 (expand-file-name "theindex.org"
697 (plist-get project-plist :base-directory))))
698 (when preparation-function (run-hooks 'preparation-function))
699 (if sitemap-p (funcall sitemap-function project sitemap-filename))
700 ;; Publish all files from PROJECT excepted "theindex.org". Its
701 ;; publishing will be deferred until "theindex.inc" is
702 ;; populated.
703 (dolist (file files)
704 (unless (equal file theindex)
705 (org-publish-file file project t)))
706 ;; Populate "theindex.inc", if needed, and publish
707 ;; "theindex.org".
708 (when (plist-get project-plist :makeindex)
709 (org-publish-index-generate-theindex
710 project (plist-get project-plist :base-directory))
711 (org-publish-file theindex project t))
712 (when completion-function (run-hooks 'completion-function))
713 (org-publish-write-cache-file)))
714 (org-publish-expand-projects projects)))
716 (defun org-publish-org-sitemap (project &optional sitemap-filename)
717 "Create a sitemap of pages in set defined by PROJECT.
718 Optionally set the filename of the sitemap with SITEMAP-FILENAME.
719 Default for SITEMAP-FILENAME is 'sitemap.org'."
720 (let* ((project-plist (cdr project))
721 (dir (file-name-as-directory
722 (plist-get project-plist :base-directory)))
723 (localdir (file-name-directory dir))
724 (indent-str (make-string 2 ?\ ))
725 (exclude-regexp (plist-get project-plist :exclude))
726 (files (nreverse
727 (org-publish-get-base-files project exclude-regexp)))
728 (sitemap-filename (concat dir (or sitemap-filename "sitemap.org")))
729 (sitemap-title (or (plist-get project-plist :sitemap-title)
730 (concat "Sitemap for project " (car project))))
731 (sitemap-style (or (plist-get project-plist :sitemap-style)
732 'tree))
733 (sitemap-sans-extension
734 (plist-get project-plist :sitemap-sans-extension))
735 (visiting (find-buffer-visiting sitemap-filename))
736 (ifn (file-name-nondirectory sitemap-filename))
737 file sitemap-buffer)
738 (with-current-buffer
739 (let ((org-inhibit-startup t))
740 (setq sitemap-buffer
741 (or visiting (find-file sitemap-filename))))
742 (erase-buffer)
743 (insert (concat "#+TITLE: " sitemap-title "\n\n"))
744 (while (setq file (pop files))
745 (let ((fn (file-name-nondirectory file))
746 (link (file-relative-name file dir))
747 (oldlocal localdir))
748 (when sitemap-sans-extension
749 (setq link (file-name-sans-extension link)))
750 ;; sitemap shouldn't list itself
751 (unless (equal (file-truename sitemap-filename)
752 (file-truename file))
753 (if (eq sitemap-style 'list)
754 (message "Generating list-style sitemap for %s" sitemap-title)
755 (message "Generating tree-style sitemap for %s" sitemap-title)
756 (setq localdir (concat (file-name-as-directory dir)
757 (file-name-directory link)))
758 (unless (string= localdir oldlocal)
759 (if (string= localdir dir)
760 (setq indent-str (make-string 2 ?\ ))
761 (let ((subdirs
762 (split-string
763 (directory-file-name
764 (file-name-directory
765 (file-relative-name localdir dir))) "/"))
766 (subdir "")
767 (old-subdirs (split-string
768 (file-relative-name oldlocal dir) "/")))
769 (setq indent-str (make-string 2 ?\ ))
770 (while (string= (car old-subdirs) (car subdirs))
771 (setq indent-str (concat indent-str (make-string 2 ?\ )))
772 (pop old-subdirs)
773 (pop subdirs))
774 (dolist (d subdirs)
775 (setq subdir (concat subdir d "/"))
776 (insert (concat indent-str " + " d "\n"))
777 (setq indent-str (make-string
778 (+ (length indent-str) 2) ?\ )))))))
779 ;; This is common to 'flat and 'tree
780 (let ((entry
781 (org-publish-format-file-entry
782 org-publish-sitemap-file-entry-format file project-plist))
783 (regexp "\\(.*\\)\\[\\([^][]+\\)\\]\\(.*\\)"))
784 (cond ((string-match-p regexp entry)
785 (string-match regexp entry)
786 (insert (concat indent-str " + " (match-string 1 entry)
787 "[[file:" link "]["
788 (match-string 2 entry)
789 "]]" (match-string 3 entry) "\n")))
791 (insert (concat indent-str " + [[file:" link "]["
792 entry
793 "]]\n"))))))))
794 (save-buffer))
795 (or visiting (kill-buffer sitemap-buffer))))
797 (defun org-publish-format-file-entry (fmt file project-plist)
798 (format-spec
800 `((?t . ,(org-publish-find-title file t))
801 (?d . ,(format-time-string org-publish-sitemap-date-format
802 (org-publish-find-date file)))
803 (?a . ,(or (plist-get project-plist :author) user-full-name)))))
805 (defun org-publish-find-title (file &optional reset)
806 "Find the title of FILE in project."
808 (and (not reset) (org-publish-cache-get-file-property file :title nil t))
809 (let* ((org-inhibit-startup t)
810 (visiting (find-buffer-visiting file))
811 (buffer (or visiting (find-file-noselect file))))
812 (with-current-buffer buffer
813 (org-mode)
814 (let ((title
815 (let ((property (plist-get (org-export-get-environment) :title)))
816 (if property (org-element-interpret-data property)
817 (file-name-nondirectory (file-name-sans-extension file))))))
818 (unless visiting (kill-buffer buffer))
819 (org-publish-cache-set-file-property file :title title)
820 title)))))
822 (defun org-publish-find-date (file)
823 "Find the date of FILE in project.
824 This function assumes FILE is either a directory or an Org file.
825 If FILE is an Org file and provides a DATE keyword use it. In
826 any other case use the file system's modification time. Return
827 time in `current-time' format."
828 (if (file-directory-p file) (nth 5 (file-attributes file))
829 (let* ((visiting (find-buffer-visiting file))
830 (file-buf (or visiting (find-file-noselect file nil)))
831 (date (plist-get
832 (with-current-buffer file-buf
833 (let ((org-inhibit-startup t)) (org-mode))
834 (org-export-get-environment))
835 :date)))
836 (unless visiting (kill-buffer file-buf))
837 ;; DATE is either a timestamp object or a secondary string. If it
838 ;; is a timestamp or if the secondary string contains a timestamp,
839 ;; convert it to internal format. Otherwise, use FILE
840 ;; modification time.
841 (cond ((eq (org-element-type date) 'timestamp)
842 (org-time-string-to-time (org-element-interpret-data date)))
843 ((let ((ts (and (consp date) (assq 'timestamp date))))
844 (and ts
845 (let ((value (org-element-interpret-data ts)))
846 (and (org-string-nw-p value)
847 (org-time-string-to-time value))))))
848 ((file-exists-p file) (nth 5 (file-attributes file)))
849 (t (error "No such file: \"%s\"" file))))))
853 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
854 ;;; Interactive publishing functions
856 ;;;###autoload
857 (defalias 'org-publish-project 'org-publish)
859 ;;;###autoload
860 (defun org-publish (project &optional force async)
861 "Publish PROJECT.
863 PROJECT is either a project name, as a string, or a project
864 alist (see `org-publish-project-alist' variable).
866 When optional argument FORCE is non-nil, force publishing all
867 files in PROJECT. With a non-nil optional argument ASYNC,
868 publishing will be done asynchronously, in another process."
869 (interactive
870 (list
871 (assoc (org-icompleting-read
872 "Publish project: "
873 org-publish-project-alist nil t)
874 org-publish-project-alist)
875 current-prefix-arg))
876 (let ((project-alist (if (not (stringp project)) (list project)
877 ;; If this function is called in batch mode,
878 ;; project is still a string here.
879 (list (assoc project org-publish-project-alist)))))
880 (if async
881 (org-export-async-start 'ignore
882 `(let ((org-publish-use-timestamps-flag
883 (if ',force nil ,org-publish-use-timestamps-flag)))
884 (org-publish-projects ',project-alist)))
885 (save-window-excursion
886 (let* ((org-publish-use-timestamps-flag
887 (if force nil org-publish-use-timestamps-flag)))
888 (org-publish-projects project-alist))))))
890 ;;;###autoload
891 (defun org-publish-all (&optional force async)
892 "Publish all projects.
893 With prefix argument FORCE, remove all files in the timestamp
894 directory and force publishing all projects. With a non-nil
895 optional argument ASYNC, publishing will be done asynchronously,
896 in another process."
897 (interactive "P")
898 (if async
899 (org-export-async-start 'ignore
900 `(progn
901 (when ',force (org-publish-remove-all-timestamps))
902 (let ((org-publish-use-timestamps-flag
903 (if ',force nil ,org-publish-use-timestamps-flag)))
904 (org-publish-projects ',org-publish-project-alist))))
905 (when force (org-publish-remove-all-timestamps))
906 (save-window-excursion
907 (let ((org-publish-use-timestamps-flag
908 (if force nil org-publish-use-timestamps-flag)))
909 (org-publish-projects org-publish-project-alist)))))
912 ;;;###autoload
913 (defun org-publish-current-file (&optional force async)
914 "Publish the current file.
915 With prefix argument FORCE, force publish the file. When
916 optional argument ASYNC is non-nil, publishing will be done
917 asynchronously, in another process."
918 (interactive "P")
919 (let ((file (buffer-file-name (buffer-base-buffer))))
920 (if async
921 (org-export-async-start 'ignore
922 `(let ((org-publish-use-timestamps-flag
923 (if ',force nil ,org-publish-use-timestamps-flag)))
924 (org-publish-file ,file)))
925 (save-window-excursion
926 (let ((org-publish-use-timestamps-flag
927 (if force nil org-publish-use-timestamps-flag)))
928 (org-publish-file file))))))
930 ;;;###autoload
931 (defun org-publish-current-project (&optional force async)
932 "Publish the project associated with the current file.
933 With a prefix argument, force publishing of all files in
934 the project."
935 (interactive "P")
936 (save-window-excursion
937 (let ((project (org-publish-get-project-from-filename
938 (buffer-file-name (buffer-base-buffer)) 'up)))
939 (if project (org-publish project force async)
940 (error "File %s is not part of any known project"
941 (buffer-file-name (buffer-base-buffer)))))))
945 ;;; Index generation
947 (defun org-publish-collect-index (output backend info)
948 "Update index for a file in cache.
950 OUTPUT is the output from transcoding current file. BACKEND is
951 the back-end that was used for transcoding. INFO is a plist
952 containing publishing and export options.
954 The index relative to current file is stored as an alist. An
955 association has the following shape: (TERM FILE-NAME PARENT),
956 where TERM is the indexed term, as a string, FILE-NAME is the
957 original full path of the file where the term in encountered, and
958 PARENT is a reference to the headline, if any, containing the
959 original index keyword. When non-nil, this reference is a cons
960 cell. Its CAR is a symbol among `id', `custom-id' and `name' and
961 its CDR is a string."
962 (let ((file (plist-get info :input-file)))
963 (org-publish-cache-set-file-property
964 file :index
965 (delete-dups
966 (org-element-map (plist-get info :parse-tree) 'keyword
967 (lambda (k)
968 (when (equal (org-element-property :key k) "INDEX")
969 (let ((parent (org-export-get-parent-headline k)))
970 (list (org-element-property :value k)
971 file
972 (cond
973 ((not parent) nil)
974 ((let ((id (org-element-property :ID parent)))
975 (and id (cons 'id id))))
976 ((let ((id (org-element-property :CUSTOM_ID parent)))
977 (and id (cons 'custom-id id))))
978 (t (cons 'name
979 ;; Remove statistics cookie.
980 (replace-regexp-in-string
981 "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
982 (org-element-property :raw-value parent)))))))))
983 info))))
984 ;; Return output unchanged.
985 output)
987 (defun org-publish-index-generate-theindex (project directory)
988 "Retrieve full index from cache and build \"theindex.org\".
989 PROJECT is the project the index relates to. DIRECTORY is the
990 publishing directory."
991 (let ((all-files (org-publish-get-base-files
992 project (plist-get (cdr project) :exclude)))
993 full-index)
994 ;; Compile full index and sort it alphabetically.
995 (dolist (file all-files
996 (setq full-index
997 (sort (nreverse full-index)
998 (lambda (a b) (string< (downcase (car a))
999 (downcase (car b)))))))
1000 (let ((index (org-publish-cache-get-file-property file :index)))
1001 (dolist (term index)
1002 (unless (member term full-index) (push term full-index)))))
1003 ;; Write "theindex.inc" in DIRECTORY.
1004 (with-temp-file (expand-file-name "theindex.inc" directory)
1005 (let ((current-letter nil) (last-entry nil))
1006 (dolist (idx full-index)
1007 (let* ((entry (org-split-string (car idx) "!"))
1008 (letter (upcase (substring (car entry) 0 1)))
1009 ;; Transform file into a path relative to publishing
1010 ;; directory.
1011 (file (file-relative-name
1012 (nth 1 idx)
1013 (plist-get (cdr project) :base-directory))))
1014 ;; Check if another letter has to be inserted.
1015 (unless (string= letter current-letter)
1016 (insert (format "* %s\n" letter)))
1017 ;; Compute the first difference between last entry and
1018 ;; current one: it tells the level at which new items
1019 ;; should be added.
1020 (let* ((rank (if (equal entry last-entry) (1- (length entry))
1021 (loop for n from 0 to (length entry)
1022 unless (equal (nth n entry) (nth n last-entry))
1023 return n)))
1024 (len (length (nthcdr rank entry))))
1025 ;; For each term after the first difference, create
1026 ;; a new sub-list with the term as body. Moreover,
1027 ;; linkify the last term.
1028 (dotimes (n len)
1029 (insert
1030 (concat
1031 (make-string (* (+ rank n) 2) ? ) " - "
1032 (if (not (= (1- len) n)) (nth (+ rank n) entry)
1033 ;; Last term: Link it to TARGET, if possible.
1034 (let ((target (nth 2 idx)))
1035 (format
1036 "[[%s][%s]]"
1037 ;; Destination.
1038 (case (car target)
1039 ('nil (format "file:%s" file))
1040 (id (format "id:%s" (cdr target)))
1041 (custom-id (format "file:%s::#%s" file (cdr target)))
1042 (otherwise (format "file:%s::*%s" file (cdr target))))
1043 ;; Description.
1044 (car (last entry)))))
1045 "\n"))))
1046 (setq current-letter letter last-entry entry))))
1047 ;; Create "theindex.org", if it doesn't exist yet, and provide
1048 ;; a default index file.
1049 (let ((index.org (expand-file-name "theindex.org" directory)))
1050 (unless (file-exists-p index.org)
1051 (with-temp-file index.org
1052 (insert "#+TITLE: Index\n\n#+INCLUDE: \"theindex.inc\"\n\n")))))))
1056 ;;; External Fuzzy Links Resolution
1058 ;; This part implements tools to resolve [[file.org::*Some headline]]
1059 ;; links, where "file.org" belongs to the current project.
1061 (defun org-publish-collect-numbering (output backend info)
1062 (org-publish-cache-set-file-property
1063 (plist-get info :input-file) :numbering
1064 (mapcar (lambda (entry)
1065 (cons (org-split-string
1066 (replace-regexp-in-string
1067 "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
1068 (org-element-property :raw-value (car entry))))
1069 (cdr entry)))
1070 (plist-get info :headline-numbering)))
1071 ;; Return output unchanged.
1072 output)
1074 (defun org-publish-resolve-external-fuzzy-link (file fuzzy)
1075 "Return numbering for headline matching FUZZY search in FILE.
1077 Return value is a list of numbers, or nil. This function allows
1078 to resolve external fuzzy links like:
1080 [[file.org::*fuzzy][description]]"
1081 (when org-publish-cache
1082 (cdr (assoc (org-split-string
1083 (if (eq (aref fuzzy 0) ?*) (substring fuzzy 1) fuzzy))
1084 (org-publish-cache-get-file-property
1085 (expand-file-name file) :numbering nil t)))))
1089 ;;; Caching functions
1091 (defun org-publish-write-cache-file (&optional free-cache)
1092 "Write `org-publish-cache' to file.
1093 If FREE-CACHE, empty the cache."
1094 (unless org-publish-cache
1095 (error "`org-publish-write-cache-file' called, but no cache present"))
1097 (let ((cache-file (org-publish-cache-get ":cache-file:")))
1098 (unless cache-file
1099 (error "Cannot find cache-file name in `org-publish-write-cache-file'"))
1100 (with-temp-file cache-file
1101 (let (print-level print-length)
1102 (insert "(setq org-publish-cache (make-hash-table :test 'equal :weakness nil :size 100))\n")
1103 (maphash (lambda (k v)
1104 (insert
1105 (format (concat "(puthash %S "
1106 (if (or (listp v) (symbolp v))
1107 "'" "")
1108 "%S org-publish-cache)\n") k v)))
1109 org-publish-cache)))
1110 (when free-cache (org-publish-reset-cache))))
1112 (defun org-publish-initialize-cache (project-name)
1113 "Initialize the projects cache if not initialized yet and return it."
1115 (unless project-name
1116 (error "Cannot initialize `org-publish-cache' without projects name in `org-publish-initialize-cache'"))
1118 (unless (file-exists-p org-publish-timestamp-directory)
1119 (make-directory org-publish-timestamp-directory t))
1120 (unless (file-directory-p org-publish-timestamp-directory)
1121 (error "Org publish timestamp: %s is not a directory"
1122 org-publish-timestamp-directory))
1124 (unless (and org-publish-cache
1125 (string= (org-publish-cache-get ":project:") project-name))
1126 (let* ((cache-file
1127 (concat
1128 (expand-file-name org-publish-timestamp-directory)
1129 project-name ".cache"))
1130 (cexists (file-exists-p cache-file)))
1132 (when org-publish-cache (org-publish-reset-cache))
1134 (if cexists (load-file cache-file)
1135 (setq org-publish-cache
1136 (make-hash-table :test 'equal :weakness nil :size 100))
1137 (org-publish-cache-set ":project:" project-name)
1138 (org-publish-cache-set ":cache-file:" cache-file))
1139 (unless cexists (org-publish-write-cache-file nil))))
1140 org-publish-cache)
1142 (defun org-publish-reset-cache ()
1143 "Empty org-publish-cache and reset it nil."
1144 (message "%s" "Resetting org-publish-cache")
1145 (when (hash-table-p org-publish-cache)
1146 (clrhash org-publish-cache))
1147 (setq org-publish-cache nil))
1149 (defun org-publish-cache-file-needs-publishing
1150 (filename &optional pub-dir pub-func base-dir)
1151 "Check the timestamp of the last publishing of FILENAME.
1152 Return non-nil if the file needs publishing. Also check if
1153 any included files have been more recently published, so that
1154 the file including them will be republished as well."
1155 (unless org-publish-cache
1156 (error
1157 "`org-publish-cache-file-needs-publishing' called, but no cache present"))
1158 (let* ((case-fold-search t)
1159 (key (org-publish-timestamp-filename filename pub-dir pub-func))
1160 (pstamp (org-publish-cache-get key))
1161 (org-inhibit-startup t)
1162 (visiting (find-buffer-visiting filename))
1163 included-files-ctime buf)
1165 (when (equal (file-name-extension filename) "org")
1166 (setq buf (find-file (expand-file-name filename)))
1167 (with-current-buffer buf
1168 (goto-char (point-min))
1169 (while (re-search-forward
1170 "^#\\+INCLUDE:[ \t]+\"\\([^\t\n\r\"]*\\)\"[ \t]*.*$" nil t)
1171 (let* ((included-file (expand-file-name (match-string 1))))
1172 (add-to-list 'included-files-ctime
1173 (org-publish-cache-ctime-of-src included-file) t))))
1174 (unless visiting (kill-buffer buf)))
1175 (if (null pstamp) t
1176 (let ((ctime (org-publish-cache-ctime-of-src filename)))
1177 (or (< pstamp ctime)
1178 (when included-files-ctime
1179 (not (null (delq nil (mapcar (lambda(ct) (< ctime ct))
1180 included-files-ctime))))))))))
1182 (defun org-publish-cache-set-file-property
1183 (filename property value &optional project-name)
1184 "Set the VALUE for a PROPERTY of file FILENAME in publishing cache to VALUE.
1185 Use cache file of PROJECT-NAME. If the entry does not exist, it
1186 will be created. Return VALUE."
1187 ;; Evtl. load the requested cache file:
1188 (if project-name (org-publish-initialize-cache project-name))
1189 (let ((pl (org-publish-cache-get filename)))
1190 (if pl (progn (plist-put pl property value) value)
1191 (org-publish-cache-get-file-property
1192 filename property value nil project-name))))
1194 (defun org-publish-cache-get-file-property
1195 (filename property &optional default no-create project-name)
1196 "Return the value for a PROPERTY of file FILENAME in publishing cache.
1197 Use cache file of PROJECT-NAME. Return the value of that PROPERTY
1198 or DEFAULT, if the value does not yet exist. If the entry will
1199 be created, unless NO-CREATE is not nil."
1200 ;; Evtl. load the requested cache file:
1201 (if project-name (org-publish-initialize-cache project-name))
1202 (let ((pl (org-publish-cache-get filename)) retval)
1203 (if pl
1204 (if (plist-member pl property)
1205 (setq retval (plist-get pl property))
1206 (setq retval default))
1207 ;; no pl yet:
1208 (unless no-create
1209 (org-publish-cache-set filename (list property default)))
1210 (setq retval default))
1211 retval))
1213 (defun org-publish-cache-get (key)
1214 "Return the value stored in `org-publish-cache' for key KEY.
1215 Returns nil, if no value or nil is found, or the cache does not
1216 exist."
1217 (unless org-publish-cache
1218 (error "`org-publish-cache-get' called, but no cache present"))
1219 (gethash key org-publish-cache))
1221 (defun org-publish-cache-set (key value)
1222 "Store KEY VALUE pair in `org-publish-cache'.
1223 Returns value on success, else nil."
1224 (unless org-publish-cache
1225 (error "`org-publish-cache-set' called, but no cache present"))
1226 (puthash key value org-publish-cache))
1228 (defun org-publish-cache-ctime-of-src (file)
1229 "Get the ctime of FILE as an integer."
1230 (let ((attr (file-attributes
1231 (expand-file-name (or (file-symlink-p file) file)
1232 (file-name-directory file)))))
1233 (if (not attr) (error "No such file: \"%s\"" file)
1234 (+ (lsh (car (nth 5 attr)) 16)
1235 (cadr (nth 5 attr))))))
1238 (provide 'ox-publish)
1240 ;; Local variables:
1241 ;; generated-autoload-file: "org-loaddefs.el"
1242 ;; End:
1244 ;;; ox-publish.el ends here