Browse Source

Fix file sorting for publishing.

Carsten Dominik 15 years ago
parent
commit
830e0cfe40
2 changed files with 22 additions and 11 deletions
  1. 2 0
      lisp/ChangeLog
  2. 20 11
      lisp/org-publish.el

+ 2 - 0
lisp/ChangeLog

@@ -1,5 +1,7 @@
 2010-04-22  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-publish.el (org-publish-compare-directory-files): Fix sorting.
+
 	* org-compat.el (org-get-x-clipboard-compat): Use (featurep 'xemacs).
 
 	* org-publish.el (org-publish-project-alist): Update docstring.

+ 20 - 11
lisp/org-publish.el

@@ -384,24 +384,33 @@ eventually alphabetically."
     (when (or sitemap-alphabetically sitemap-sort-folders)
       ;; First we sort alphabetically:
       (when sitemap-alphabetically
-        (let ((aorg (and (string-match "\\.org$" a) (not (file-directory-p a))))
-              (borg (and (string-match "\\.org$" b) (not (file-directory-p b)))))
-          (setq retval
-                (if sitemap-ignore-case
-                    (string-lessp (if borg (upcase (org-publish-find-title a)) (upcase a))
-                                  (if aorg (upcase (org-publish-find-title b)) (upcase b)))
-                  (string-lessp (if borg (org-publish-find-title a) a)
-                                (if aorg (org-publish-find-title b) b))))))
+        (let* ((adir (file-directory-p a))
+               (aorg (and (string-match "\\.org$" a) (not adir)))
+               (bdir (file-directory-p b))
+               (borg (and (string-match "\\.org$" b) (not bdir)))
+               (A (if aorg (org-publish-find-title a) a))
+               (B (if borg (org-publish-find-title b) b)))
+          ;; If we have a directory and an Org file, we need to combine
+          ;; directory and title as filename of the Org file:
+          (when (and adir borg)
+            (setq B (concat (file-name-directory b) B)))
+          (when (and bdir aorg)
+            (setq A (concat (file-name-directory a) A)))
+          ;;
+          (setq retval (if sitemap-ignore-case
+			   (string-lessp (upcase A) (upcase B))
+			 (string-lessp A B)))))
+
       ;; Directory-wise wins:
       (when sitemap-sort-folders
         ;; a is directory, b not:
         (cond
          ((and (file-directory-p a) (not (file-directory-p b)))
-          (setq retval (eq sitemap-sort-folders 'first)))
+          (setq retval (equal sitemap-sort-folders 'first)))
           ;; a is not a directory, but b is:
          ((and (not (file-directory-p a)) (file-directory-p b))
-          (setq retval (eq sitemap-sort-folders 'last))))))
-      retval))
+          (setq retval (equal sitemap-sort-folders 'last))))))
+    retval))
 
 (defun org-publish-get-base-files-1 (base-dir &optional recurse match skip-file skip-dir)
   "Set `org-publish-temp-files' with files from BASE-DIR directory.