emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Patch 2/2] org-publish
@ 2010-12-01 10:11 Manuel Giraud
  2011-02-08 17:04 ` Bastien
  0 siblings, 1 reply; 5+ messages in thread
From: Manuel Giraud @ 2010-12-01 10:11 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 254 bytes --]


This second patch (that should be applied after the first one) adds a
formating option to sitemap entries. One can now use a formated string
to generate a sitemap entry. This formated string currently understands
title (%T), author (%A) and date (%D).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: formated-sitemap.patch --]
[-- Type: text/x-patch, Size: 4581 bytes --]

diff --git a/lisp/org-publish.el b/lisp/org-publish.el
index 296921f..ec58af0 100644
--- a/lisp/org-publish.el
+++ b/lisp/org-publish.el
@@ -267,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.
+Watch out the text used for the link should between brackets.
+
+%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
 
@@ -370,6 +386,8 @@ This splices all the components into the list."
 (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 and files for sitemap."
   (let ((retval t))
@@ -392,8 +410,10 @@ This splices all the components into the list."
 				(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)))
+		 (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)))))))
@@ -695,6 +715,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)
@@ -770,12 +794,27 @@ 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 "\\(.*\\)\\[\\([^][]+\\)\\]\\(.*\\)"))
+	      (string-match regexp entry)
+	      (insert (concat indent-str " + " (match-string 1 entry)
+			      "[[file:" link "]["
+			      (match-string 2 entry)
+			      "]]" (match-string 3 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
@@ -800,7 +839,9 @@ Default for SITEMAP-FILENAME is 'sitemap.org'."
 (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."
+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)))
@@ -809,10 +850,9 @@ system's modification time."
 	(unless visiting
 	  (kill-buffer (current-buffer)))
 	(if date
-	    (let ((dt (org-time-string-to-time date)))
-	      (+ (lsh (car dt) 16) (cadr dt)))
+	    (org-time-string-to-time date)
 	  (when (file-exists-p file)
-	    (org-publish-cache-ctime-of-src file)))))))
+	    (nth 5 (file-attributes file))))))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Interactive publishing functions

[-- Attachment #3: Type: text/plain, Size: 19 bytes --]


-- 
Manuel Giraud

[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch 2/2] org-publish
  2010-12-01 10:11 [Patch 2/2] org-publish Manuel Giraud
@ 2011-02-08 17:04 ` Bastien
  2011-02-09 12:23   ` Manuel Giraud
  0 siblings, 1 reply; 5+ messages in thread
From: Bastien @ 2011-02-08 17:04 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: emacs-orgmode

Hi Manuel,

Manuel Giraud <manuel.giraud@univ-nantes.fr> writes:

> This second patch (that should be applied after the first one) adds a
> formating option to sitemap entries. One can now use a formated string
> to generate a sitemap entry. This formated string currently understands
> title (%T), author (%A) and date (%D).

I tested this patch and it produce weird results.

  (setq org-publish-sitemap-file-entry-format "%T")

Outputs ill-formed links instead of the title.

I'd welcome a reworked version of this idea!

Best,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch 2/2] org-publish
  2011-02-08 17:04 ` Bastien
@ 2011-02-09 12:23   ` Manuel Giraud
  2011-02-09 16:13     ` [Accepted] [Orgmode,2/2] org-publish Bastien Guerry
  2011-02-09 16:14     ` [Patch 2/2] org-publish Bastien
  0 siblings, 2 replies; 5+ messages in thread
From: Manuel Giraud @ 2011-02-09 12:23 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Bastien <bastien.guerry@wikimedia.fr> writes:

> I'd welcome a reworked version of this idea!

Hi Bastien,

Thanks for accepting my previous patch. Here's a new version of this last
patch that support formated sitemap entry.

--8<---------------cut here---------------start------------->8---
commit 660ece15eca316075da6529560bf66565934b713
Author: Manuel Giraud <manuel.giraud@univ-nantes.fr>
Date:   Tue Nov 23 16:20:15 2010 +0100

    formated sitemap

	Modified lisp/org-publish.el
diff --git a/lisp/org-publish.el b/lisp/org-publish.el
index 47b80db..98e09f3 100644
--- a/lisp/org-publish.el
+++ b/lisp/org-publish.el
@@ -267,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
 
@@ -370,6 +386,8 @@ This splices all the components into the list."
 (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 and files for sitemap."
   (let ((retval t))
@@ -392,8 +410,10 @@ This splices all the components into the list."
 				(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)))
+		 (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)))))))
@@ -701,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)
@@ -776,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
@@ -806,7 +850,9 @@ Default for SITEMAP-FILENAME is 'sitemap.org'."
 (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."
+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)))
@@ -815,10 +861,9 @@ system's modification time."
 	(unless visiting
 	  (kill-buffer (current-buffer)))
 	(if date
-	    (let ((dt (org-time-string-to-time date)))
-	      (+ (lsh (car dt) 16) (cadr dt)))
+	    (org-time-string-to-time date)
 	  (when (file-exists-p file)
-	    (org-publish-cache-ctime-of-src file)))))))
+	    (nth 5 (file-attributes file))))))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Interactive publishing functions
--8<---------------cut here---------------end--------------->8---

Best regards,
-- 
Manuel Giraud

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Accepted] [Orgmode,2/2] org-publish
  2011-02-09 12:23   ` Manuel Giraud
@ 2011-02-09 16:13     ` Bastien Guerry
  2011-02-09 16:14     ` [Patch 2/2] org-publish Bastien
  1 sibling, 0 replies; 5+ messages in thread
From: Bastien Guerry @ 2011-02-09 16:13 UTC (permalink / raw)
  To: emacs-orgmode

Patch 590 (http://patchwork.newartisans.com/patch/590/) is now "Accepted".

Maintainer comment: none

This relates to the following submission:

http://mid.gmane.org/%3C87bp2lcs6d.fsf%40univ-nantes.fr%3E

Here is the original message containing the patch:

> Content-Type: text/plain; charset="utf-8"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Subject: [Orgmode,2/2] org-publish
> Date: Wed, 09 Feb 2011 17:23:54 -0000
> From: Manuel Giraud <manuel.giraud@univ-nantes.fr>
> X-Patchwork-Id: 590
> Message-Id: <87bp2lcs6d.fsf@univ-nantes.fr>
> To: Bastien <bastien.guerry@wikimedia.fr>
> Cc: emacs-orgmode <emacs-orgmode@gnu.org>
> 
> Bastien <bastien.guerry@wikimedia.fr> writes:
> 
> > I'd welcome a reworked version of this idea!
> 
> Hi Bastien,
> 
> Thanks for accepting my previous patch. Here's a new version of this last
> patch that support formated sitemap entry.
> 
> --8<---------------cut here---------------start------------->8---
> commit 660ece15eca316075da6529560bf66565934b713
> Author: Manuel Giraud <manuel.giraud@univ-nantes.fr>
> Date:   Tue Nov 23 16:20:15 2010 +0100
> 
>     formated sitemap
> 
> 	Modified lisp/org-publish.el
> --8<---------------cut here---------------end--------------->8---
> 
> Best regards,
> 
> 
> diff --git a/lisp/org-publish.el b/lisp/org-publish.el
> index 47b80db..98e09f3 100644
> --- a/lisp/org-publish.el
> +++ b/lisp/org-publish.el
> @@ -267,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
>  
> @@ -370,6 +386,8 @@ This splices all the components into the list."
>  (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 and files for sitemap."
>    (let ((retval t))
> @@ -392,8 +410,10 @@ This splices all the components into the list."
>  				(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)))
> +		 (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)))))))
> @@ -701,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)
> @@ -776,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
> @@ -806,7 +850,9 @@ Default for SITEMAP-FILENAME is 'sitemap.org'."
>  (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."
> +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)))
> @@ -815,10 +861,9 @@ system's modification time."
>  	(unless visiting
>  	  (kill-buffer (current-buffer)))
>  	(if date
> -	    (let ((dt (org-time-string-to-time date)))
> -	      (+ (lsh (car dt) 16) (cadr dt)))
> +	    (org-time-string-to-time date)
>  	  (when (file-exists-p file)
> -	    (org-publish-cache-ctime-of-src file)))))))
> +	    (nth 5 (file-attributes file))))))))
>  
>  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>  ;;; Interactive publishing functions
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch 2/2] org-publish
  2011-02-09 12:23   ` Manuel Giraud
  2011-02-09 16:13     ` [Accepted] [Orgmode,2/2] org-publish Bastien Guerry
@ 2011-02-09 16:14     ` Bastien
  1 sibling, 0 replies; 5+ messages in thread
From: Bastien @ 2011-02-09 16:14 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: emacs-orgmode

Hi Manuel,

Manuel Giraud <manuel.giraud@univ-nantes.fr> writes:

> Thanks for accepting my previous patch. Here's a new version of this
> last patch that support formated sitemap entry.

Works fine, thanks.  Note for later: better to prepare patch submission
with git format-patch* so that I don't have to amend the commit message.

Thanks!

* http://www.kernel.org/pub/software/scm/git/docs/git-format-patch.html

-- 
 Bastien

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-02-09 16:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-01 10:11 [Patch 2/2] org-publish Manuel Giraud
2011-02-08 17:04 ` Bastien
2011-02-09 12:23   ` Manuel Giraud
2011-02-09 16:13     ` [Accepted] [Orgmode,2/2] org-publish Bastien Guerry
2011-02-09 16:14     ` [Patch 2/2] org-publish Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).