|
@@ -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.
|
|
@@ -261,6 +267,22 @@ You can overwrite this default per project in your
|
|
|
:group 'org-publish
|
|
|
:type 'boolean)
|
|
|
|
|
|
+(defcustom org-publish-sitemap-date-format "%Y-%m-%d"
|
|
|
+ "Format for `format-time-string' which is used to print a date
|
|
|
+in the sitemap."
|
|
|
+ :group 'org-publish
|
|
|
+ :type 'string)
|
|
|
+
|
|
|
+(defcustom org-publish-sitemap-file-entry-format "%T"
|
|
|
+ "How a sitemap file entry is formated.
|
|
|
+You could use brackets to delimit on what part the link will be.
|
|
|
+
|
|
|
+%T is the title.
|
|
|
+%A is the author.
|
|
|
+%D is the date formated using `org-publish-sitemap-date-format'."
|
|
|
+ :group 'org-publish
|
|
|
+ :type 'string)
|
|
|
+
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
;;; Timestamp-related functions
|
|
|
|
|
@@ -360,30 +382,41 @@ 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)
|
|
|
+(defvar sitemap-date-format)
|
|
|
+(defvar sitemap-file-entry-format)
|
|
|
(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* ((adate (org-publish-find-date a))
|
|
|
+ (bdate (org-publish-find-date b))
|
|
|
+ (A (+ (lsh (car adate) 16) (cadr adate)))
|
|
|
+ (B (+ (lsh (car bdate) 16) (cadr bdate))))
|
|
|
+ (setq retval (if (equal sitemap-sort-files 'chronologically)
|
|
|
+ (<= A B)
|
|
|
+ (>= A B)))))))
|
|
|
;; Directory-wise wins:
|
|
|
(when sitemap-sort-folders
|
|
|
;; a is directory, b not:
|
|
@@ -441,10 +474,14 @@ 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
|
|
|
+ (cond ((plist-member project-plist :sitemap-sort-files)
|
|
|
+ (plist-get project-plist :sitemap-sort-files))
|
|
|
+ ;; For backward compatibility:
|
|
|
+ ((plist-member project-plist :sitemap-alphabetically)
|
|
|
+ (if (plist-get project-plist :sitemap-alphabetically)
|
|
|
+ 'alphabetically nil))
|
|
|
+ (t org-publish-sitemap-sort-files)))
|
|
|
(sitemap-ignore-case
|
|
|
(if (plist-member project-plist :sitemap-ignore-case)
|
|
|
(plist-get project-plist :sitemap-ignore-case)
|
|
@@ -487,10 +524,10 @@ matching filenames."
|
|
|
(e (plist-get (cdr prj) :exclude))
|
|
|
(i (plist-get (cdr prj) :include))
|
|
|
(xm (concat "^" b (if r ".+" "[^/]+") "\\.\\(" x "\\)$")))
|
|
|
- (when (or
|
|
|
+ (when
|
|
|
+ (or
|
|
|
(and
|
|
|
- i
|
|
|
- (member filename
|
|
|
+ i (member filename
|
|
|
(mapcar
|
|
|
(lambda (file) (expand-file-name file b))
|
|
|
i)))
|
|
@@ -684,6 +721,10 @@ If :makeindex is set, also produce a file theindex.org."
|
|
|
"sitemap.org"))
|
|
|
(sitemap-function (or (plist-get project-plist :sitemap-function)
|
|
|
'org-publish-org-sitemap))
|
|
|
+ (sitemap-date-format (or (plist-get project-plist :sitemap-date-format)
|
|
|
+ org-publish-sitemap-date-format))
|
|
|
+ (sitemap-file-entry-format (or (plist-get project-plist :sitemap-file-entry-format)
|
|
|
+ org-publish-sitemap-file-entry-format))
|
|
|
(preparation-function (plist-get project-plist :preparation-function))
|
|
|
(completion-function (plist-get project-plist :completion-function))
|
|
|
(files (org-publish-get-base-files project exclude-regexp)) file)
|
|
@@ -759,12 +800,32 @@ Default for SITEMAP-FILENAME is 'sitemap.org'."
|
|
|
(setq indent-str (make-string
|
|
|
(+ (length indent-str) 2) ?\ )))))))
|
|
|
;; This is common to 'flat and 'tree
|
|
|
- (insert (concat indent-str " + [[file:" link "]["
|
|
|
- (org-publish-find-title file)
|
|
|
- "]]\n")))))
|
|
|
+ (let ((entry
|
|
|
+ (org-publish-format-file-entry sitemap-file-entry-format
|
|
|
+ file project-plist))
|
|
|
+ (regexp "\\(.*\\)\\[\\([^][]+\\)\\]\\(.*\\)"))
|
|
|
+ (cond ((string-match-p regexp entry)
|
|
|
+ (string-match regexp entry)
|
|
|
+ (insert (concat indent-str " + " (match-string 1 entry)
|
|
|
+ "[[file:" link "]["
|
|
|
+ (match-string 2 entry)
|
|
|
+ "]]" (match-string 3 entry) "\n")))
|
|
|
+ (t
|
|
|
+ (insert (concat indent-str " + [[file:" link "]["
|
|
|
+ entry
|
|
|
+ "]]\n"))))))))
|
|
|
(save-buffer))
|
|
|
(or visiting (kill-buffer sitemap-buffer))))
|
|
|
|
|
|
+(defun org-publish-format-file-entry (fmt file project-plist)
|
|
|
+ (org-replace-escapes fmt
|
|
|
+ (list (cons "%T" (org-publish-find-title file))
|
|
|
+ (cons "%D" (format-time-string
|
|
|
+ sitemap-date-format
|
|
|
+ (org-publish-find-date file)))
|
|
|
+ (cons "%A" (or (plist-get project-plist :author)
|
|
|
+ user-full-name)))))
|
|
|
+
|
|
|
(defun org-publish-find-title (file)
|
|
|
"Find the title of FILE in project."
|
|
|
(or
|
|
@@ -786,6 +847,24 @@ 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.
|
|
|
+If FILE provides a #+date keyword use it else use the file
|
|
|
+system's modification time.
|
|
|
+
|
|
|
+It returns time in `current-time' format."
|
|
|
+ (let ((visiting (find-buffer-visiting file)))
|
|
|
+ (save-excursion
|
|
|
+ (switch-to-buffer (or visiting (find-file file)))
|
|
|
+ (let* ((plist (org-infile-export-plist))
|
|
|
+ (date (plist-get plist :date)))
|
|
|
+ (unless visiting
|
|
|
+ (kill-buffer (current-buffer)))
|
|
|
+ (if date
|
|
|
+ (org-time-string-to-time date)
|
|
|
+ (when (file-exists-p file)
|
|
|
+ (nth 5 (file-attributes file))))))))
|
|
|
+
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
;;; Interactive publishing functions
|
|
|
|