org-e-publish.el 42 KB

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