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