>From 1858dc5401e1d8520aa712983ee8372ff8657e5b Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 27 May 2016 17:26:03 +0200 Subject: [PATCH 5/6] ox-publish: Sitemap preamble and postamble * lisp/ox-publish.el (org-publish-sitemap-preamble): (org-publish-sitemap-postamble): New defcustom. (org-publish-projects): (org-publish-org-sitemap): Use new defcustom --- lisp/ox-publish.el | 135 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 97 insertions(+), 38 deletions(-) diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el index d94ca04..0fde0cc 100644 --- a/lisp/ox-publish.el +++ b/lisp/ox-publish.el @@ -239,6 +239,14 @@ a site-map of files or summary page for a given project. Format of filenames and directories included in the sitemap. See `org-publish-sitemap-file-entry-format' for details. + `:sitemap-preamble' + `:sitemap-postamble' + + Preamble and postamble for sitemap. Useful for inserting + #+OPTIONS: keywords, footers etc. See + `org-publish-sitemap-preamble' for details. + + If you create a site-map file, adjust the sorting like this: `:sitemap-sort-folders' @@ -409,6 +417,35 @@ See also `org-publish-sitemap-file-entry-format'." :version "25.2" :package-version '(Org . "9.0")) +(defcustom org-publish-sitemap-preamble nil + "Sitemap preamble. + +Can be either a string, a list of strings, or a function that +takes a project-plist as an argument and return a string." + :group 'org-export-publish + :type '(choice + (const :tag "None" nil) + (string :tag "String") + (repeat :tag "List of strings" + (string :tag "String")) + (function :tag "Function")) + :version "25.2" + :package-version '(Org . "9.0")) + +(defcustom org-publish-sitemap-postamble nil + "Sitemap postamble. + +Can be either a string, a list of strings, or a function that +takes a project-plist as an argument and return a string." + :group 'org-export-publish + :type '(choice + (const :tag "None" nil) + (string :tag "String") + (repeat :tag "List of strings" + (string :tag "String")) + (function :tag "Function")) + :version "25.2" + :package-version '(Org . "9.0")) @@ -771,22 +808,28 @@ If `:auto-sitemap' is set, publish the sitemap too. If ;; Each project uses its own cache file. (org-publish-initialize-cache (car project)) (when (plist-get project-plist :auto-sitemap) - (let ((sitemap-filename - (or (plist-get project-plist :sitemap-filename) - "sitemap.org")) - (sitemap-function - (or (plist-get project-plist :sitemap-function) - #'org-publish-org-sitemap)) - (org-publish-sitemap-date-format - (or (plist-get project-plist :sitemap-date-format) - org-publish-sitemap-date-format)) - (org-publish-sitemap-file-entry-format - (or (plist-get project-plist :sitemap-file-entry-format) - org-publish-sitemap-file-entry-format)) - (org-publish-sitemap-dir-entry-format - (or (plist-get project-plist :sitemap-dir-entry-format) - org-publish-sitemap-dir-entry-format)) - (funcall sitemap-function project sitemap-filename))) + (let ((sitemap-filename + (or (plist-get project-plist :sitemap-filename) + "sitemap.org")) + (sitemap-function + (or (plist-get project-plist :sitemap-function) + #'org-publish-org-sitemap)) + (org-publish-sitemap-date-format + (or (plist-get project-plist :sitemap-date-format) + org-publish-sitemap-date-format)) + (org-publish-sitemap-file-entry-format + (or (plist-get project-plist :sitemap-file-entry-format) + org-publish-sitemap-file-entry-format)) + (org-publish-sitemap-dir-entry-format + (or (plist-get project-plist :sitemap-dir-entry-format) + org-publish-sitemap-dir-entry-format)) + (org-publish-sitemap-preamble + (or (plist-get project-plist :sitemap-preamble) + org-publish-sitemap-preamble)) + (org-publish-sitemap-postamble + (or (plist-get project-plist :sitemap-postamble) + org-publish-sitemap-postamble))) + (funcall sitemap-function project sitemap-filename))) ;; Publish all files from PROJECT excepted "theindex.org". Its ;; publishing will be deferred until "theindex.inc" is ;; populated. @@ -812,31 +855,47 @@ If `:auto-sitemap' is set, publish the sitemap too. If Optionally set the filename of the sitemap with SITEMAP-FILENAME. Default for SITEMAP-FILENAME is `sitemap.org'." (let* ((project-plist (cdr project)) - (dir (file-name-as-directory - (plist-get project-plist :base-directory))) - (sitemap-filename (concat dir (or sitemap-filename "sitemap.org"))) - (files (nreverse - ;; Sitemap shouldn't list itself. - (cl-remove sitemap-filename - (org-publish-get-base-files - project - (plist-get project-plist :exclude) t) - :test #'equal))) - (sitemap-title (or (plist-get project-plist :sitemap-title) - (concat "Sitemap for project " (car project))))) + (dir (file-name-as-directory + (plist-get project-plist :base-directory))) + (sitemap-filename (concat dir (or sitemap-filename "sitemap.org"))) + (files (nreverse + ;; Sitemap shouldn't list itself. + (cl-remove sitemap-filename + (org-publish-get-base-files + project + (plist-get project-plist :exclude) t) + :test #'equal))) + (sitemap-title (or (plist-get project-plist :sitemap-title) + (concat "Sitemap for project " (car project)))) + (prepare-pre-or-postamble (lambda (pre-or-postamble) + (cond ((not pre-or-postamble) nil) + ((stringp pre-or-postamble) pre-or-postamble) + ((listp pre-or-postamble) + (mapconcat 'identity preamble "\n")) + ((functionp pre-or-postamble) + (funcall pre-or-postamble project-plist)) + (t (error (concat "unknown `:sitemap-preamble' or " + "`:sitemap-postamble' format"))))))) (with-temp-file sitemap-filename (insert (mapconcat - 'identity - (list - (format "#+TITLE: %s" sitemap-title) - ;; Call function to build sitemap based on files and the project-plist. - (let* ((style (or (plist-get project-plist :sitemap-style) 'tree)) - (fun (intern (format "org-publish-org-sitemap-as-%s" style)))) - (unless (functionp fun) - (error "Unknown function %s for :sitemap-style %s." - fun style)) - (funcall fun files project-plist))) "\n"))))) + 'identity + (list + (format "#+TITLE: %s" sitemap-title) + ;; Insert sitemap-preamble. + (funcall prepare-pre-or-postamble + (plist-get project-plist :sitemap-preamble)) + ;; Call function to build sitemap based on files and the project-plist. + (let* ((style (or (plist-get project-plist :sitemap-style) 'tree)) + (fun (intern (format "org-publish-org-sitemap-as-%s" style)))) + (unless (functionp fun) + (error "Unknown function %s for :sitemap-style %s." + fun style)) + (funcall fun files project-plist)) + ;; Insert sitemap-postamble. + (funcall prepare-pre-or-postamble + (plist-get project-plist :sitemap-postamble))) + "\n"))))) (defun org-publish-org-sitemap-as-list (files project-plist) "Insert FILES as simple list separated by newlines. -- 2.8.3