diff --git a/lisp/org-publish.el b/lisp/org-publish.el index 54d489c..40553f1 100644 --- a/lisp/org-publish.el +++ b/lisp/org-publish.el @@ -583,6 +583,8 @@ Default for INDEX-FILENAME is 'index.org'." (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 (org-publish-get-base-files project exclude-regexp)) (index-filename (concat dir (or index-filename "index.org"))) @@ -597,15 +599,35 @@ Default for INDEX-FILENAME is 'index.org'." (with-temp-buffer (insert (concat index-title "\n\n")) (while (setq file (pop files)) - (let ((fn (file-name-nondirectory file))) + (let ((fn (file-name-nondirectory file)) + (link (file-relative-name file dir)) + (oldlocal localdir)) ;; index shouldn't index itself - (unless (string= fn ifn) - (insert (concat " + [[file:" fn "][" + (unless (string= fn ifn) + (setq localdir (concat (file-name-as-directory dir) (file-name-directory link))) + (unless (string= localdir oldlocal) + (if (string= (file-name-directory (directory-file-name localdir)) + (file-name-directory (directory-file-name oldlocal))) + (progn ; next subdir, same parent + (setq indent-str (make-string (- (length indent-str) 2) ? )) + (insert (concat indent-str " + [[file:" (file-relative-name localdir dir) + "][" (file-relative-name localdir dir) "]]\n")) + (setq indent-str (make-string (+ (length indent-str) 2) ? ))) + (if (> (length localdir) (length oldlocal)) + (progn ; entering deeper subdir + (insert (concat indent-str " + [[file:" (file-relative-name localdir dir) + "][" (file-relative-name localdir dir) "]]\n")) + (setq indent-str (make-string (+ (length indent-str) 2) ? ))) + ; up directory + (setq indent-str (make-string (- (length indent-str) 2) ? ))))) + (insert (concat indent-str " + [[file:" link "][" (file-name-sans-extension fn) "]]\n"))))) (write-file index-filename) (kill-buffer (current-buffer))))) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Interactive publishing functions