ox-publish.el 43 KB

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