ox: Optional export of title
[org-mode.git] / lisp / ox-publish.el
blob3cca0c9589992a2e3796f6dd2b699e573992d85b
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-planning `org-export-with-planning'
179 :with-priority `org-export-with-priority'
180 :with-properties `org-export-with-properties'
181 :with-smart-quotes `org-export-with-smart-quotes'
182 :with-special-strings `org-export-with-special-strings'
183 :with-statistics-cookies' `org-export-with-statistics-cookies'
184 :with-sub-superscript `org-export-with-sub-superscripts'
185 :with-toc `org-export-with-toc'
186 :with-tables `org-export-with-tables'
187 :with-tags `org-export-with-tags'
188 :with-tasks `org-export-with-tasks'
189 :with-timestamps `org-export-with-timestamps'
190 :with-title `org-export-with-title'
191 :with-todo-keywords `org-export-with-todo-keywords'
193 The following properties may be used to control publishing of
194 a site-map of files or summary page for a given project.
196 `:auto-sitemap'
198 Whether to publish a site-map during
199 `org-publish-current-project' or `org-publish-all'.
201 `:sitemap-filename'
203 Filename for output of sitemap. Defaults to \"sitemap.org\".
205 `:sitemap-title'
207 Title of site-map page. Defaults to name of file.
209 `:sitemap-function'
211 Plugin function to use for generation of site-map. Defaults
212 to `org-publish-org-sitemap', which generates a plain list of
213 links to all files in the project.
215 `:sitemap-style'
217 Can be `list' (site-map is just an itemized list of the
218 titles of the files involved) or `tree' (the directory
219 structure of the source files is reflected in the site-map).
220 Defaults to `tree'.
222 `:sitemap-sans-extension'
224 Remove extension from site-map's file-names. Useful to have
225 cool URIs (see http://www.w3.org/Provider/Style/URI).
226 Defaults to nil.
228 If you create a site-map file, adjust the sorting like this:
230 `:sitemap-sort-folders'
232 Where folders should appear in the site-map. Set this to
233 `first' (default) or `last' to display folders first or last,
234 respectively. Any other value will mix files and folders.
236 `:sitemap-sort-files'
238 The site map is normally sorted alphabetically. You can
239 change this behaviour setting this to `anti-chronologically',
240 `chronologically', or nil.
242 `:sitemap-ignore-case'
244 Should sorting be case-sensitive? Default nil.
246 The following property control the creation of a concept index.
248 `:makeindex'
250 Create a concept index. The file containing the index has to
251 be called \"theindex.org\". If it doesn't exist in the
252 project, it will be generated. Contents of the index are
253 stored in the file \"theindex.inc\", which can be included in
254 \"theindex.org\".
256 Other properties affecting publication.
258 `:body-only'
260 Set this to t to publish only the body of the documents."
261 :group 'org-export-publish
262 :type 'alist)
264 (defcustom org-publish-use-timestamps-flag t
265 "Non-nil means use timestamp checking to publish only changed files.
266 When nil, do no timestamp checking and always publish all files."
267 :group 'org-export-publish
268 :type 'boolean)
270 (defcustom org-publish-timestamp-directory
271 (convert-standard-filename "~/.org-timestamps/")
272 "Name of directory in which to store publishing timestamps."
273 :group 'org-export-publish
274 :type 'directory)
276 (defcustom org-publish-list-skipped-files t
277 "Non-nil means show message about files *not* published."
278 :group 'org-export-publish
279 :type 'boolean)
281 (defcustom org-publish-sitemap-sort-files 'alphabetically
282 "Method to sort files in site-maps.
283 Possible values are `alphabetically', `chronologically',
284 `anti-chronologically' and nil.
286 If `alphabetically', files will be sorted alphabetically. If
287 `chronologically', files will be sorted with older modification
288 time first. If `anti-chronologically', files will be sorted with
289 newer modification time first. nil won't sort files.
291 You can overwrite this default per project in your
292 `org-publish-project-alist', using `:sitemap-sort-files'."
293 :group 'org-export-publish
294 :type 'symbol)
296 (defcustom org-publish-sitemap-sort-folders 'first
297 "A symbol, denoting if folders are sorted first in sitemaps.
298 Possible values are `first', `last', and nil.
299 If `first', folders will be sorted before files.
300 If `last', folders are sorted to the end after the files.
301 Any other value will not mix files and folders.
303 You can overwrite this default per project in your
304 `org-publish-project-alist', using `:sitemap-sort-folders'."
305 :group 'org-export-publish
306 :type 'symbol)
308 (defcustom org-publish-sitemap-sort-ignore-case nil
309 "Non-nil when site-map sorting should ignore case.
311 You can overwrite this default per project in your
312 `org-publish-project-alist', using `:sitemap-ignore-case'."
313 :group 'org-export-publish
314 :type 'boolean)
316 (defcustom org-publish-sitemap-date-format "%Y-%m-%d"
317 "Format for printing a date in the sitemap.
318 See `format-time-string' for allowed formatters."
319 :group 'org-export-publish
320 :type 'string)
322 (defcustom org-publish-sitemap-file-entry-format "%t"
323 "Format string for site-map file entry.
324 You could use brackets to delimit on what part the link will be.
326 %t is the title.
327 %a is the author.
328 %d is the date formatted using `org-publish-sitemap-date-format'."
329 :group 'org-export-publish
330 :type 'string)
334 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
335 ;;; Timestamp-related functions
337 (defun org-publish-timestamp-filename (filename &optional pub-dir pub-func)
338 "Return path to timestamp file for filename FILENAME."
339 (setq filename (concat filename "::" (or pub-dir "") "::"
340 (format "%s" (or pub-func ""))))
341 (concat "X" (if (fboundp 'sha1) (sha1 filename) (md5 filename))))
343 (defun org-publish-needed-p
344 (filename &optional pub-dir pub-func true-pub-dir base-dir)
345 "Non-nil if FILENAME should be published in PUB-DIR using PUB-FUNC.
346 TRUE-PUB-DIR is where the file will truly end up. Currently we
347 are not using this - maybe it can eventually be used to check if
348 the file is present at the target location, and how old it is.
349 Right now we cannot do this, because we do not know under what
350 file name the file will be stored - the publishing function can
351 still decide about that independently."
352 (let ((rtn (if (not org-publish-use-timestamps-flag) t
353 (org-publish-cache-file-needs-publishing
354 filename pub-dir pub-func base-dir))))
355 (if rtn (message "Publishing file %s using `%s'" filename pub-func)
356 (when org-publish-list-skipped-files
357 (message "Skipping unmodified file %s" filename)))
358 rtn))
360 (defun org-publish-update-timestamp
361 (filename &optional pub-dir pub-func base-dir)
362 "Update publishing timestamp for file FILENAME.
363 If there is no timestamp, create one."
364 (let ((key (org-publish-timestamp-filename filename pub-dir pub-func))
365 (stamp (org-publish-cache-ctime-of-src filename)))
366 (org-publish-cache-set key stamp)))
368 (defun org-publish-remove-all-timestamps ()
369 "Remove all files in the timestamp directory."
370 (let ((dir org-publish-timestamp-directory)
371 files)
372 (when (and (file-exists-p dir) (file-directory-p dir))
373 (mapc 'delete-file (directory-files dir 'full "[^.]\\'"))
374 (org-publish-reset-cache))))
378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
379 ;;; Getting project information out of `org-publish-project-alist'
381 (defun org-publish-expand-projects (projects-alist)
382 "Expand projects in PROJECTS-ALIST.
383 This splices all the components into the list."
384 (let ((rest projects-alist) rtn p components)
385 (while (setq p (pop rest))
386 (if (setq components (plist-get (cdr p) :components))
387 (setq rest (append
388 (mapcar (lambda (x) (assoc x org-publish-project-alist))
389 components)
390 rest))
391 (push p rtn)))
392 (nreverse (delete-dups (delq nil rtn)))))
394 (defvar org-publish-sitemap-sort-files)
395 (defvar org-publish-sitemap-sort-folders)
396 (defvar org-publish-sitemap-ignore-case)
397 (defvar org-publish-sitemap-requested)
398 (defvar org-publish-sitemap-date-format)
399 (defvar org-publish-sitemap-file-entry-format)
400 (defun org-publish-compare-directory-files (a b)
401 "Predicate for `sort', that sorts folders and files for sitemap."
402 (let ((retval t))
403 (when (or org-publish-sitemap-sort-files org-publish-sitemap-sort-folders)
404 ;; First we sort files:
405 (when org-publish-sitemap-sort-files
406 (case org-publish-sitemap-sort-files
407 (alphabetically
408 (let* ((adir (file-directory-p a))
409 (aorg (and (string-match "\\.org$" a) (not adir)))
410 (bdir (file-directory-p b))
411 (borg (and (string-match "\\.org$" b) (not bdir)))
412 (A (if aorg (concat (file-name-directory a)
413 (org-publish-find-title a)) a))
414 (B (if borg (concat (file-name-directory b)
415 (org-publish-find-title b)) b)))
416 (setq retval (if org-publish-sitemap-ignore-case
417 (not (string-lessp (upcase B) (upcase A)))
418 (not (string-lessp B A))))))
419 ((anti-chronologically chronologically)
420 (let* ((adate (org-publish-find-date a))
421 (bdate (org-publish-find-date b))
422 (A (+ (lsh (car adate) 16) (cadr adate)))
423 (B (+ (lsh (car bdate) 16) (cadr bdate))))
424 (setq retval
425 (if (eq org-publish-sitemap-sort-files 'chronologically) (<= A B)
426 (>= A B)))))))
427 ;; Directory-wise wins:
428 (when org-publish-sitemap-sort-folders
429 ;; a is directory, b not:
430 (cond
431 ((and (file-directory-p a) (not (file-directory-p b)))
432 (setq retval (equal org-publish-sitemap-sort-folders 'first)))
433 ;; a is not a directory, but b is:
434 ((and (not (file-directory-p a)) (file-directory-p b))
435 (setq retval (equal org-publish-sitemap-sort-folders 'last))))))
436 retval))
438 (defun org-publish-get-base-files-1
439 (base-dir &optional recurse match skip-file skip-dir)
440 "Set `org-publish-temp-files' with files from BASE-DIR directory.
441 If RECURSE is non-nil, check BASE-DIR recursively. If MATCH is
442 non-nil, restrict this list to the files matching the regexp
443 MATCH. If SKIP-FILE is non-nil, skip file matching the regexp
444 SKIP-FILE. If SKIP-DIR is non-nil, don't check directories
445 matching the regexp SKIP-DIR when recursing through BASE-DIR."
446 (mapc (lambda (f)
447 (let ((fd-p (file-directory-p f))
448 (fnd (file-name-nondirectory f)))
449 (if (and fd-p recurse
450 (not (string-match "^\\.+$" fnd))
451 (if skip-dir (not (string-match skip-dir fnd)) t))
452 (org-publish-get-base-files-1
453 f recurse match skip-file skip-dir)
454 (unless (or fd-p ;; this is a directory
455 (and skip-file (string-match skip-file fnd))
456 (not (file-exists-p (file-truename f)))
457 (not (string-match match fnd)))
459 (pushnew f org-publish-temp-files)))))
460 (let ((all-files (if (not recurse) (directory-files base-dir t match)
461 ;; If RECURSE is non-nil, we want all files
462 ;; matching MATCH and sub-directories.
463 (org-remove-if-not
464 (lambda (file)
465 (or (file-directory-p file)
466 (and match (string-match match file))))
467 (directory-files base-dir t)))))
468 (if (not org-publish-sitemap-requested) all-files
469 (sort all-files 'org-publish-compare-directory-files)))))
471 (defun org-publish-get-base-files (project &optional exclude-regexp)
472 "Return a list of all files in PROJECT.
473 If EXCLUDE-REGEXP is set, this will be used to filter out
474 matching filenames."
475 (let* ((project-plist (cdr project))
476 (base-dir (file-name-as-directory
477 (plist-get project-plist :base-directory)))
478 (include-list (plist-get project-plist :include))
479 (recurse (plist-get project-plist :recursive))
480 (extension (or (plist-get project-plist :base-extension) "org"))
481 ;; sitemap-... variables are dynamically scoped for
482 ;; org-publish-compare-directory-files:
483 (org-publish-sitemap-requested
484 (plist-get project-plist :auto-sitemap))
485 (sitemap-filename
486 (or (plist-get project-plist :sitemap-filename) "sitemap.org"))
487 (org-publish-sitemap-sort-folders
488 (if (plist-member project-plist :sitemap-sort-folders)
489 (plist-get project-plist :sitemap-sort-folders)
490 org-publish-sitemap-sort-folders))
491 (org-publish-sitemap-sort-files
492 (cond ((plist-member project-plist :sitemap-sort-files)
493 (plist-get project-plist :sitemap-sort-files))
494 ;; For backward compatibility:
495 ((plist-member project-plist :sitemap-alphabetically)
496 (if (plist-get project-plist :sitemap-alphabetically)
497 'alphabetically nil))
498 (t org-publish-sitemap-sort-files)))
499 (org-publish-sitemap-ignore-case
500 (if (plist-member project-plist :sitemap-ignore-case)
501 (plist-get project-plist :sitemap-ignore-case)
502 org-publish-sitemap-sort-ignore-case))
503 (match (if (eq extension 'any) "^[^\\.]"
504 (concat "^[^\\.].*\\.\\(" extension "\\)$"))))
505 ;; Make sure `org-publish-sitemap-sort-folders' has an accepted
506 ;; value.
507 (unless (memq org-publish-sitemap-sort-folders '(first last))
508 (setq org-publish-sitemap-sort-folders nil))
510 (setq org-publish-temp-files nil)
511 (if org-publish-sitemap-requested
512 (pushnew (expand-file-name (concat base-dir sitemap-filename))
513 org-publish-temp-files))
514 (org-publish-get-base-files-1 base-dir recurse match
515 ;; FIXME distinguish exclude regexp
516 ;; for skip-file and skip-dir?
517 exclude-regexp exclude-regexp)
518 (mapc (lambda (f)
519 (pushnew
520 (expand-file-name (concat base-dir f))
521 org-publish-temp-files))
522 include-list)
523 org-publish-temp-files))
525 (defun org-publish-get-project-from-filename (filename &optional up)
526 "Return the project that FILENAME belongs to."
527 (let* ((filename (expand-file-name filename))
528 project-name)
530 (catch 'p-found
531 (dolist (prj org-publish-project-alist)
532 (unless (plist-get (cdr prj) :components)
533 ;; [[info:org:Selecting%20files]] shows how this is supposed to work:
534 (let* ((r (plist-get (cdr prj) :recursive))
535 (b (expand-file-name (file-name-as-directory
536 (plist-get (cdr prj) :base-directory))))
537 (x (or (plist-get (cdr prj) :base-extension) "org"))
538 (e (plist-get (cdr prj) :exclude))
539 (i (plist-get (cdr prj) :include))
540 (xm (concat "^" b (if r ".+" "[^/]+") "\\.\\(" x "\\)$")))
541 (when
542 (or (and i
543 (member filename
544 (mapcar (lambda (file)
545 (expand-file-name file b))
546 i)))
547 (and (not (and e (string-match e filename)))
548 (string-match xm filename)))
549 (setq project-name (car prj))
550 (throw 'p-found project-name))))))
551 (when up
552 (dolist (prj org-publish-project-alist)
553 (if (member project-name (plist-get (cdr prj) :components))
554 (setq project-name (car prj)))))
555 (assoc project-name org-publish-project-alist)))
559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
560 ;;; Tools for publishing functions in back-ends
562 (defun org-publish-org-to (backend filename extension plist &optional pub-dir)
563 "Publish an Org file to a specified back-end.
565 BACKEND is a symbol representing the back-end used for
566 transcoding. FILENAME is the filename of the Org file to be
567 published. EXTENSION is the extension used for the output
568 string, with the leading dot. PLIST is the property list for the
569 given project.
571 Optional argument PUB-DIR, when non-nil is the publishing
572 directory.
574 Return output file name."
575 (unless (or (not pub-dir) (file-exists-p pub-dir)) (make-directory pub-dir t))
576 ;; Check if a buffer visiting FILENAME is already open.
577 (let* ((org-inhibit-startup t)
578 (visitingp (find-buffer-visiting filename))
579 (work-buffer (or visitingp (find-file-noselect filename))))
580 (prog1 (with-current-buffer work-buffer
581 (let ((output-file
582 (org-export-output-file-name extension nil pub-dir))
583 (body-p (plist-get plist :body-only)))
584 (org-export-to-file backend output-file
585 nil nil nil body-p
586 ;; Add `org-publish-collect-numbering' and
587 ;; `org-publish-collect-index' to final output
588 ;; filters. The latter isn't dependent on
589 ;; `:makeindex', since we want to keep it up-to-date
590 ;; in cache anyway.
591 (org-combine-plists
592 plist
593 `(:filter-final-output
594 ,(cons 'org-publish-collect-numbering
595 (cons 'org-publish-collect-index
596 (plist-get plist :filter-final-output))))))))
597 ;; Remove opened buffer in the process.
598 (unless visitingp (kill-buffer work-buffer)))))
600 (defun org-publish-attachment (plist filename pub-dir)
601 "Publish a file with no transformation of any kind.
603 FILENAME is the filename of the Org file to be published. PLIST
604 is the property list for the given project. PUB-DIR is the
605 publishing directory.
607 Return output file name."
608 (unless (file-directory-p pub-dir)
609 (make-directory pub-dir t))
610 (let ((output (expand-file-name (file-name-nondirectory filename) pub-dir)))
611 (or (equal (expand-file-name (file-name-directory filename))
612 (file-name-as-directory (expand-file-name pub-dir)))
613 (copy-file filename output t))
614 ;; Return file name.
615 output))
619 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
620 ;;; Publishing files, sets of files, and indices
622 (defun org-publish-file (filename &optional project no-cache)
623 "Publish file FILENAME from PROJECT.
624 If NO-CACHE is not nil, do not initialize org-publish-cache and
625 write it to disk. This is needed, since this function is used to
626 publish single files, when entire projects are published.
627 See `org-publish-projects'."
628 (let* ((project
629 (or project
630 (or (org-publish-get-project-from-filename filename)
631 (error "File %s not part of any known project"
632 (abbreviate-file-name filename)))))
633 (project-plist (cdr project))
634 (ftname (expand-file-name filename))
635 (publishing-function
636 (let ((fun (plist-get project-plist :publishing-function)))
637 (cond ((null fun) (error "No publishing function chosen"))
638 ((listp fun) fun)
639 (t (list fun)))))
640 (base-dir
641 (file-name-as-directory
642 (expand-file-name
643 (or (plist-get project-plist :base-directory)
644 (error "Project %s does not have :base-directory defined"
645 (car project))))))
646 (pub-dir
647 (file-name-as-directory
648 (file-truename
649 (or (eval (plist-get project-plist :publishing-directory))
650 (error "Project %s does not have :publishing-directory defined"
651 (car project))))))
652 tmp-pub-dir)
654 (unless no-cache (org-publish-initialize-cache (car project)))
656 (setq tmp-pub-dir
657 (file-name-directory
658 (concat pub-dir
659 (and (string-match (regexp-quote base-dir) ftname)
660 (substring ftname (match-end 0))))))
661 ;; Allow chain of publishing functions.
662 (dolist (f publishing-function)
663 (when (org-publish-needed-p filename pub-dir f tmp-pub-dir base-dir)
664 (let ((output (funcall f project-plist filename tmp-pub-dir)))
665 (org-publish-update-timestamp filename pub-dir f base-dir)
666 (run-hook-with-args 'org-publish-after-publishing-hook
667 filename
668 output))))
669 (unless no-cache (org-publish-write-cache-file))))
671 (defun org-publish-projects (projects)
672 "Publish all files belonging to the PROJECTS alist.
673 If `:auto-sitemap' is set, publish the sitemap too. If
674 `:makeindex' is set, also produce a file theindex.org."
675 (mapc
676 (lambda (project)
677 ;; Each project uses its own cache file:
678 (org-publish-initialize-cache (car project))
679 (let* ((project-plist (cdr project))
680 (exclude-regexp (plist-get project-plist :exclude))
681 (sitemap-p (plist-get project-plist :auto-sitemap))
682 (sitemap-filename (or (plist-get project-plist :sitemap-filename)
683 "sitemap.org"))
684 (sitemap-function (or (plist-get project-plist :sitemap-function)
685 'org-publish-org-sitemap))
686 (org-publish-sitemap-date-format
687 (or (plist-get project-plist :sitemap-date-format)
688 org-publish-sitemap-date-format))
689 (org-publish-sitemap-file-entry-format
690 (or (plist-get project-plist :sitemap-file-entry-format)
691 org-publish-sitemap-file-entry-format))
692 (preparation-function
693 (plist-get project-plist :preparation-function))
694 (completion-function (plist-get project-plist :completion-function))
695 (files (org-publish-get-base-files project exclude-regexp))
696 (theindex
697 (expand-file-name "theindex.org"
698 (plist-get project-plist :base-directory))))
699 (when preparation-function (run-hooks 'preparation-function))
700 (if sitemap-p (funcall sitemap-function project sitemap-filename))
701 ;; Publish all files from PROJECT excepted "theindex.org". Its
702 ;; publishing will be deferred until "theindex.inc" is
703 ;; populated.
704 (dolist (file files)
705 (unless (equal file theindex)
706 (org-publish-file file project t)))
707 ;; Populate "theindex.inc", if needed, and publish
708 ;; "theindex.org".
709 (when (plist-get project-plist :makeindex)
710 (org-publish-index-generate-theindex
711 project (plist-get project-plist :base-directory))
712 (org-publish-file theindex project t))
713 (when completion-function (run-hooks 'completion-function))
714 (org-publish-write-cache-file)))
715 (org-publish-expand-projects projects)))
717 (defun org-publish-org-sitemap (project &optional sitemap-filename)
718 "Create a sitemap of pages in set defined by PROJECT.
719 Optionally set the filename of the sitemap with SITEMAP-FILENAME.
720 Default for SITEMAP-FILENAME is 'sitemap.org'."
721 (let* ((project-plist (cdr project))
722 (dir (file-name-as-directory
723 (plist-get project-plist :base-directory)))
724 (localdir (file-name-directory dir))
725 (indent-str (make-string 2 ?\ ))
726 (exclude-regexp (plist-get project-plist :exclude))
727 (files (nreverse
728 (org-publish-get-base-files project exclude-regexp)))
729 (sitemap-filename (concat dir (or sitemap-filename "sitemap.org")))
730 (sitemap-title (or (plist-get project-plist :sitemap-title)
731 (concat "Sitemap for project " (car project))))
732 (sitemap-style (or (plist-get project-plist :sitemap-style)
733 'tree))
734 (sitemap-sans-extension
735 (plist-get project-plist :sitemap-sans-extension))
736 (visiting (find-buffer-visiting sitemap-filename))
737 (ifn (file-name-nondirectory sitemap-filename))
738 file sitemap-buffer)
739 (with-current-buffer
740 (let ((org-inhibit-startup t))
741 (setq sitemap-buffer
742 (or visiting (find-file sitemap-filename))))
743 (erase-buffer)
744 (insert (concat "#+TITLE: " sitemap-title "\n\n"))
745 (while (setq file (pop files))
746 (let ((fn (file-name-nondirectory file))
747 (link (file-relative-name file dir))
748 (oldlocal localdir))
749 (when sitemap-sans-extension
750 (setq link (file-name-sans-extension link)))
751 ;; sitemap shouldn't list itself
752 (unless (equal (file-truename sitemap-filename)
753 (file-truename file))
754 (if (eq sitemap-style 'list)
755 (message "Generating list-style sitemap for %s" sitemap-title)
756 (message "Generating tree-style sitemap for %s" sitemap-title)
757 (setq localdir (concat (file-name-as-directory dir)
758 (file-name-directory link)))
759 (unless (string= localdir oldlocal)
760 (if (string= localdir dir)
761 (setq indent-str (make-string 2 ?\ ))
762 (let ((subdirs
763 (split-string
764 (directory-file-name
765 (file-name-directory
766 (file-relative-name localdir dir))) "/"))
767 (subdir "")
768 (old-subdirs (split-string
769 (file-relative-name oldlocal dir) "/")))
770 (setq indent-str (make-string 2 ?\ ))
771 (while (string= (car old-subdirs) (car subdirs))
772 (setq indent-str (concat indent-str (make-string 2 ?\ )))
773 (pop old-subdirs)
774 (pop subdirs))
775 (dolist (d subdirs)
776 (setq subdir (concat subdir d "/"))
777 (insert (concat indent-str " + " d "\n"))
778 (setq indent-str (make-string
779 (+ (length indent-str) 2) ?\ )))))))
780 ;; This is common to 'flat and 'tree
781 (let ((entry
782 (org-publish-format-file-entry
783 org-publish-sitemap-file-entry-format file project-plist))
784 (regexp "\\(.*\\)\\[\\([^][]+\\)\\]\\(.*\\)"))
785 (cond ((string-match-p regexp entry)
786 (string-match regexp entry)
787 (insert (concat indent-str " + " (match-string 1 entry)
788 "[[file:" link "]["
789 (match-string 2 entry)
790 "]]" (match-string 3 entry) "\n")))
792 (insert (concat indent-str " + [[file:" link "]["
793 entry
794 "]]\n"))))))))
795 (save-buffer))
796 (or visiting (kill-buffer sitemap-buffer))))
798 (defun org-publish-format-file-entry (fmt file project-plist)
799 (format-spec
801 `((?t . ,(org-publish-find-title file t))
802 (?d . ,(format-time-string org-publish-sitemap-date-format
803 (org-publish-find-date file)))
804 (?a . ,(or (plist-get project-plist :author) user-full-name)))))
806 (defun org-publish-find-title (file &optional reset)
807 "Find the title of FILE in project."
809 (and (not reset) (org-publish-cache-get-file-property file :title nil t))
810 (let* ((org-inhibit-startup t)
811 (visiting (find-buffer-visiting file))
812 (buffer (or visiting (find-file-noselect file))))
813 (with-current-buffer buffer
814 (let ((title
815 (let ((property
816 (plist-get
817 ;; protect local variables in open buffers
818 (if visiting
819 (org-export-with-buffer-copy (org-export-get-environment))
820 (org-export-get-environment))
821 :title)))
822 (if property
823 (org-no-properties (org-element-interpret-data property))
824 (file-name-nondirectory (file-name-sans-extension file))))))
825 (unless visiting (kill-buffer buffer))
826 (org-publish-cache-set-file-property file :title title)
827 title)))))
829 (defun org-publish-find-date (file)
830 "Find the date of FILE in project.
831 This function assumes FILE is either a directory or an Org file.
832 If FILE is an Org file and provides a DATE keyword use it. In
833 any other case use the file system's modification time. Return
834 time in `current-time' format."
835 (if (file-directory-p file) (nth 5 (file-attributes file))
836 (let* ((org-inhibit-startup t)
837 (visiting (find-buffer-visiting file))
838 (file-buf (or visiting (find-file-noselect file nil)))
839 (date (plist-get
840 (with-current-buffer file-buf
841 (if visiting
842 (org-export-with-buffer-copy (org-export-get-environment))
843 (org-export-get-environment)))
844 :date)))
845 (unless visiting (kill-buffer file-buf))
846 ;; DATE is either a timestamp object or a secondary string. If it
847 ;; is a timestamp or if the secondary string contains a timestamp,
848 ;; convert it to internal format. Otherwise, use FILE
849 ;; modification time.
850 (cond ((eq (org-element-type date) 'timestamp)
851 (org-time-string-to-time (org-element-interpret-data date)))
852 ((let ((ts (and (consp date) (assq 'timestamp date))))
853 (and ts
854 (let ((value (org-element-interpret-data ts)))
855 (and (org-string-nw-p value)
856 (org-time-string-to-time value))))))
857 ((file-exists-p file) (nth 5 (file-attributes file)))
858 (t (error "No such file: \"%s\"" file))))))
862 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
863 ;;; Interactive publishing functions
865 ;;;###autoload
866 (defalias 'org-publish-project 'org-publish)
868 ;;;###autoload
869 (defun org-publish (project &optional force async)
870 "Publish PROJECT.
872 PROJECT is either a project name, as a string, or a project
873 alist (see `org-publish-project-alist' variable).
875 When optional argument FORCE is non-nil, force publishing all
876 files in PROJECT. With a non-nil optional argument ASYNC,
877 publishing will be done asynchronously, in another process."
878 (interactive
879 (list (assoc (org-icompleting-read "Publish project: "
880 org-publish-project-alist nil t)
881 org-publish-project-alist)
882 current-prefix-arg))
883 (let ((project (if (not (stringp project)) project
884 ;; If this function is called in batch mode,
885 ;; PROJECT is still a string here.
886 (assoc project org-publish-project-alist))))
887 (cond
888 ((not project))
889 (async
890 (org-export-async-start (lambda (results) nil)
891 `(let ((org-publish-use-timestamps-flag
892 ,(and (not force) org-publish-use-timestamps-flag)))
893 ;; Expand components right now as external process may not
894 ;; be aware of complete `org-publish-project-alist'.
895 (org-publish-projects
896 ',(org-publish-expand-projects (list project))))))
897 (t (save-window-excursion
898 (let ((org-publish-use-timestamps-flag
899 (and (not force) org-publish-use-timestamps-flag)))
900 (org-publish-projects (list project))))))))
902 ;;;###autoload
903 (defun org-publish-all (&optional force async)
904 "Publish all projects.
905 With prefix argument FORCE, remove all files in the timestamp
906 directory and force publishing all projects. With a non-nil
907 optional argument ASYNC, publishing will be done asynchronously,
908 in another process."
909 (interactive "P")
910 (if async
911 (org-export-async-start (lambda (results) nil)
912 `(progn
913 (when ',force (org-publish-remove-all-timestamps))
914 (let ((org-publish-use-timestamps-flag
915 (if ',force nil ,org-publish-use-timestamps-flag)))
916 (org-publish-projects ',org-publish-project-alist))))
917 (when force (org-publish-remove-all-timestamps))
918 (save-window-excursion
919 (let ((org-publish-use-timestamps-flag
920 (if force nil org-publish-use-timestamps-flag)))
921 (org-publish-projects org-publish-project-alist)))))
924 ;;;###autoload
925 (defun org-publish-current-file (&optional force async)
926 "Publish the current file.
927 With prefix argument FORCE, force publish the file. When
928 optional argument ASYNC is non-nil, publishing will be done
929 asynchronously, in another process."
930 (interactive "P")
931 (let ((file (buffer-file-name (buffer-base-buffer))))
932 (if async
933 (org-export-async-start (lambda (results) nil)
934 `(let ((org-publish-use-timestamps-flag
935 (if ',force nil ,org-publish-use-timestamps-flag)))
936 (org-publish-file ,file)))
937 (save-window-excursion
938 (let ((org-publish-use-timestamps-flag
939 (if force nil org-publish-use-timestamps-flag)))
940 (org-publish-file file))))))
942 ;;;###autoload
943 (defun org-publish-current-project (&optional force async)
944 "Publish the project associated with the current file.
945 With a prefix argument, force publishing of all files in
946 the project."
947 (interactive "P")
948 (save-window-excursion
949 (let ((project (org-publish-get-project-from-filename
950 (buffer-file-name (buffer-base-buffer)) 'up)))
951 (if project (org-publish project force async)
952 (error "File %s is not part of any known project"
953 (buffer-file-name (buffer-base-buffer)))))))
957 ;;; Index generation
959 (defun org-publish-collect-index (output backend info)
960 "Update index for a file in cache.
962 OUTPUT is the output from transcoding current file. BACKEND is
963 the back-end that was used for transcoding. INFO is a plist
964 containing publishing and export options.
966 The index relative to current file is stored as an alist. An
967 association has the following shape: (TERM FILE-NAME PARENT),
968 where TERM is the indexed term, as a string, FILE-NAME is the
969 original full path of the file where the term in encountered, and
970 PARENT is a reference to the headline, if any, containing the
971 original index keyword. When non-nil, this reference is a cons
972 cell. Its CAR is a symbol among `id', `custom-id' and `name' and
973 its CDR is a string."
974 (let ((file (plist-get info :input-file)))
975 (org-publish-cache-set-file-property
976 file :index
977 (delete-dups
978 (org-element-map (plist-get info :parse-tree) 'keyword
979 (lambda (k)
980 (when (equal (org-element-property :key k) "INDEX")
981 (let ((parent (org-export-get-parent-headline k)))
982 (list (org-element-property :value k)
983 file
984 (cond
985 ((not parent) nil)
986 ((let ((id (org-element-property :ID parent)))
987 (and id (cons 'id id))))
988 ((let ((id (org-element-property :CUSTOM_ID parent)))
989 (and id (cons 'custom-id id))))
990 (t (cons 'name
991 ;; Remove statistics cookie.
992 (replace-regexp-in-string
993 "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
994 (org-element-property :raw-value parent)))))))))
995 info))))
996 ;; Return output unchanged.
997 output)
999 (defun org-publish-index-generate-theindex (project directory)
1000 "Retrieve full index from cache and build \"theindex.org\".
1001 PROJECT is the project the index relates to. DIRECTORY is the
1002 publishing directory."
1003 (let ((all-files (org-publish-get-base-files
1004 project (plist-get (cdr project) :exclude)))
1005 full-index)
1006 ;; Compile full index and sort it alphabetically.
1007 (dolist (file all-files
1008 (setq full-index
1009 (sort (nreverse full-index)
1010 (lambda (a b) (string< (downcase (car a))
1011 (downcase (car b)))))))
1012 (let ((index (org-publish-cache-get-file-property file :index)))
1013 (dolist (term index)
1014 (unless (member term full-index) (push term full-index)))))
1015 ;; Write "theindex.inc" in DIRECTORY.
1016 (with-temp-file (expand-file-name "theindex.inc" directory)
1017 (let ((current-letter nil) (last-entry nil))
1018 (dolist (idx full-index)
1019 (let* ((entry (org-split-string (car idx) "!"))
1020 (letter (upcase (substring (car entry) 0 1)))
1021 ;; Transform file into a path relative to publishing
1022 ;; directory.
1023 (file (file-relative-name
1024 (nth 1 idx)
1025 (plist-get (cdr project) :base-directory))))
1026 ;; Check if another letter has to be inserted.
1027 (unless (string= letter current-letter)
1028 (insert (format "* %s\n" letter)))
1029 ;; Compute the first difference between last entry and
1030 ;; current one: it tells the level at which new items
1031 ;; should be added.
1032 (let* ((rank (if (equal entry last-entry) (1- (length entry))
1033 (loop for n from 0 to (length entry)
1034 unless (equal (nth n entry) (nth n last-entry))
1035 return n)))
1036 (len (length (nthcdr rank entry))))
1037 ;; For each term after the first difference, create
1038 ;; a new sub-list with the term as body. Moreover,
1039 ;; linkify the last term.
1040 (dotimes (n len)
1041 (insert
1042 (concat
1043 (make-string (* (+ rank n) 2) ? ) " - "
1044 (if (not (= (1- len) n)) (nth (+ rank n) entry)
1045 ;; Last term: Link it to TARGET, if possible.
1046 (let ((target (nth 2 idx)))
1047 (format
1048 "[[%s][%s]]"
1049 ;; Destination.
1050 (case (car target)
1051 ('nil (format "file:%s" file))
1052 (id (format "id:%s" (cdr target)))
1053 (custom-id (format "file:%s::#%s" file (cdr target)))
1054 (otherwise (format "file:%s::*%s" file (cdr target))))
1055 ;; Description.
1056 (car (last entry)))))
1057 "\n"))))
1058 (setq current-letter letter last-entry entry))))
1059 ;; Create "theindex.org", if it doesn't exist yet, and provide
1060 ;; a default index file.
1061 (let ((index.org (expand-file-name "theindex.org" directory)))
1062 (unless (file-exists-p index.org)
1063 (with-temp-file index.org
1064 (insert "#+TITLE: Index\n\n#+INCLUDE: \"theindex.inc\"\n\n")))))))
1068 ;;; External Fuzzy Links Resolution
1070 ;; This part implements tools to resolve [[file.org::*Some headline]]
1071 ;; links, where "file.org" belongs to the current project.
1073 (defun org-publish-collect-numbering (output backend info)
1074 (org-publish-cache-set-file-property
1075 (plist-get info :input-file) :numbering
1076 (mapcar (lambda (entry)
1077 (cons (org-split-string
1078 (replace-regexp-in-string
1079 "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
1080 (org-element-property :raw-value (car entry))))
1081 (cdr entry)))
1082 (plist-get info :headline-numbering)))
1083 ;; Return output unchanged.
1084 output)
1086 (defun org-publish-resolve-external-fuzzy-link (file fuzzy)
1087 "Return numbering for headline matching FUZZY search in FILE.
1089 Return value is a list of numbers, or nil. This function allows
1090 to resolve external fuzzy links like:
1092 [[file.org::*fuzzy][description]]"
1093 (when org-publish-cache
1094 (cdr (assoc (org-split-string
1095 (if (eq (aref fuzzy 0) ?*) (substring fuzzy 1) fuzzy))
1096 (org-publish-cache-get-file-property
1097 (expand-file-name file) :numbering nil t)))))
1101 ;;; Caching functions
1103 (defun org-publish-write-cache-file (&optional free-cache)
1104 "Write `org-publish-cache' to file.
1105 If FREE-CACHE, empty the cache."
1106 (unless org-publish-cache
1107 (error "`org-publish-write-cache-file' called, but no cache present"))
1109 (let ((cache-file (org-publish-cache-get ":cache-file:")))
1110 (unless cache-file
1111 (error "Cannot find cache-file name in `org-publish-write-cache-file'"))
1112 (with-temp-file cache-file
1113 (let (print-level print-length)
1114 (insert "(setq org-publish-cache (make-hash-table :test 'equal :weakness nil :size 100))\n")
1115 (maphash (lambda (k v)
1116 (insert
1117 (format (concat "(puthash %S "
1118 (if (or (listp v) (symbolp v))
1119 "'" "")
1120 "%S org-publish-cache)\n") k v)))
1121 org-publish-cache)))
1122 (when free-cache (org-publish-reset-cache))))
1124 (defun org-publish-initialize-cache (project-name)
1125 "Initialize the projects cache if not initialized yet and return it."
1127 (unless project-name
1128 (error "Cannot initialize `org-publish-cache' without projects name in `org-publish-initialize-cache'"))
1130 (unless (file-exists-p org-publish-timestamp-directory)
1131 (make-directory org-publish-timestamp-directory t))
1132 (unless (file-directory-p org-publish-timestamp-directory)
1133 (error "Org publish timestamp: %s is not a directory"
1134 org-publish-timestamp-directory))
1136 (unless (and org-publish-cache
1137 (string= (org-publish-cache-get ":project:") project-name))
1138 (let* ((cache-file
1139 (concat
1140 (expand-file-name org-publish-timestamp-directory)
1141 project-name ".cache"))
1142 (cexists (file-exists-p cache-file)))
1144 (when org-publish-cache (org-publish-reset-cache))
1146 (if cexists (load-file cache-file)
1147 (setq org-publish-cache
1148 (make-hash-table :test 'equal :weakness nil :size 100))
1149 (org-publish-cache-set ":project:" project-name)
1150 (org-publish-cache-set ":cache-file:" cache-file))
1151 (unless cexists (org-publish-write-cache-file nil))))
1152 org-publish-cache)
1154 (defun org-publish-reset-cache ()
1155 "Empty org-publish-cache and reset it nil."
1156 (message "%s" "Resetting org-publish-cache")
1157 (when (hash-table-p org-publish-cache)
1158 (clrhash org-publish-cache))
1159 (setq org-publish-cache nil))
1161 (defun org-publish-cache-file-needs-publishing
1162 (filename &optional pub-dir pub-func base-dir)
1163 "Check the timestamp of the last publishing of FILENAME.
1164 Return non-nil if the file needs publishing. Also check if
1165 any included files have been more recently published, so that
1166 the file including them will be republished as well."
1167 (unless org-publish-cache
1168 (error
1169 "`org-publish-cache-file-needs-publishing' called, but no cache present"))
1170 (let* ((case-fold-search t)
1171 (key (org-publish-timestamp-filename filename pub-dir pub-func))
1172 (pstamp (org-publish-cache-get key))
1173 (org-inhibit-startup t)
1174 (visiting (find-buffer-visiting filename))
1175 included-files-ctime buf)
1176 (when (equal (file-name-extension filename) "org")
1177 (setq buf (find-file (expand-file-name filename)))
1178 (with-current-buffer buf
1179 (goto-char (point-min))
1180 (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t)
1181 (let* ((element (org-element-at-point))
1182 (included-file
1183 (and (eq (org-element-type element) 'keyword)
1184 (let ((value (org-element-property :value element)))
1185 (and value
1186 (string-match "^\\(\".+?\"\\|\\S-+\\)" value)
1187 (org-remove-double-quotes
1188 (match-string 1 value)))))))
1189 (when included-file
1190 (add-to-list 'included-files-ctime
1191 (org-publish-cache-ctime-of-src
1192 (expand-file-name included-file))
1193 t)))))
1194 (unless visiting (kill-buffer buf)))
1195 (if (null pstamp) t
1196 (let ((ctime (org-publish-cache-ctime-of-src filename)))
1197 (or (< pstamp ctime)
1198 (when included-files-ctime
1199 (not (null (delq nil (mapcar (lambda (ct) (< ctime ct))
1200 included-files-ctime))))))))))
1202 (defun org-publish-cache-set-file-property
1203 (filename property value &optional project-name)
1204 "Set the VALUE for a PROPERTY of file FILENAME in publishing cache to VALUE.
1205 Use cache file of PROJECT-NAME. If the entry does not exist, it
1206 will be created. Return VALUE."
1207 ;; Evtl. load the requested cache file:
1208 (if project-name (org-publish-initialize-cache project-name))
1209 (let ((pl (org-publish-cache-get filename)))
1210 (if pl (progn (plist-put pl property value) value)
1211 (org-publish-cache-get-file-property
1212 filename property value nil project-name))))
1214 (defun org-publish-cache-get-file-property
1215 (filename property &optional default no-create project-name)
1216 "Return the value for a PROPERTY of file FILENAME in publishing cache.
1217 Use cache file of PROJECT-NAME. Return the value of that PROPERTY
1218 or DEFAULT, if the value does not yet exist. If the entry will
1219 be created, unless NO-CREATE is not nil."
1220 ;; Evtl. load the requested cache file:
1221 (if project-name (org-publish-initialize-cache project-name))
1222 (let ((pl (org-publish-cache-get filename)) retval)
1223 (if pl
1224 (if (plist-member pl property)
1225 (setq retval (plist-get pl property))
1226 (setq retval default))
1227 ;; no pl yet:
1228 (unless no-create
1229 (org-publish-cache-set filename (list property default)))
1230 (setq retval default))
1231 retval))
1233 (defun org-publish-cache-get (key)
1234 "Return the value stored in `org-publish-cache' for key KEY.
1235 Returns nil, if no value or nil is found, or the cache does not
1236 exist."
1237 (unless org-publish-cache
1238 (error "`org-publish-cache-get' called, but no cache present"))
1239 (gethash key org-publish-cache))
1241 (defun org-publish-cache-set (key value)
1242 "Store KEY VALUE pair in `org-publish-cache'.
1243 Returns value on success, else nil."
1244 (unless org-publish-cache
1245 (error "`org-publish-cache-set' called, but no cache present"))
1246 (puthash key value org-publish-cache))
1248 (defun org-publish-cache-ctime-of-src (file)
1249 "Get the ctime of FILE as an integer."
1250 (let ((attr (file-attributes
1251 (expand-file-name (or (file-symlink-p file) file)
1252 (file-name-directory file)))))
1253 (if (not attr) (error "No such file: \"%s\"" file)
1254 (+ (lsh (car (nth 5 attr)) 16)
1255 (cadr (nth 5 attr))))))
1258 (provide 'ox-publish)
1260 ;; Local variables:
1261 ;; generated-autoload-file: "org-loaddefs.el"
1262 ;; End:
1264 ;;; ox-publish.el ends here