* [PATCH] Include missing files when sitemap style is tree
@ 2020-09-12 3:26 Anthony Carrico
2020-10-24 12:21 ` Bastien
0 siblings, 1 reply; 3+ messages in thread
From: Anthony Carrico @ 2020-09-12 3:26 UTC (permalink / raw)
To: emacs-orgmode
* ox-publish.el (org-publish-sitemap): Include files that have an
ancestor below base-directory with no published files and sitemap style
is tree.
This entire patch is released to the public domain by its author,
Anthony Carrico. TINYCHANGE
---
lisp/ox-publish.el | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el
index 7bb2fed6e..314b48ffc 100644
--- a/lisp/ox-publish.el
+++ b/lisp/ox-publish.el
@@ -747,6 +747,20 @@ return a string. Return value is a list as returned by
(funcall subtree-to-list root)))
(_ (user-error "Unknown site-map style: `%s'" style)))))
+(defun org-publish-dir-name-parent (dir-name)
+ (file-name-as-directory (expand-file-name (concat dir-name ".."))))
+
+(defun org-publish-dir-name-and-parents (dir-name root-dir-name)
+ (pcase dir-name
+ ("" nil)
+ ((or "./" "/" (pred (string= root-dir-name))) (list dir-name))
+ (_ (cons dir-name (org-publish-dir-name-and-parents
+ (org-publish-dir-name-parent dir-name) root-dir-name)))))
+
+(defun org-publish-file-name-parents (file root)
+ (org-publish-dir-name-and-parents (file-name-directory file)
+ (file-name-as-directory root)))
+
(defun org-publish-sitemap (project &optional sitemap-filename)
"Create a sitemap of pages in set defined by PROJECT.
Optionally set the filename of the sitemap with SITEMAP-FILENAME.
@@ -819,8 +833,11 @@ Default for SITEMAP-FILENAME is `sitemap.org'."
;; Add directories, if applicable.
(unless (and (eq style 'list) (eq sort-folders 'ignore))
(setq files
- (nconc (remove root (org-uniquify
- (mapcar #'file-name-directory files)))
+ (nconc (remove
+ root
+ (org-uniquify
+ (mapcan (lambda (f) (org-publish-file-name-parents f root))
+ files)))
files)))
;; Eventually sort all entries.
(when (or sort-files (not (memq sort-folders 'ignore)))
--
2.25.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Include missing files when sitemap style is tree
2020-09-12 3:26 [PATCH] Include missing files when sitemap style is tree Anthony Carrico
@ 2020-10-24 12:21 ` Bastien
2020-10-27 0:38 ` Anthony Carrico
0 siblings, 1 reply; 3+ messages in thread
From: Bastien @ 2020-10-24 12:21 UTC (permalink / raw)
To: Anthony Carrico; +Cc: emacs-orgmode
Hi Anthony,
Anthony Carrico <acarrico@memebeam.org> writes:
> * ox-publish.el (org-publish-sitemap): Include files that have an
> ancestor below base-directory with no published files and sitemap style
> is tree.
thanks for the patch and sorry for the delay in replying. I'm not
sure I understand the bug it fixes: can you briefly describe it or
provide a reproducible recipe?
> +(defun org-publish-dir-name-parent (dir-name)
> + (file-name-as-directory (expand-file-name (concat dir-name ".."))))
> +
> +(defun org-publish-dir-name-and-parents (dir-name root-dir-name)
> + (pcase dir-name
> + ("" nil)
> + ((or "./" "/" (pred (string= root-dir-name))) (list dir-name))
> + (_ (cons dir-name (org-publish-dir-name-and-parents
> + (org-publish-dir-name-parent dir-name) root-dir-name)))))
> +
> +(defun org-publish-file-name-parents (file root)
> + (org-publish-dir-name-and-parents (file-name-directory file)
> + (file-name-as-directory root)))
> +
You would need to add docstrings for each of the new functions.
Thanks,
--
Bastien
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Include missing files when sitemap style is tree
2020-10-24 12:21 ` Bastien
@ 2020-10-27 0:38 ` Anthony Carrico
0 siblings, 0 replies; 3+ messages in thread
From: Anthony Carrico @ 2020-10-27 0:38 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode
On 10/24/20 8:21 AM, Bastien wrote:
> Anthony Carrico <acarrico@memebeam.org> writes:
>
>> * ox-publish.el (org-publish-sitemap): Include files that have an
>> ancestor below base-directory with no published files and sitemap style
>> is tree.
>
> thanks for the patch and sorry for the delay in replying. I'm not
> sure I understand the bug it fixes: can you briefly describe it or
> provide a reproducible recipe?
#!/run/current-system/sw/bin/emacs --script
(require 'org)
(require 'ox-publish)
;;; create a source directory tree:
(make-directory "test-export/src/level1/level2/level3" t)
;;; create two source files, with an empty directory between:
(with-temp-file "test-export/src/level1/one.org"
(insert "#+TITLE one"))
(with-temp-file "test-export/src/level1/level2/level3/three.org"
(insert "#+TITLE three"))
;;; create a destination directory trees:
(make-directory "test-export/dest" t)
;;; publish the test-export:
(setq org-publish-project-alist
`(("test-export"
:base-directory "test-export/src"
:publishing-directory "test-export/dest"
:publishing-function org-html-publish-to-html
:sitemap-filename "index.org"
:sitemap-title "test-export"
:sitemap-style tree
:auto-sitemap t
:recursive t)))
;; ISSUE: Even with the force argument, org-publish still seems to
generate a cache in ~/.org-timestamps which creates a sitemap with old
titles and breaks reproducible builds. To avoid this problem delete the
cache when publishing:
(defun org-publish-delete-cache-file (project-name)
(let* ((cache-file
(concat
(expand-file-name org-publish-timestamp-directory)
project-name ".cache"))
(cexists (file-exists-p cache-file)))
(when (file-exists-p cache-file)
(delete-file cache-file))))
(org-publish-delete-cache-file "test-export")
(org-publish "test-export" t)
(org-publish-delete-cache-file "test-export")
;; Now run:
;;
;; $ firefox test-export/dest/index.html
;;
;; You should see something like this:
;;
;;
;; test-export
;;
;; level1
;; one
;;
;; Now run again with my patch, and you will see something like this:
;;
;; test-export
;;
;; level1
;; one
;; level2
;; level3
;; three
;;
;; As you can see, without the patch, "three" is missing from the index.
>> +(defun org-publish-dir-name-parent (dir-name)
>> + (file-name-as-directory (expand-file-name (concat dir-name ".."))))
>> +
>> +(defun org-publish-dir-name-and-parents (dir-name root-dir-name)
>> + (pcase dir-name
>> + ("" nil)
>> + ((or "./" "/" (pred (string= root-dir-name))) (list dir-name))
>> + (_ (cons dir-name (org-publish-dir-name-and-parents
>> + (org-publish-dir-name-parent dir-name) root-dir-name)))))
>> +
>> +(defun org-publish-file-name-parents (file root)
>> + (org-publish-dir-name-and-parents (file-name-directory file)
>> + (file-name-as-directory root)))
>> +
>
> You would need to add docstrings for each of the new functions.
I've run out of time today. These /seem/ like they should be standard
procedures in elisp, not something in org-publish, but I couldn't find
them in the manual. I'm not very experienced with elisp though.
I've run out of time today. Tell me if you have trouble with the test
case. Thank you Bastien.
--
Anthony Carrico
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-27 0:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-12 3:26 [PATCH] Include missing files when sitemap style is tree Anthony Carrico
2020-10-24 12:21 ` Bastien
2020-10-27 0:38 ` Anthony Carrico
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).