>From a9ae0ecc623d2794475f3481765c637447f1ab24 Mon Sep 17 00:00:00 2001 From: thibault Date: Wed, 28 Sep 2016 22:47:48 -0500 Subject: [PATCH] ox-publish.el: Option to use headings instead of list in sitemap * list/ox-publish.el (org-publish-org-sitemap): Add an optional parameter allowing generation of a sitemap composed of headings instead of list items. --- lisp/ox-publish.el | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el index 14c93b2..ceb0673 100644 --- a/lisp/ox-publish.el +++ b/lisp/ox-publish.el @@ -716,15 +716,17 @@ If `:auto-sitemap' is set, publish the sitemap too. If ((functionp fun) (funcall fun project-plist)))) (org-publish-write-cache-file)))) -(defun org-publish-org-sitemap (project &optional sitemap-filename) +(defun org-publish-org-sitemap + (project &optional sitemap-filename use-headings) "Create a sitemap of pages in set defined by PROJECT. Optionally set the filename of the sitemap with SITEMAP-FILENAME. -Default for SITEMAP-FILENAME is `sitemap.org'." +Default for SITEMAP-FILENAME is `sitemap.org'. When USE-HEADINGS +is nil (default), the sitemap produced is a list, otherwise it +uses headings." (let* ((project-plist (cdr project)) (dir (file-name-as-directory (plist-get project-plist :base-directory))) (localdir (file-name-directory dir)) - (indent-str (make-string 2 ?\ )) (exclude-regexp (plist-get project-plist :exclude)) (files (nreverse (org-publish-get-base-files project exclude-regexp))) @@ -736,7 +738,18 @@ Default for SITEMAP-FILENAME is `sitemap.org'." (sitemap-sans-extension (plist-get project-plist :sitemap-sans-extension)) (visiting (find-buffer-visiting sitemap-filename)) - file sitemap-buffer) + file sitemap-buffer + (entry-string + (if use-headings + `((indent . ,(make-string 1 ?*)) + (char-space . " ")) + `((indent . ,(make-string 2 ?\ )) + (char-space . " + ")))) + (entry-string-indent (cdr (assq 'indent entry-string))) + (entry-string-char (string-to-char + (substring entry-string-indent 0 1))) + (entry-string-indent-char (cdr (assq 'char-space entry-string))) + (indent-str entry-string-indent)) (with-current-buffer (let ((org-inhibit-startup t)) (setq sitemap-buffer @@ -758,7 +771,7 @@ Default for SITEMAP-FILENAME is `sitemap.org'." (file-name-directory link))) (unless (string= localdir oldlocal) (if (string= localdir dir) - (setq indent-str (make-string 2 ?\ )) + (setq indent-str entry-string-indent) (let ((subdirs (split-string (directory-file-name @@ -767,16 +780,18 @@ Default for SITEMAP-FILENAME is `sitemap.org'." (subdir "") (old-subdirs (split-string (file-relative-name oldlocal dir) "/"))) - (setq indent-str (make-string 2 ?\ )) + (setq indent-str entry-string-indent) (while (string= (car old-subdirs) (car subdirs)) - (setq indent-str (concat indent-str (make-string 2 ?\ ))) + (setq indent-str (concat indent-str entry-string-indent)) (pop old-subdirs) (pop subdirs)) (dolist (d subdirs) (setq subdir (concat subdir d "/")) - (insert (concat indent-str " + " d "\n")) + (insert (concat indent-str entry-string-indent-char d "\n")) (setq indent-str (make-string - (+ (length indent-str) 2) ?\ ))))))) + (+ (length indent-str) + (length entry-string-indent)) + entry-string-char))))))) ;; This is common to 'flat and 'tree (let ((entry (org-publish-format-file-entry @@ -784,12 +799,14 @@ Default for SITEMAP-FILENAME is `sitemap.org'." (regexp "\\(.*\\)\\[\\([^][]+\\)\\]\\(.*\\)")) (cond ((string-match-p regexp entry) (string-match regexp entry) - (insert (concat indent-str " + " (match-string 1 entry) + (insert (concat indent-str entry-string-indent-char + (match-string 1 entry) "[[file:" link "][" (match-string 2 entry) "]]" (match-string 3 entry) "\n"))) (t - (insert (concat indent-str " + [[file:" link "][" + (insert (concat indent-str entry-string-indent-char + "[[file:" link "][" entry "]]\n")))))))) (save-buffer)) -- 2.9.3