summary refs log tree commit diff
diff options
context:
space:
mode:
authornoa@gaiwan.org2024-06-29 09:33:21 +0000
committernoa@gaiwan.org2024-06-29 09:33:21 +0000
commit89d495cdf20d8ec9720b8f74991fa6260bd8d1be (patch)
tree58c7b660f2e2b3d63d121cfb773dd5b48df0b8c6
parentcd5d618884a710705b5ab5c8191154605b58d4f9 (diff)
Updates to org-publish sitemap generation
-rw-r--r--config.org152
1 files changed, 83 insertions, 69 deletions
diff --git a/config.org b/config.org
index 3b04711..45ed395 100644
--- a/config.org
+++ b/config.org
@@ -721,12 +721,12 @@ The index page generation functions were taken from Dennis Ogbe.  Thank you!
 #+end_src
 
 #+begin_src elisp
-(defun my-blog-sort-article-list (l p)
-  "sort the article list anti-chronologically."
-  (sort l #'(lambda (a b)
-              (let ((date-a (org-publish-find-date a p))
-                    (date-b (org-publish-find-date b p)))
-                (not (time-less-p date-a date-b))))))
+  (defun my-blog-sort-article-list (l p)
+    "sort the article list anti-chronologically."
+    (sort l #'(lambda (a b)
+                (let ((date-a (org-publish-find-date a p))
+                      (date-b (org-publish-find-date b p)))
+                  (not (time-less-p date-a date-b))))))
 #+end_src
 
 #+begin_src elisp
@@ -745,73 +745,87 @@ The index page generation functions were taken from Dennis Ogbe.  Thank you!
 #+end_src
 
 #+begin_src elisp
-(defun noa/website-sitemap (title list)
-  "Generate the index page for my website."
-  ;; LIST looks like:
-  ;; (unordered ("[[file:uses.org][Things i use]]") ("[[file:media.org][Media Diary]]") ("[[file:tanklobsters.org][Tank lobsters]]"))
-  (with-temp-buffer
-    ;; mangle the parsed list given to us into a plain lisp list of files
-    (let* ((filenames (my-blog-parse-sitemap-list list))
-           (project-plist (assoc "website-pages" org-publish-project-alist))
-           (articles (my-blog-sort-article-list filenames project-plist)))
-      (message (concat "PLIST: " (plist-get project-plist :base-directory)))
+  (defun noa/website-sitemap (title list)
+    "Generate the index page for my website."
+    ;; LIST looks like:
+    ;; (unordered ("[[file:uses.org][Things i use]]") ("[[file:media.org][Media Diary]]") ("[[file:tanklobsters.org][Tank lobsters]]"))
+    (with-temp-buffer
+      ;; mangle the parsed list given to us into a plain lisp list of files
+      (let* ((filenames (my-blog-parse-sitemap-list list))
+	     (project-plist (assoc "website-pages" org-publish-project-alist))
+	     (articles (my-blog-sort-article-list filenames project-plist)))
+	(message (concat "PLIST: " (plist-get project-plist :base-directory)))
       
-      (insert "Several parts of this website are broken as i wrangle with the monstrosity that is programming in emacs lisp.  The content should still be fine, but for further cosmetics please hold <3\n\n")
-      (dolist (file filenames)
-        (let* ((abspath (file-name-concat "/home/noa/data/share" file))
-               ;; (abspath (file-name-concat (plist-get project-plist :base-directory) file))
-               (relpath (file-relative-name abspath "/home/noa/data/share"))
-               (title (org-publish-find-title file project-plist))
-               (date (format-time-string (car org-time-stamp-formats) (org-publish-find-date file project-plist)))
-               (preview (noa/naive-org-first-paragraph abspath)))
-          (insert (concat "* [[file:" relpath "][" title "]]\n"))
-          (insert (concat
-		   "*" date ":*"
-		   preview))
-          (insert "\n")))
-      ;; insert a title and save
-      (insert "#+TITLE: noa.pub\n")
-      (buffer-string))))
+	(insert "Several parts of this website are broken as i wrangle with the monstrosity that is programming in emacs lisp.  The content should still be fine, but for further cosmetics please hold <3\n\n")
+	(dolist (file filenames)
+	  (let* ((abspath (file-name-concat "/home/noa/data/share" file))
+		 ;; (abspath (file-name-concat (plist-get project-plist :base-directory) file))
+		 (relpath (file-relative-name abspath "/home/noa/data/share"))
+		 (title (org-publish-find-title file project-plist))
+		 (date (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date file project-plist)))
+		 (preview (noa/naive-org-first-paragraph abspath)))
+	    (insert (concat "* [[file:" relpath "][" title "]]\n"))
+	    (insert (concat
+		     "*" date ":*"
+		     preview))
+	    (insert "\n")))
+	;; insert a title and save
+	(insert "#+TITLE: noa.pub\n")
+	(buffer-string))))
       #+end_src
 
 #+begin_src elisp
-(setq org-publish-project-alist
-      `(("website"
-         :components ("website-pages" "website-assets"))
-        ("website-pages"
-         :publishing-function org-html-publish-to-html
-         :base-directory "/home/noa/data/share"
-         :publishing-directory "/home/noa/projects/org-website"
-         :base-extension "org"
-         :with-drawers t
-         :html-link-home "/"
-         :html-head-include-default-style nil
-         :html-head-include-scripts nil
-         :html-doctype "html5"
-         ;; :html-validation-link nil
-         :html-preamble ""
-         :html-postamble ,noa/website-footer
-         :html-home/up-format ""
-         :html-link-up ""
-         :html-html5-fancy t
-         :html-indent nil
-         :html-head "<link rel=\"icon\" href=\"data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>𰻝</text></svg>\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"love.css\" />
-<meta name=\"color-scheme\" content=\"light dark\">"
-         :auto-sitemap t
-         :sitemap-filename "/home/noa/projects/org-website/index.org"
-         :sitemap-title "noa.pub"
-         :sitemap-style list
-         ;; :sitemap-format-entry
-         :sitemap-function noa/website-sitemap
-         :sitemap-sort-folders ignore
-         :sitemap-sort-files anti-chronologically
-         :sitemap-ignore-case t)
-        ("website-assets"
-         :publishing-function org-publish-attachment
-         :base-directory "/home/noa/data/share"
-         :publishing-directory "/home/noa/projects/org-website"
-         :base-extension "css\\|js\\|png|\\jpg"
-         :recursive t)))
+  (defun noa/org-publish-sitemap-entry (entry style project)
+    "Default format for site map ENTRY, as a string.
+  ENTRY is a file name.  STYLE is the style of the sitemap.
+  PROJECT is the current project."
+    (cond ((not (directory-name-p entry))
+	   (format "%s: [[file:%s][%s]]"
+		   (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date entry project))
+		   entry
+		   (org-publish-find-title entry project)))
+	  ((eq style 'tree)
+	   ;; Return only last subdir.
+	   (file-name-nondirectory (directory-file-name entry)))
+	  (t entry)))
+
+  (setq org-publish-project-alist
+	`(("website"
+	   :components ("website-pages" "website-assets"))
+	  ("website-pages"
+	   :publishing-function org-html-publish-to-html
+	   :base-directory "/home/noa/data/share"
+	   :publishing-directory "/home/noa/projects/org-website"
+	   :base-extension "org"
+	   :with-drawers t
+	   :html-link-home "/"
+	   :html-head-include-default-style nil
+	   :html-head-include-scripts nil
+	   :html-doctype "html5"
+	   ;; :html-validation-link nil
+	   :html-preamble ""
+	   :html-postamble ,noa/website-footer
+	   :html-home/up-format ""
+	   :html-link-up ""
+	   :html-html5-fancy t
+	   :html-indent nil
+	   :html-head "<link rel=\"icon\" href=\"data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>𰻝</text></svg>\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"love.css\" />
+  <meta name=\"color-scheme\" content=\"light dark\">"
+	   :auto-sitemap t
+	   :sitemap-filename "/home/noa/projects/org-website/index.org"
+	   :sitemap-title "noa.pub"
+	   :sitemap-style list
+	   :sitemap-format-entry noa/org-publish-sitemap-entry
+	   ;; :sitemap-function noa/website-sitemap
+	   :sitemap-sort-folders ignore
+	   :sitemap-sort-files anti-chronologically
+	   :sitemap-ignore-case t)
+	  ("website-assets"
+	   :publishing-function org-publish-attachment
+	   :base-directory "/home/noa/data/share"
+	   :publishing-directory "/home/noa/projects/org-website"
+	   :base-extension "css\\|js\\|png|\\jpg"
+	   :recursive t)))
 #+end_src
 
 ** Markdown