From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thibault Marin Subject: Use headings in sitemap Date: Wed, 28 Sep 2016 23:09:11 -0500 Message-ID: <87fuojl53s.fsf@dell-desktop.WORKGROUP> Reply-To: thibault.marin@gmx.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpSev-0000AZ-Jo for emacs-orgmode@gnu.org; Thu, 29 Sep 2016 00:09:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpSeq-0002n1-D7 for emacs-orgmode@gnu.org; Thu, 29 Sep 2016 00:09:20 -0400 Received: from mout.gmx.net ([212.227.17.22]:63478) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpSeq-0002me-2Q for emacs-orgmode@gnu.org; Thu, 29 Sep 2016 00:09:16 -0400 Received: from dell-desktop ([99.47.196.62]) by mail.gmx.com (mrgmx102) with ESMTPSA (Nemesis) id 0MFi1J-1bkFzQ28bl-00EZwr for ; Thu, 29 Sep 2016 06:09:13 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: org mode --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi list, I would like to generate a sitemap for a published website and use it to = extract the last few entries in a specific folder to put on the main page. The site structure looks like: . =E2=94=9C=E2=94=80=E2=94=80 index.org =E2=94=9C=E2=94=80=E2=94=80 posts =E2=94=82 =E2=94=9C=E2=94=80=E2=94=80 A.org =E2=94=82 =E2=94=9C=E2=94=80=E2=94=80 B.org =E2=94=82 =E2=94=94=E2=94=80=E2=94=80 C.org =E2=94=9C=E2=94=80=E2=94=80 misc =E2=94=82 =E2=94=9C=E2=94=80=E2=94=80 page.org =E2=94=82 =E2=94=94=E2=94=80=E2=94=80 other-page.org =E2=94=94=E2=94=80=E2=94=80 sitemap.org In index.org, I would have: #+begin_src org #+INCLUDE: sitemap.org::*posts :lines "-10" :only-contents t #+end_src to include links to the 10 most recent pages in =3Dposts=3D (I use :sitemap-sort-files anti-chronologically in the project setup). If I am = not missing anything, this requires the sitemap.org file to have a =3Dposts=3D= heading, but the `org-publish-org-sitemap' function only produces a list of pages. If there is no better way to get this to work, I would like to propose a = patch to `org-publish-org-sitemap' to produce headings in the sitemap file when= a new parameter is passed and non-nil. The attached patch is my first attempt = at it, it works for my tests. I would be interested to hear people's opinion on this: - Is there a better way to achieve what I want? - Is the proposed patch acceptable? Any comments would be appreciated. Thanks in advance. thibault --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-ox-publish.el-Option-to-use-headings-instead-of-list.patch >From a9ae0ecc623d2794475f3481765c637447f1ab24 Mon Sep 17 00:00:00 2001 From: thibault Date: Wed, 28 Sep 2016 22:47:48 -0500 Subject: [PATCH] ox-publish.el: Option to use headings instead of list in sitemap * list/ox-publish.el (org-publish-org-sitemap): Add an optional parameter allowing generation of a sitemap composed of headings instead of list items. --- lisp/ox-publish.el | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el index 14c93b2..ceb0673 100644 --- a/lisp/ox-publish.el +++ b/lisp/ox-publish.el @@ -716,15 +716,17 @@ If `:auto-sitemap' is set, publish the sitemap too. If ((functionp fun) (funcall fun project-plist)))) (org-publish-write-cache-file)))) -(defun org-publish-org-sitemap (project &optional sitemap-filename) +(defun org-publish-org-sitemap + (project &optional sitemap-filename use-headings) "Create a sitemap of pages in set defined by PROJECT. Optionally set the filename of the sitemap with SITEMAP-FILENAME. -Default for SITEMAP-FILENAME is `sitemap.org'." +Default for SITEMAP-FILENAME is `sitemap.org'. When USE-HEADINGS +is nil (default), the sitemap produced is a list, otherwise it +uses headings." (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 (nreverse (org-publish-get-base-files project exclude-regexp))) @@ -736,7 +738,18 @@ Default for SITEMAP-FILENAME is `sitemap.org'." (sitemap-sans-extension (plist-get project-plist :sitemap-sans-extension)) (visiting (find-buffer-visiting sitemap-filename)) - file sitemap-buffer) + file sitemap-buffer + (entry-string + (if use-headings + `((indent . ,(make-string 1 ?*)) + (char-space . " ")) + `((indent . ,(make-string 2 ?\ )) + (char-space . " + ")))) + (entry-string-indent (cdr (assq 'indent entry-string))) + (entry-string-char (string-to-char + (substring entry-string-indent 0 1))) + (entry-string-indent-char (cdr (assq 'char-space entry-string))) + (indent-str entry-string-indent)) (with-current-buffer (let ((org-inhibit-startup t)) (setq sitemap-buffer @@ -758,7 +771,7 @@ Default for SITEMAP-FILENAME is `sitemap.org'." (file-name-directory link))) (unless (string= localdir oldlocal) (if (string= localdir dir) - (setq indent-str (make-string 2 ?\ )) + (setq indent-str entry-string-indent) (let ((subdirs (split-string (directory-file-name @@ -767,16 +780,18 @@ Default for SITEMAP-FILENAME is `sitemap.org'." (subdir "") (old-subdirs (split-string (file-relative-name oldlocal dir) "/"))) - (setq indent-str (make-string 2 ?\ )) + (setq indent-str entry-string-indent) (while (string= (car old-subdirs) (car subdirs)) - (setq indent-str (concat indent-str (make-string 2 ?\ ))) + (setq indent-str (concat indent-str entry-string-indent)) (pop old-subdirs) (pop subdirs)) (dolist (d subdirs) (setq subdir (concat subdir d "/")) - (insert (concat indent-str " + " d "\n")) + (insert (concat indent-str entry-string-indent-char d "\n")) (setq indent-str (make-string - (+ (length indent-str) 2) ?\ ))))))) + (+ (length indent-str) + (length entry-string-indent)) + entry-string-char))))))) ;; This is common to 'flat and 'tree (let ((entry (org-publish-format-file-entry @@ -784,12 +799,14 @@ Default for SITEMAP-FILENAME is `sitemap.org'." (regexp "\\(.*\\)\\[\\([^][]+\\)\\]\\(.*\\)")) (cond ((string-match-p regexp entry) (string-match regexp entry) - (insert (concat indent-str " + " (match-string 1 entry) + (insert (concat indent-str entry-string-indent-char + (match-string 1 entry) "[[file:" link "][" (match-string 2 entry) "]]" (match-string 3 entry) "\n"))) (t - (insert (concat indent-str " + [[file:" link "][" + (insert (concat indent-str entry-string-indent-char + "[[file:" link "][" entry "]]\n")))))))) (save-buffer)) -- 2.9.3 --=-=-=--