ox-publish: Fix :base-extension (part 2)
[org-mode/org-tableheadings.git] / lisp / ox-publish.el
blobf4943c5e88df72f89c2625e790c6457543607362
1 ;;; ox-publish.el --- Publish Related Org Mode Files as a Website -*- lexical-binding: t; -*-
2 ;; Copyright (C) 2006-2016 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 (require 'cl-lib)
42 (require 'format-spec)
43 (require 'ox)
47 ;;; Variables
49 ;; Here, so you find the variable right before it's used the first time:
50 (defvar org-publish-cache nil
51 "This will cache timestamps and titles for files in publishing projects.
52 Blocks could hash sha1 values here.")
54 (defvar org-publish-after-publishing-hook nil
55 "Hook run each time a file is published.
56 Every function in this hook will be called with two arguments:
57 the name of the original file and the name of the file
58 produced.")
60 (defgroup org-publish nil
61 "Options for publishing a set of files."
62 :tag "Org Publishing"
63 :group 'org)
65 (defcustom org-publish-project-alist nil
66 "Association list to control publishing behavior.
67 \\<org-mode-map>
68 Each element of the alist is a publishing project. The car of
69 each element is a string, uniquely identifying the project. The
70 cdr of each element is in one of the following forms:
72 1. A well-formed property list with an even number of elements,
73 alternating keys and values, specifying parameters for the
74 publishing process.
76 (:property value :property value ... )
78 2. A meta-project definition, specifying of a list of
79 sub-projects:
81 (:components (\"project-1\" \"project-2\" ...))
83 When the CDR of an element of org-publish-project-alist is in
84 this second form, the elements of the list after `:components'
85 are taken to be components of the project, which group together
86 files requiring different publishing options. When you publish
87 such a project with `\\[org-publish]', the components all publish.
89 When a property is given a value in `org-publish-project-alist',
90 its setting overrides the value of the corresponding user
91 variable (if any) during publishing. However, options set within
92 a file override everything.
94 Most properties are optional, but some should always be set:
96 `:base-directory'
98 Directory containing publishing source files.
100 `:base-extension'
102 Extension (without the dot!) of source files. This can be
103 a regular expression. If not given, \"org\" will be used as
104 default extension. If it is `any', include all the files,
105 even without extension.
107 `:publishing-directory'
109 Directory (possibly remote) where output files will be
110 published.
112 If `:recursive' is non-nil files in sub-directories of
113 `:base-directory' are considered.
115 The `:exclude' property may be used to prevent certain files from
116 being published. Its value may be a string or regexp matching
117 file names you don't want to be published.
119 The `:include' property may be used to include extra files. Its
120 value may be a list of filenames to include. The filenames are
121 considered relative to the base directory.
123 When both `:include' and `:exclude' properties are given values,
124 the exclusion step happens first.
126 One special property controls which back-end function to use for
127 publishing files in the project. This can be used to extend the
128 set of file types publishable by `org-publish', as well as the
129 set of output formats.
131 `:publishing-function'
133 Function to publish file. Each back-end may define its
134 own (i.e. `org-latex-publish-to-pdf',
135 `org-html-publish-to-html'). May be a list of functions, in
136 which case each function in the list is invoked in turn.
138 Another property allows you to insert code that prepares
139 a project for publishing. For example, you could call GNU Make
140 on a certain makefile, to ensure published files are built up to
141 date.
143 `:preparation-function'
145 Function to be called before publishing this project. This
146 may also be a list of functions. Preparation functions are
147 called with the project properties list as their sole
148 argument.
150 `:completion-function'
152 Function to be called after publishing this project. This
153 may also be a list of functions. Completion functions are
154 called with the project properties list as their sole
155 argument.
157 Some properties control details of the Org publishing process,
158 and are equivalent to the corresponding user variables listed in
159 the right column. Back-end specific properties may also be
160 included. See the back-end documentation for more information.
162 :author `user-full-name'
163 :creator `org-export-creator-string'
164 :email `user-mail-address'
165 :exclude-tags `org-export-exclude-tags'
166 :headline-levels `org-export-headline-levels'
167 :language `org-export-default-language'
168 :preserve-breaks `org-export-preserve-breaks'
169 :section-numbers `org-export-with-section-numbers'
170 :select-tags `org-export-select-tags'
171 :time-stamp-file `org-export-time-stamp-file'
172 :with-archived-trees `org-export-with-archived-trees'
173 :with-author `org-export-with-author'
174 :with-creator `org-export-with-creator'
175 :with-date `org-export-with-date'
176 :with-drawers `org-export-with-drawers'
177 :with-email `org-export-with-email'
178 :with-emphasize `org-export-with-emphasize'
179 :with-entities `org-export-with-entities'
180 :with-fixed-width `org-export-with-fixed-width'
181 :with-footnotes `org-export-with-footnotes'
182 :with-inlinetasks `org-export-with-inlinetasks'
183 :with-latex `org-export-with-latex'
184 :with-planning `org-export-with-planning'
185 :with-priority `org-export-with-priority'
186 :with-properties `org-export-with-properties'
187 :with-smart-quotes `org-export-with-smart-quotes'
188 :with-special-strings `org-export-with-special-strings'
189 :with-statistics-cookies' `org-export-with-statistics-cookies'
190 :with-sub-superscript `org-export-with-sub-superscripts'
191 :with-toc `org-export-with-toc'
192 :with-tables `org-export-with-tables'
193 :with-tags `org-export-with-tags'
194 :with-tasks `org-export-with-tasks'
195 :with-timestamps `org-export-with-timestamps'
196 :with-title `org-export-with-title'
197 :with-todo-keywords `org-export-with-todo-keywords'
199 The following properties may be used to control publishing of
200 a site-map of files or summary page for a given project.
202 `:auto-sitemap'
204 Whether to publish a site-map during
205 `org-publish-current-project' or `org-publish-all'.
207 `:sitemap-filename'
209 Filename for output of site-map. Defaults to \"sitemap.org\".
211 `:sitemap-title'
213 Title of site-map page. Defaults to name of file.
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-format-entry'
224 Plugin function used to format entries in the site-map. It
225 is called with three arguments: the file or directory name
226 relative to base directory, the site map style and the
227 current project. It has to return a string.
229 Defaults to `org-publish-sitemap-default-entry', which turns
230 file names into links and use document titles as
231 descriptions. For specific formatting needs, one can use
232 `org-publish-find-date', `org-publish-find-title' and
233 `org-publish-find-property', to retrieve additional
234 information about published documents.
236 `:sitemap-function'
238 Plugin function to use for generation of site-map. It is
239 called with two arguments: the title of the site-map, as
240 a string, and a representation of the files involved in the
241 project, as returned by `org-list-to-lisp'. The latter can
242 further be transformed using `org-list-to-generic',
243 `org-list-to-subtree' and alike. It has to return a string.
245 Defaults to `org-publish-sitemap-default', which generates
246 a plain list of links to all files in the project.
248 If you create a site-map file, adjust the sorting like this:
250 `:sitemap-sort-folders'
252 Where folders should appear in the site-map. Set this to
253 `first' or `last' to display folders first or last,
254 respectively. When set to `ignore' (default), folders are
255 ignored altogether. Any other value will mix files and
256 folders. This variable has no effect when site-map style is
257 `tree'.
259 `:sitemap-sort-files'
261 The site map is normally sorted alphabetically. You can
262 change this behavior setting this to `anti-chronologically',
263 `chronologically', or nil.
265 `:sitemap-ignore-case'
267 Should sorting be case-sensitive? Default nil.
269 The following property control the creation of a concept index.
271 `:makeindex'
273 Create a concept index. The file containing the index has to
274 be called \"theindex.org\". If it doesn't exist in the
275 project, it will be generated. Contents of the index are
276 stored in the file \"theindex.inc\", which can be included in
277 \"theindex.org\".
279 Other properties affecting publication.
281 `:body-only'
283 Set this to t to publish only the body of the documents."
284 :group 'org-export-publish
285 :type 'alist)
287 (defcustom org-publish-use-timestamps-flag t
288 "Non-nil means use timestamp checking to publish only changed files.
289 When nil, do no timestamp checking and always publish all files."
290 :group 'org-export-publish
291 :type 'boolean)
293 (defcustom org-publish-timestamp-directory
294 (convert-standard-filename "~/.org-timestamps/")
295 "Name of directory in which to store publishing timestamps."
296 :group 'org-export-publish
297 :type 'directory)
299 (defcustom org-publish-list-skipped-files t
300 "Non-nil means show message about files *not* published."
301 :group 'org-export-publish
302 :type 'boolean)
304 (defcustom org-publish-sitemap-sort-files 'alphabetically
305 "Method to sort files in site-maps.
306 Possible values are `alphabetically', `chronologically',
307 `anti-chronologically' and nil.
309 If `alphabetically', files will be sorted alphabetically. If
310 `chronologically', files will be sorted with older modification
311 time first. If `anti-chronologically', files will be sorted with
312 newer modification time first. nil won't sort files.
314 You can overwrite this default per project in your
315 `org-publish-project-alist', using `:sitemap-sort-files'."
316 :group 'org-export-publish
317 :type 'symbol)
319 (defcustom org-publish-sitemap-sort-folders 'ignore
320 "A symbol, denoting if folders are sorted first in site-maps.
322 Possible values are `first', `last', `ignore' and nil.
323 If `first', folders will be sorted before files.
324 If `last', folders are sorted to the end after the files.
325 If `ignore', folders do not appear in the site-map.
326 Any other value will mix files and folders.
328 You can overwrite this default per project in your
329 `org-publish-project-alist', using `:sitemap-sort-folders'.
331 This variable is ignored when site-map style is `tree'."
332 :group 'org-export-publish
333 :type '(choice
334 (const :tag "Folders before files" first)
335 (const :tag "Folders after files" last)
336 (const :tag "No folder in site-map" ignore)
337 (const :tag "Mix folders and files" nil))
338 :version "25.2"
339 :package-version '(Org . "9.1")
340 :safe #'symbolp)
342 (defcustom org-publish-sitemap-sort-ignore-case nil
343 "Non-nil when site-map sorting should ignore case.
345 You can overwrite this default per project in your
346 `org-publish-project-alist', using `:sitemap-ignore-case'."
347 :group 'org-export-publish
348 :type 'boolean)
352 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
353 ;;; Timestamp-related functions
355 (defun org-publish-timestamp-filename (filename &optional pub-dir pub-func)
356 "Return path to timestamp file for filename FILENAME."
357 (setq filename (concat filename "::" (or pub-dir "") "::"
358 (format "%s" (or pub-func ""))))
359 (concat "X" (if (fboundp 'sha1) (sha1 filename) (md5 filename))))
361 (defun org-publish-needed-p
362 (filename &optional pub-dir pub-func _true-pub-dir base-dir)
363 "Non-nil if FILENAME should be published in PUB-DIR using PUB-FUNC.
364 TRUE-PUB-DIR is where the file will truly end up. Currently we
365 are not using this - maybe it can eventually be used to check if
366 the file is present at the target location, and how old it is.
367 Right now we cannot do this, because we do not know under what
368 file name the file will be stored - the publishing function can
369 still decide about that independently."
370 (let ((rtn (if (not org-publish-use-timestamps-flag) t
371 (org-publish-cache-file-needs-publishing
372 filename pub-dir pub-func base-dir))))
373 (if rtn (message "Publishing file %s using `%s'" filename pub-func)
374 (when org-publish-list-skipped-files
375 (message "Skipping unmodified file %s" filename)))
376 rtn))
378 (defun org-publish-update-timestamp
379 (filename &optional pub-dir pub-func _base-dir)
380 "Update publishing timestamp for file FILENAME.
381 If there is no timestamp, create one."
382 (let ((key (org-publish-timestamp-filename filename pub-dir pub-func))
383 (stamp (org-publish-cache-ctime-of-src filename)))
384 (org-publish-cache-set key stamp)))
386 (defun org-publish-remove-all-timestamps ()
387 "Remove all files in the timestamp directory."
388 (let ((dir org-publish-timestamp-directory))
389 (when (and (file-exists-p dir) (file-directory-p dir))
390 (mapc #'delete-file (directory-files dir 'full "[^.]\\'"))
391 (org-publish-reset-cache))))
395 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
396 ;;; Getting project information out of `org-publish-project-alist'
398 (defun org-publish-property (property project &optional default)
399 "Return value PROPERTY, as à symbol, in PROJECT.
400 DEFAULT is returned when PROPERTY is not actually set in PROJECT
401 definition."
402 (let ((properties (cdr project)))
403 (if (plist-member properties property)
404 (plist-get properties property)
405 default)))
407 (defun org-publish--expand-file-name (file project)
408 "Return full file name for FILE in PROJECT.
409 When FILE is a relative file name, it is expanded according to
410 project base directory."
411 (if (file-name-absolute-p file) file
412 (expand-file-name file (org-publish-property :base-directory project))))
414 (defun org-publish-expand-projects (projects-alist)
415 "Expand projects in PROJECTS-ALIST.
416 This splices all the components into the list."
417 (let ((rest projects-alist) rtn p components)
418 (while (setq p (pop rest))
419 (if (setq components (plist-get (cdr p) :components))
420 (setq rest (append
421 (mapcar (lambda (x) (assoc x org-publish-project-alist))
422 components)
423 rest))
424 (push p rtn)))
425 (nreverse (delete-dups (delq nil rtn)))))
427 (defun org-publish-get-base-files (project)
428 "Return a list of all files in PROJECT."
429 (let* ((base-dir (file-name-as-directory
430 (org-publish-property :base-directory project)))
431 (extension (or (org-publish-property :base-extension project) "org"))
432 (match (and (not (eq extension 'any))
433 (concat "^[^\\.].*\\.\\(" extension "\\)$")))
434 (base-files
435 (cl-remove-if #'file-directory-p
436 (if (org-publish-property :recursive project)
437 (directory-files-recursively base-dir match)
438 (directory-files base-dir t match t)))))
439 (org-uniquify
440 (append
441 ;; Files from BASE-DIR. Apply exclusion filter before adding
442 ;; included files.
443 (let ((exclude-regexp (org-publish-property :exclude project)))
444 (if exclude-regexp
445 (cl-remove-if
446 (lambda (f)
447 ;; Match against relative names, yet BASE-DIR file
448 ;; names are absolute.
449 (string-match exclude-regexp
450 (file-relative-name f base-dir)))
451 base-files)
452 base-files))
453 ;; Sitemap file.
454 (and (org-publish-property :auto-sitemap project)
455 (list (expand-file-name
456 (or (org-publish-property :sitemap-filename project)
457 "sitemap.org")
458 base-dir)))
459 ;; Included files.
460 (mapcar (lambda (f) (expand-file-name f base-dir))
461 (org-publish-property :include project))))))
463 (defun org-publish-get-project-from-filename (filename &optional up)
464 "Return the project that FILENAME belongs to."
465 (let* ((filename (expand-file-name filename))
466 project-name)
468 (catch 'p-found
469 (dolist (prj org-publish-project-alist)
470 (unless (plist-get (cdr prj) :components)
471 ;; [[info:org:Selecting%20files]] shows how this is supposed to work:
472 (let* ((r (plist-get (cdr prj) :recursive))
473 (b (expand-file-name (file-name-as-directory
474 (plist-get (cdr prj) :base-directory))))
475 (x (or (plist-get (cdr prj) :base-extension) "org"))
476 (e (plist-get (cdr prj) :exclude))
477 (i (plist-get (cdr prj) :include))
478 (xm (concat "\\`" b
479 (if r ".+" "[^/]+")
480 (and (not (eq x 'any))
481 (format "\\.\\(%s\\)\\'" x)))))
482 (when
483 (or (and i
484 (member filename
485 (dolist (file i) (expand-file-name file b))))
486 (and (not (and e (string-match e filename)))
487 (string-match xm filename)))
488 (setq project-name (car prj))
489 (throw 'p-found project-name))))))
490 (when up
491 (dolist (prj org-publish-project-alist)
492 (if (member project-name (plist-get (cdr prj) :components))
493 (setq project-name (car prj)))))
494 (assoc project-name org-publish-project-alist)))
498 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
499 ;;; Tools for publishing functions in back-ends
501 (defun org-publish-org-to (backend filename extension plist &optional pub-dir)
502 "Publish an Org file to a specified back-end.
504 BACKEND is a symbol representing the back-end used for
505 transcoding. FILENAME is the filename of the Org file to be
506 published. EXTENSION is the extension used for the output
507 string, with the leading dot. PLIST is the property list for the
508 given project.
510 Optional argument PUB-DIR, when non-nil is the publishing
511 directory.
513 Return output file name."
514 (unless (or (not pub-dir) (file-exists-p pub-dir)) (make-directory pub-dir t))
515 ;; Check if a buffer visiting FILENAME is already open.
516 (let* ((org-inhibit-startup t)
517 (visiting (find-buffer-visiting filename))
518 (work-buffer (or visiting (find-file-noselect filename))))
519 (unwind-protect
520 (with-current-buffer work-buffer
521 (let ((output (org-export-output-file-name extension nil pub-dir)))
522 (org-export-to-file backend output
523 nil nil nil (plist-get plist :body-only)
524 ;; Add `org-publish--store-crossrefs' and
525 ;; `org-publish-collect-index' to final output filters.
526 ;; The latter isn't dependent on `:makeindex', since we
527 ;; want to keep it up-to-date in cache anyway.
528 (org-combine-plists
529 plist
530 `(:crossrefs
531 ,(org-publish-cache-get-file-property
532 (expand-file-name filename) :crossrefs nil t)
533 :filter-final-output
534 (org-publish--store-crossrefs
535 org-publish-collect-index
536 ,@(plist-get plist :filter-final-output)))))))
537 ;; Remove opened buffer in the process.
538 (unless visiting (kill-buffer work-buffer)))))
540 (defun org-publish-attachment (_plist filename pub-dir)
541 "Publish a file with no transformation of any kind.
543 FILENAME is the filename of the Org file to be published. PLIST
544 is the property list for the given project. PUB-DIR is the
545 publishing directory.
547 Return output file name."
548 (unless (file-directory-p pub-dir)
549 (make-directory pub-dir t))
550 (let ((output (expand-file-name (file-name-nondirectory filename) pub-dir)))
551 (or (equal (expand-file-name (file-name-directory filename))
552 (file-name-as-directory (expand-file-name pub-dir)))
553 (copy-file filename output t))
554 ;; Return file name.
555 output))
559 ;;; Publishing files, sets of files
561 (defun org-publish-file (filename &optional project no-cache)
562 "Publish file FILENAME from PROJECT.
563 If NO-CACHE is not nil, do not initialize `org-publish-cache'.
564 This is needed, since this function is used to publish single
565 files, when entire projects are published (see
566 `org-publish-projects')."
567 (let* ((project
568 (or project
569 (or (org-publish-get-project-from-filename filename)
570 (error "File %s not part of any known project"
571 (abbreviate-file-name filename)))))
572 (plist (cdr project))
573 (ftname (expand-file-name filename))
574 (publishing-function
575 (let ((fun (org-publish-property :publishing-function project)))
576 (cond ((null fun) (error "No publishing function chosen"))
577 ((listp fun) fun)
578 (t (list fun)))))
579 (base-dir
580 (file-name-as-directory
581 (expand-file-name
582 (or (org-publish-property :base-directory project)
583 (error "Project %s does not have :base-directory defined"
584 (car project))))))
585 (pub-dir
586 (file-name-as-directory
587 (file-truename
588 (or (org-publish-property :publishing-directory project)
589 (error "Project %s does not have :publishing-directory defined"
590 (car project))))))
591 tmp-pub-dir)
593 (unless no-cache (org-publish-initialize-cache (car project)))
595 (setq tmp-pub-dir
596 (file-name-directory
597 (concat pub-dir
598 (and (string-match (regexp-quote base-dir) ftname)
599 (substring ftname (match-end 0))))))
600 ;; Allow chain of publishing functions.
601 (dolist (f publishing-function)
602 (when (org-publish-needed-p filename pub-dir f tmp-pub-dir base-dir)
603 (let ((output (funcall f plist filename tmp-pub-dir)))
604 (org-publish-update-timestamp filename pub-dir f base-dir)
605 (run-hook-with-args 'org-publish-after-publishing-hook
606 filename
607 output))))
608 ;; Make sure to write cache to file after successfully publishing
609 ;; a file, so as to minimize impact of a publishing failure.
610 (org-publish-write-cache-file)))
612 (defun org-publish-projects (projects)
613 "Publish all files belonging to the PROJECTS alist.
614 If `:auto-sitemap' is set, publish the sitemap too. If
615 `:makeindex' is set, also produce a file \"theindex.org\"."
616 (dolist (project (org-publish-expand-projects projects))
617 (let ((plist (cdr project)))
618 (let ((fun (org-publish-property :preparation-function project)))
619 (cond
620 ((consp fun) (dolist (f fun) (funcall f plist)))
621 ((functionp fun) (funcall fun plist))))
622 ;; Each project uses its own cache file.
623 (org-publish-initialize-cache (car project))
624 (when (org-publish-property :auto-sitemap project)
625 (let ((sitemap-filename
626 (or (org-publish-property :sitemap-filename project)
627 "sitemap.org")))
628 (org-publish-sitemap project sitemap-filename)))
629 ;; Publish all files from PROJECT except "theindex.org". Its
630 ;; publishing will be deferred until "theindex.inc" is
631 ;; populated.
632 (let ((theindex (expand-file-name
633 "theindex.org"
634 (org-publish-property :base-directory project))))
635 (dolist (file (org-publish-get-base-files project))
636 (unless (equal file theindex) (org-publish-file file project t)))
637 ;; Populate "theindex.inc", if needed, and publish
638 ;; "theindex.org".
639 (when (org-publish-property :makeindex project)
640 (org-publish-index-generate-theindex
641 project (org-publish-property :base-directory project))
642 (org-publish-file theindex project t)))
643 (let ((fun (org-publish-property :completion-function project)))
644 (cond
645 ((consp fun) (dolist (f fun) (funcall f plist)))
646 ((functionp fun) (funcall fun plist)))))
647 (org-publish-write-cache-file)))
650 ;;; Site map generation
652 (defun org-publish--sitemap-files-to-lisp (files project style format-entry)
653 "Represent FILES as a parsed plain list.
654 FILES is the list of files in the site map. PROJECT is the
655 current project. STYLE determines is either `list' or `tree'.
656 FORMAT-ENTRY is a function called on each file which should
657 return a string. Return value is a list as returned by
658 `org-list-to-lisp'."
659 (let ((root (expand-file-name
660 (file-name-as-directory
661 (org-publish-property :base-directory project)))))
662 (pcase style
663 (`list
664 (cons 'unordered
665 (mapcar
666 (lambda (f)
667 (list (funcall format-entry
668 (file-relative-name f root)
669 style
670 project)))
671 files)))
672 (`tree
673 (letrec ((files-only (cl-remove-if #'directory-name-p files))
674 (directories (cl-remove-if-not #'directory-name-p files))
675 (subtree-to-list
676 (lambda (dir)
677 (cons 'unordered
678 (nconc
679 ;; Files in DIR.
680 (mapcar
681 (lambda (f)
682 (list (funcall format-entry
683 (file-relative-name f root)
684 style
685 project)))
686 (cl-remove-if-not
687 (lambda (f) (string= dir (file-name-directory f)))
688 files-only))
689 ;; Direct sub-directories.
690 (mapcar
691 (lambda (sub)
692 (list (funcall format-entry
693 (file-relative-name sub root)
694 style
695 project)
696 (funcall subtree-to-list sub)))
697 (cl-remove-if-not
698 (lambda (f)
699 (string=
701 ;; Parent directory.
702 (file-name-directory (directory-file-name f))))
703 directories)))))))
704 (funcall subtree-to-list root)))
705 (_ (user-error "Unknown site-map style: `%s'" style)))))
707 (defun org-publish-sitemap (project &optional sitemap-filename)
708 "Create a sitemap of pages in set defined by PROJECT.
709 Optionally set the filename of the sitemap with SITEMAP-FILENAME.
710 Default for SITEMAP-FILENAME is `sitemap.org'."
711 (let* ((root (expand-file-name
712 (file-name-as-directory
713 (org-publish-property :base-directory project))))
714 (sitemap-filename (concat root (or sitemap-filename "sitemap.org")))
715 (title (or (org-publish-property :sitemap-title project)
716 (concat "Sitemap for project " (car project))))
717 (style (or (org-publish-property :sitemap-style project)
718 'tree))
719 (sitemap-builder (or (org-publish-property :sitemap-function project)
720 #'org-publish-sitemap-default))
721 (format-entry (or (org-publish-property :sitemap-format-entry project)
722 #'org-publish-sitemap-default-entry))
723 (sort-folders
724 (org-publish-property :sitemap-sort-folders project
725 org-publish-sitemap-sort-folders))
726 (sort-files
727 (org-publish-property :sitemap-sort-files project
728 org-publish-sitemap-sort-files))
729 (ignore-case
730 (org-publish-property :sitemap-ignore-case project
731 org-publish-sitemap-sort-ignore-case))
732 (org-file-p (lambda (f) (equal "org" (file-name-extension f))))
733 (sort-predicate
734 (lambda (a b)
735 (let ((retval t))
736 ;; First we sort files:
737 (pcase sort-files
738 (`alphabetically
739 (let ((A (if (funcall org-file-p a)
740 (concat (file-name-directory a)
741 (org-publish-find-title a project))
743 (B (if (funcall org-file-p b)
744 (concat (file-name-directory b)
745 (org-publish-find-title b project))
746 b)))
747 (setq retval
748 (if ignore-case
749 (not (string-lessp (upcase B) (upcase A)))
750 (not (string-lessp B A))))))
751 ((or `anti-chronologically `chronologically)
752 (let* ((adate (org-publish-find-date a project))
753 (bdate (org-publish-find-date b project))
754 (A (+ (lsh (car adate) 16) (cadr adate)))
755 (B (+ (lsh (car bdate) 16) (cadr bdate))))
756 (setq retval
757 (if (eq sort-files 'chronologically)
758 (<= A B)
759 (>= A B)))))
760 (`nil nil)
761 (_ (user-error "Invalid sort value %s" sort-files)))
762 ;; Directory-wise wins:
763 (when (memq sort-folders '(first last))
764 ;; a is directory, b not:
765 (cond
766 ((and (file-directory-p a) (not (file-directory-p b)))
767 (setq retval (eq sort-folders 'first)))
768 ;; a is not a directory, but b is:
769 ((and (not (file-directory-p a)) (file-directory-p b))
770 (setq retval (eq sort-folders 'last)))))
771 retval))))
772 (message "Generating sitemap for %s" title)
773 (with-temp-file sitemap-filename
774 (insert
775 (let ((files (remove sitemap-filename
776 (org-publish-get-base-files project))))
777 ;; Add directories, if applicable.
778 (unless (and (eq style 'list) (eq sort-folders 'ignore))
779 (setq files
780 (nconc (remove root (org-uniquify
781 (mapcar #'file-name-directory files)))
782 files)))
783 ;; Eventually sort all entries.
784 (when (or sort-files (not (memq sort-folders 'ignore)))
785 (setq files (sort files sort-predicate)))
786 (funcall sitemap-builder
787 title
788 (org-publish--sitemap-files-to-lisp
789 files project style format-entry)))))))
791 (defun org-publish-find-property (file property project &optional backend)
792 "Find the PROPERTY of FILE in project.
794 PROPERTY is a keyword referring to an export option, as defined
795 in `org-export-options-alist' or in export back-ends. In the
796 latter case, optional argument BACKEND has to be set to the
797 back-end where the option is defined, e.g.,
799 (org-publish-find-property file :subtitle 'latex)
801 Return value may be a string or a list, depending on the type of
802 PROPERTY, i.e. \"behavior\" parameter from `org-export-options-alist'."
803 (let ((file (org-publish--expand-file-name file project)))
804 (when (and (file-readable-p file) (not (directory-name-p file)))
805 (let* ((org-inhibit-startup t)
806 (visiting (find-buffer-visiting file))
807 (buffer (or visiting (find-file-noselect file))))
808 (unwind-protect
809 (plist-get (with-current-buffer buffer
810 (if (not visiting) (org-export-get-environment backend)
811 ;; Protect local variables in open buffers.
812 (org-export-with-buffer-copy
813 (org-export-get-environment backend))))
814 property)
815 (unless visiting (kill-buffer buffer)))))))
817 (defun org-publish-find-title (file project)
818 "Find the title of FILE in PROJECT."
819 (let ((file (org-publish--expand-file-name file project)))
820 (or (org-publish-cache-get-file-property file :title nil t)
821 (let* ((parsed-title (org-publish-find-property file :title project))
822 (title
823 (if parsed-title
824 ;; Remove property so that the return value is
825 ;; cache-able (i.e., it can be `read' back).
826 (org-no-properties
827 (org-element-interpret-data parsed-title))
828 (file-name-nondirectory (file-name-sans-extension file)))))
829 (org-publish-cache-set-file-property file :title title)
830 title))))
832 (defun org-publish-find-date (file project)
833 "Find the date of FILE in PROJECT.
834 This function assumes FILE is either a directory or an Org file.
835 If FILE is an Org file and provides a DATE keyword use it. In
836 any other case use the file system's modification time. Return
837 time in `current-time' format."
838 (let ((file (org-publish--expand-file-name file project)))
839 (if (file-directory-p file) (nth 5 (file-attributes file))
840 (let ((date (org-publish-find-property file :date project)))
841 ;; DATE is a secondary string. If it contains a time-stamp,
842 ;; convert it to internal format. Otherwise, use FILE
843 ;; modification time.
844 (cond ((let ((ts (and (consp date) (assq 'timestamp date))))
845 (and ts
846 (let ((value (org-element-interpret-data ts)))
847 (and (org-string-nw-p value)
848 (org-time-string-to-time value))))))
849 ((file-exists-p file) (nth 5 (file-attributes file)))
850 (t (error "No such file: \"%s\"" file)))))))
852 (defun org-publish-sitemap-default-entry (entry style project)
853 "Default format for site map ENTRY, as a string.
854 ENTRY is a file name. STYLE is the style of the sitemap.
855 PROJECT is the current project."
856 (cond ((not (directory-name-p entry))
857 (format "[[file:%s][%s]]"
858 entry
859 (org-publish-find-title entry project)))
860 ((eq style 'tree)
861 ;; Return only last subdir.
862 (file-name-nondirectory (directory-file-name entry)))
863 (t entry)))
865 (defun org-publish-sitemap-default (title list)
866 "Default site map, as a string.
867 TITLE is the the title of the site map. LIST is an internal
868 representation for the files to include, as returned by
869 `org-list-to-lisp'. PROJECT is the current project."
870 (concat "#+TITLE: " title "\n\n"
871 (org-list-to-org list)))
874 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
875 ;;; Interactive publishing functions
877 ;;;###autoload
878 (defalias 'org-publish-project 'org-publish)
880 ;;;###autoload
881 (defun org-publish (project &optional force async)
882 "Publish PROJECT.
884 PROJECT is either a project name, as a string, or a project
885 alist (see `org-publish-project-alist' variable).
887 When optional argument FORCE is non-nil, force publishing all
888 files in PROJECT. With a non-nil optional argument ASYNC,
889 publishing will be done asynchronously, in another process."
890 (interactive
891 (list (assoc (completing-read "Publish project: "
892 org-publish-project-alist nil t)
893 org-publish-project-alist)
894 current-prefix-arg))
895 (let ((project (if (not (stringp project)) project
896 ;; If this function is called in batch mode,
897 ;; PROJECT is still a string here.
898 (assoc project org-publish-project-alist))))
899 (cond
900 ((not project))
901 (async
902 (org-export-async-start (lambda (_) nil)
903 `(let ((org-publish-use-timestamps-flag
904 ,(and (not force) org-publish-use-timestamps-flag)))
905 ;; Expand components right now as external process may not
906 ;; be aware of complete `org-publish-project-alist'.
907 (org-publish-projects
908 ',(org-publish-expand-projects (list project))))))
909 (t (save-window-excursion
910 (let ((org-publish-use-timestamps-flag
911 (and (not force) org-publish-use-timestamps-flag)))
912 (org-publish-projects (list project))))))))
914 ;;;###autoload
915 (defun org-publish-all (&optional force async)
916 "Publish all projects.
917 With prefix argument FORCE, remove all files in the timestamp
918 directory and force publishing all projects. With a non-nil
919 optional argument ASYNC, publishing will be done asynchronously,
920 in another process."
921 (interactive "P")
922 (if async
923 (org-export-async-start (lambda (_) nil)
924 `(progn
925 (when ',force (org-publish-remove-all-timestamps))
926 (let ((org-publish-use-timestamps-flag
927 (if ',force nil ,org-publish-use-timestamps-flag)))
928 (org-publish-projects ',org-publish-project-alist))))
929 (when force (org-publish-remove-all-timestamps))
930 (save-window-excursion
931 (let ((org-publish-use-timestamps-flag
932 (if force nil org-publish-use-timestamps-flag)))
933 (org-publish-projects org-publish-project-alist)))))
936 ;;;###autoload
937 (defun org-publish-current-file (&optional force async)
938 "Publish the current file.
939 With prefix argument FORCE, force publish the file. When
940 optional argument ASYNC is non-nil, publishing will be done
941 asynchronously, in another process."
942 (interactive "P")
943 (let ((file (buffer-file-name (buffer-base-buffer))))
944 (if async
945 (org-export-async-start (lambda (_) nil)
946 `(let ((org-publish-use-timestamps-flag
947 (if ',force nil ,org-publish-use-timestamps-flag)))
948 (org-publish-file ,file)))
949 (save-window-excursion
950 (let ((org-publish-use-timestamps-flag
951 (if force nil org-publish-use-timestamps-flag)))
952 (org-publish-file file))))))
954 ;;;###autoload
955 (defun org-publish-current-project (&optional force async)
956 "Publish the project associated with the current file.
957 With a prefix argument, force publishing of all files in
958 the project."
959 (interactive "P")
960 (save-window-excursion
961 (let ((project (org-publish-get-project-from-filename
962 (buffer-file-name (buffer-base-buffer)) 'up)))
963 (if project (org-publish project force async)
964 (error "File %s is not part of any known project"
965 (buffer-file-name (buffer-base-buffer)))))))
969 ;;; Index generation
971 (defun org-publish-collect-index (output _backend info)
972 "Update index for a file in cache.
974 OUTPUT is the output from transcoding current file. BACKEND is
975 the back-end that was used for transcoding. INFO is a plist
976 containing publishing and export options.
978 The index relative to current file is stored as an alist. An
979 association has the following shape: (TERM FILE-NAME PARENT),
980 where TERM is the indexed term, as a string, FILE-NAME is the
981 original full path of the file where the term in encountered, and
982 PARENT is a reference to the headline, if any, containing the
983 original index keyword. When non-nil, this reference is a cons
984 cell. Its CAR is a symbol among `id', `custom-id' and `name' and
985 its CDR is a string."
986 (let ((file (plist-get info :input-file)))
987 (org-publish-cache-set-file-property
988 file :index
989 (delete-dups
990 (org-element-map (plist-get info :parse-tree) 'keyword
991 (lambda (k)
992 (when (equal (org-element-property :key k) "INDEX")
993 (let ((parent (org-export-get-parent-headline k)))
994 (list (org-element-property :value k)
995 file
996 (cond
997 ((not parent) nil)
998 ((let ((id (org-element-property :ID parent)))
999 (and id (cons 'id id))))
1000 ((let ((id (org-element-property :CUSTOM_ID parent)))
1001 (and id (cons 'custom-id id))))
1002 (t (cons 'name
1003 ;; Remove statistics cookie.
1004 (replace-regexp-in-string
1005 "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
1006 (org-element-property :raw-value parent)))))))))
1007 info))))
1008 ;; Return output unchanged.
1009 output)
1011 (defun org-publish-index-generate-theindex (project directory)
1012 "Retrieve full index from cache and build \"theindex.org\".
1013 PROJECT is the project the index relates to. DIRECTORY is the
1014 publishing directory."
1015 (let ((all-files (org-publish-get-base-files project))
1016 full-index)
1017 ;; Compile full index and sort it alphabetically.
1018 (dolist (file all-files
1019 (setq full-index
1020 (sort (nreverse full-index)
1021 (lambda (a b) (string< (downcase (car a))
1022 (downcase (car b)))))))
1023 (let ((index (org-publish-cache-get-file-property file :index)))
1024 (dolist (term index)
1025 (unless (member term full-index) (push term full-index)))))
1026 ;; Write "theindex.inc" in DIRECTORY.
1027 (with-temp-file (expand-file-name "theindex.inc" directory)
1028 (let ((current-letter nil) (last-entry nil))
1029 (dolist (idx full-index)
1030 (let* ((entry (org-split-string (car idx) "!"))
1031 (letter (upcase (substring (car entry) 0 1)))
1032 ;; Transform file into a path relative to publishing
1033 ;; directory.
1034 (file (file-relative-name
1035 (nth 1 idx)
1036 (plist-get (cdr project) :base-directory))))
1037 ;; Check if another letter has to be inserted.
1038 (unless (string= letter current-letter)
1039 (insert (format "* %s\n" letter)))
1040 ;; Compute the first difference between last entry and
1041 ;; current one: it tells the level at which new items
1042 ;; should be added.
1043 (let* ((rank
1044 (if (equal entry last-entry) (1- (length entry))
1045 (cl-loop for n from 0 to (length entry)
1046 unless (equal (nth n entry) (nth n last-entry))
1047 return n)))
1048 (len (length (nthcdr rank entry))))
1049 ;; For each term after the first difference, create
1050 ;; a new sub-list with the term as body. Moreover,
1051 ;; linkify the last term.
1052 (dotimes (n len)
1053 (insert
1054 (concat
1055 (make-string (* (+ rank n) 2) ?\s) " - "
1056 (if (not (= (1- len) n)) (nth (+ rank n) entry)
1057 ;; Last term: Link it to TARGET, if possible.
1058 (let ((target (nth 2 idx)))
1059 (format
1060 "[[%s][%s]]"
1061 ;; Destination.
1062 (pcase (car target)
1063 (`nil (format "file:%s" file))
1064 (`id (format "id:%s" (cdr target)))
1065 (`custom-id (format "file:%s::#%s" file (cdr target)))
1066 (_ (format "file:%s::*%s" file (cdr target))))
1067 ;; Description.
1068 (car (last entry)))))
1069 "\n"))))
1070 (setq current-letter letter last-entry entry))))
1071 ;; Create "theindex.org", if it doesn't exist yet, and provide
1072 ;; a default index file.
1073 (let ((index.org (expand-file-name "theindex.org" directory)))
1074 (unless (file-exists-p index.org)
1075 (with-temp-file index.org
1076 (insert "#+TITLE: Index\n\n#+INCLUDE: \"theindex.inc\"\n\n")))))))
1080 ;;; External Fuzzy Links Resolution
1082 ;; This part implements tools to resolve [[file.org::*Some headline]]
1083 ;; links, where "file.org" belongs to the current project.
1085 (defun org-publish--store-crossrefs (output _backend info)
1086 "Store cross-references for current published file.
1088 OUPUT is the produced output, as a string. BACKEND is the export
1089 back-end used, as a symbol. INFO is the final export state, as
1090 a plist.
1092 This function is meant to be used as a final output filter. See
1093 `org-publish-org-to'."
1094 (org-publish-cache-set-file-property
1095 (plist-get info :input-file) :crossrefs
1096 ;; Update `:crossrefs' so as to remove unused references and search
1097 ;; cells. Actually used references are extracted from
1098 ;; `:internal-references', with references as strings removed. See
1099 ;; `org-export-get-reference' for details.
1100 (cl-remove-if (lambda (pair) (stringp (car pair)))
1101 (plist-get info :internal-references)))
1102 ;; Return output unchanged.
1103 output)
1105 (defun org-publish-resolve-external-link (search file)
1106 "Return reference for element matching string SEARCH in FILE.
1108 Return value is an internal reference, as a string.
1110 This function allows resolving external links with a search
1111 option, e.g.,
1113 [[file.org::*heading][description]]
1114 [[file.org::#custom-id][description]]
1115 [[file.org::fuzzy][description]]
1117 It only makes sense to use this if export back-end builds
1118 references with `org-export-get-reference'."
1119 (if (not org-publish-cache)
1120 (progn
1121 (message "Reference %S in file %S cannot be resolved without publishing"
1122 search
1123 file)
1124 "MissingReference")
1125 (let* ((filename (expand-file-name file))
1126 (crossrefs
1127 (org-publish-cache-get-file-property filename :crossrefs nil t))
1128 (cells (org-export-string-to-search-cell search)))
1130 ;; Look for reference associated to search cells triggered by
1131 ;; LINK. It can match when targeted file has been published
1132 ;; already.
1133 (let ((known (cdr (cl-some (lambda (c) (assoc c crossrefs)) cells))))
1134 (and known (org-export-format-reference known)))
1135 ;; Search cell is unknown so far. Generate a new internal
1136 ;; reference that will be used when the targeted file will be
1137 ;; published.
1138 (let ((new (org-export-new-reference crossrefs)))
1139 (dolist (cell cells) (push (cons cell new) crossrefs))
1140 (org-publish-cache-set-file-property filename :crossrefs crossrefs)
1141 (org-export-format-reference new))))))
1145 ;;; Caching functions
1147 (defun org-publish-write-cache-file (&optional free-cache)
1148 "Write `org-publish-cache' to file.
1149 If FREE-CACHE, empty the cache."
1150 (unless org-publish-cache
1151 (error "`org-publish-write-cache-file' called, but no cache present"))
1153 (let ((cache-file (org-publish-cache-get ":cache-file:")))
1154 (unless cache-file
1155 (error "Cannot find cache-file name in `org-publish-write-cache-file'"))
1156 (with-temp-file cache-file
1157 (let (print-level print-length)
1158 (insert "(setq org-publish-cache \
1159 \(make-hash-table :test 'equal :weakness nil :size 100))\n")
1160 (maphash (lambda (k v)
1161 (insert
1162 (format "(puthash %S %s%S org-publish-cache)\n"
1163 k (if (or (listp v) (symbolp v)) "'" "") v)))
1164 org-publish-cache)))
1165 (when free-cache (org-publish-reset-cache))))
1167 (defun org-publish-initialize-cache (project-name)
1168 "Initialize the projects cache if not initialized yet and return it."
1170 (unless project-name
1171 (error "Cannot initialize `org-publish-cache' without projects name in \
1172 `org-publish-initialize-cache'"))
1174 (unless (file-exists-p org-publish-timestamp-directory)
1175 (make-directory org-publish-timestamp-directory t))
1176 (unless (file-directory-p org-publish-timestamp-directory)
1177 (error "Org publish timestamp: %s is not a directory"
1178 org-publish-timestamp-directory))
1180 (unless (and org-publish-cache
1181 (string= (org-publish-cache-get ":project:") project-name))
1182 (let* ((cache-file
1183 (concat
1184 (expand-file-name org-publish-timestamp-directory)
1185 project-name ".cache"))
1186 (cexists (file-exists-p cache-file)))
1188 (when org-publish-cache (org-publish-reset-cache))
1190 (if cexists (load-file cache-file)
1191 (setq org-publish-cache
1192 (make-hash-table :test 'equal :weakness nil :size 100))
1193 (org-publish-cache-set ":project:" project-name)
1194 (org-publish-cache-set ":cache-file:" cache-file))
1195 (unless cexists (org-publish-write-cache-file nil))))
1196 org-publish-cache)
1198 (defun org-publish-reset-cache ()
1199 "Empty org-publish-cache and reset it nil."
1200 (message "%s" "Resetting org-publish-cache")
1201 (when (hash-table-p org-publish-cache)
1202 (clrhash org-publish-cache))
1203 (setq org-publish-cache nil))
1205 (defun org-publish-cache-file-needs-publishing
1206 (filename &optional pub-dir pub-func _base-dir)
1207 "Check the timestamp of the last publishing of FILENAME.
1208 Return non-nil if the file needs publishing. Also check if
1209 any included files have been more recently published, so that
1210 the file including them will be republished as well."
1211 (unless org-publish-cache
1212 (error
1213 "`org-publish-cache-file-needs-publishing' called, but no cache present"))
1214 (let* ((key (org-publish-timestamp-filename filename pub-dir pub-func))
1215 (pstamp (org-publish-cache-get key))
1216 (org-inhibit-startup t)
1217 included-files-ctime)
1218 (when (equal (file-name-extension filename) "org")
1219 (let ((visiting (find-buffer-visiting filename))
1220 (buf (find-file-noselect filename))
1221 (case-fold-search t))
1222 (unwind-protect
1223 (with-current-buffer buf
1224 (goto-char (point-min))
1225 (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t)
1226 (let* ((element (org-element-at-point))
1227 (included-file
1228 (and (eq (org-element-type element) 'keyword)
1229 (let ((value (org-element-property :value element)))
1230 (and value
1231 (string-match
1232 "\\`\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)"
1233 value)
1234 (let ((m (match-string 1 value)))
1235 (org-unbracket-string
1236 "\"" "\""
1237 ;; Ignore search suffix.
1238 (if (string-match "::.*?\"?\\'" m)
1239 (substring m 0 (match-beginning 0))
1240 m))))))))
1241 (when included-file
1242 (push (org-publish-cache-ctime-of-src
1243 (expand-file-name included-file))
1244 included-files-ctime)))))
1245 (unless visiting (kill-buffer buf)))))
1246 (or (null pstamp)
1247 (let ((ctime (org-publish-cache-ctime-of-src filename)))
1248 (or (< pstamp ctime)
1249 (cl-some (lambda (ct) (< ctime ct)) included-files-ctime))))))
1251 (defun org-publish-cache-set-file-property
1252 (filename property value &optional project-name)
1253 "Set the VALUE for a PROPERTY of file FILENAME in publishing cache to VALUE.
1254 Use cache file of PROJECT-NAME. If the entry does not exist, it
1255 will be created. Return VALUE."
1256 ;; Evtl. load the requested cache file:
1257 (if project-name (org-publish-initialize-cache project-name))
1258 (let ((pl (org-publish-cache-get filename)))
1259 (if pl (progn (plist-put pl property value) value)
1260 (org-publish-cache-get-file-property
1261 filename property value nil project-name))))
1263 (defun org-publish-cache-get-file-property
1264 (filename property &optional default no-create project-name)
1265 "Return the value for a PROPERTY of file FILENAME in publishing cache.
1266 Use cache file of PROJECT-NAME. Return the value of that PROPERTY,
1267 or DEFAULT, if the value does not yet exist. Create the entry,
1268 if necessary, unless NO-CREATE is non-nil."
1269 ;; Evtl. load the requested cache file:
1270 (if project-name (org-publish-initialize-cache project-name))
1271 (let ((pl (org-publish-cache-get filename)) retval)
1272 (if pl
1273 (if (plist-member pl property)
1274 (setq retval (plist-get pl property))
1275 (setq retval default))
1276 ;; no pl yet:
1277 (unless no-create
1278 (org-publish-cache-set filename (list property default)))
1279 (setq retval default))
1280 retval))
1282 (defun org-publish-cache-get (key)
1283 "Return the value stored in `org-publish-cache' for key KEY.
1284 Return nil, if no value or nil is found. Raise an error if the
1285 cache does not exist."
1286 (unless org-publish-cache
1287 (error "`org-publish-cache-get' called, but no cache present"))
1288 (gethash key org-publish-cache))
1290 (defun org-publish-cache-set (key value)
1291 "Store KEY VALUE pair in `org-publish-cache'.
1292 Returns value on success, else nil. Raise an error if the cache
1293 does not exist."
1294 (unless org-publish-cache
1295 (error "`org-publish-cache-set' called, but no cache present"))
1296 (puthash key value org-publish-cache))
1298 (defun org-publish-cache-ctime-of-src (file)
1299 "Get the ctime of FILE as an integer."
1300 (let ((attr (file-attributes
1301 (expand-file-name (or (file-symlink-p file) file)
1302 (file-name-directory file)))))
1303 (if (not attr) (error "No such file: \"%s\"" file)
1304 (+ (lsh (car (nth 5 attr)) 16)
1305 (cadr (nth 5 attr))))))
1308 (provide 'ox-publish)
1310 ;; Local variables:
1311 ;; generated-autoload-file: "org-loaddefs.el"
1312 ;; End:
1314 ;;; ox-publish.el ends here