From mboxrd@z Thu Jan 1 00:00:00 1970 From: Manuel Giraud Subject: [PATCH] Sitemap publish with chronological ordering Date: Mon, 25 Oct 2010 13:41:53 +0200 Message-ID: <87y69meby6.fsf@univ-nantes.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=40446 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PALR8-0003Jn-B5 for emacs-orgmode@gnu.org; Mon, 25 Oct 2010 07:41:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PALR7-0002Vg-M8 for emacs-orgmode@gnu.org; Mon, 25 Oct 2010 07:41:58 -0400 Received: from smtp-tls2.univ-nantes.fr ([193.52.101.146]:57071 helo=smtp-tls.univ-nantes.fr) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PALR7-0002VW-EA for emacs-orgmode@gnu.org; Mon, 25 Oct 2010 07:41:57 -0400 Received: from localhost (debian [127.0.0.1]) by smtp-tls.univ-nantes.fr (Postfix) with ESMTP id 938A840063D for ; Mon, 25 Oct 2010 13:44:39 +0200 (CEST) Received: from smtp-tls.univ-nantes.fr ([127.0.0.1]) by localhost (smtp-tls2.d101.univ-nantes.fr [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Dn0rVntxcJNz for ; Mon, 25 Oct 2010 13:44:39 +0200 (CEST) Received: from K (unknown [172.16.13.134]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by smtp-tls.univ-nantes.fr (Postfix) with ESMTPSA id 7C4B3400631 for ; Mon, 25 Oct 2010 13:44:39 +0200 (CEST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode Here's a patch that add an option to sort files in the sitemap chronologically. A "#+DATE" driven sorting is still missing IMO. --8<---------------cut here---------------start------------->8--- diff --git a/lisp/org-publish.el b/lisp/org-publish.el index c66cd29..74afa87 100644 --- a/lisp/org-publish.el +++ b/lisp/org-publish.el @@ -186,8 +186,9 @@ sitemap of files or summary page for a given project. Set this to `first' (default) or `last' to display folders first or last, respectively. Any other value will mix files and folders. - :sitemap-alphabetically The site map is normally sorted alphabetically. - Set this explicitly to nil to turn off sorting. + :sitemap-sort-files The site map is normally sorted alphabetically. + You can change this behaviour setting this to + `chronologically', `anti-chronologically' or nil. :sitemap-ignore-case Should sorting be case-sensitive? Default nil. The following properties control the creation of a concept index. @@ -233,13 +234,18 @@ Any changes made by this hook will be saved." :group 'org-publish :type 'hook) -(defcustom org-publish-sitemap-sort-alphabetically t - "Should sitemaps be sorted alphabetically by default? +(defcustom org-publish-sitemap-sort-files 'alphabetically + "How sitemaps files should be sorted by default? +Possible values are `alphabetically', `chronologically', `anti-chronologically' and nil. +If `alphabetically', files will be sorted alphabetically. +If `chronologically', files will be sorted with older modification time first. +If `anti-chronologically', files will be sorted with newer modification time first. +nil won't sort files. You can overwrite this default per project in your -`org-publish-project-alist', using `:sitemap-alphabetically'." +`org-publish-project-alist', using `:sitemap-sort-files'." :group 'org-publish - :type 'boolean) + :type 'symbol) (defcustom org-publish-sitemap-sort-folders 'first "A symbol, denoting if folders are sorted first in sitemaps. @@ -360,30 +366,37 @@ This splices all the components into the list." (nreverse (org-publish-delete-dups (delq nil rtn))))) -(defvar sitemap-alphabetically) +(defvar sitemap-sort-files) (defvar sitemap-sort-folders) (defvar sitemap-ignore-case) (defvar sitemap-requested) (defun org-publish-compare-directory-files (a b) - "Predicate for `sort', that sorts folders-first/last and alphabetically." + "Predicate for `sort', that sorts folders and files for sitemap." (let ((retval t)) - (when (or sitemap-alphabetically sitemap-sort-folders) - ;; First we sort alphabetically: - (when sitemap-alphabetically - (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 - (concat (file-name-directory a) - (org-publish-find-title a)) a)) - (B (if borg - (concat (file-name-directory b) - (org-publish-find-title b)) b))) - (setq retval (if sitemap-ignore-case - (not (string-lessp (upcase B) (upcase A))) - (not (string-lessp B A)))))) - + (when (or sitemap-sort-files sitemap-sort-folders) + ;; First we sort files: + (when sitemap-sort-files + (cond ((equal sitemap-sort-files 'alphabetically) + (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 + (concat (file-name-directory a) + (org-publish-find-title a)) a)) + (B (if borg + (concat (file-name-directory b) + (org-publish-find-title b)) b))) + (setq retval (if sitemap-ignore-case + (not (string-lessp (upcase B) (upcase A))) + (not (string-lessp B A)))))) + ((or (equal sitemap-sort-files 'chronologically) + (equal sitemap-sort-files 'anti-chronologically)) + (let ((A (org-publish-find-date a)) + (B (org-publish-find-date b))) + (setq retval (if (equal sitemap-sort-files 'chronologically) + (<= A B) + (>= A B))))))) ;; Directory-wise wins: (when sitemap-sort-folders ;; a is directory, b not: @@ -438,10 +451,10 @@ matching filenames." (if (plist-member project-plist :sitemap-sort-folders) (plist-get project-plist :sitemap-sort-folders) org-publish-sitemap-sort-folders)) - (sitemap-alphabetically - (if (plist-member project-plist :sitemap-alphabetically) - (plist-get project-plist :sitemap-alphabetically) - org-publish-sitemap-sort-alphabetically)) + (sitemap-sort-files + (if (plist-member project-plist :sitemap-sort-files) + (plist-get project-plist :sitemap-sort-files) + org-publish-sitemap-sort-files)) (sitemap-ignore-case (if (plist-member project-plist :sitemap-ignore-case) (plist-get project-plist :sitemap-ignore-case) @@ -780,6 +793,11 @@ Default for SITEMAP-FILENAME is 'sitemap.org'." (org-publish-cache-set-file-property file :title title) title))) +(defun org-publish-find-date (file) + "Find the date of FILE in project." + ;; FIXME add a support for user defined date based on #+DATE keyword. + (org-publish-cache-ctime-of-src file)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Interactive publishing functions --8<---------------cut here---------------end--------------->8--- -- Manuel Giraud