From 74db49b6f8d93289ce869d0a35d0d7c75f2ead3b Mon Sep 17 00:00:00 2001
From: noa@gaiwan.org
Date: Sun, 30 Jun 2024 19:12:34 +0000
Subject: Update website generation configuration
---
config.org | 222 ++++++++++++++++++++++---------------------------------------
1 file changed, 80 insertions(+), 142 deletions(-)
diff --git a/config.org b/config.org
index 7c1ed14..b02f4b6 100644
--- a/config.org
+++ b/config.org
@@ -684,148 +684,6 @@ This doesn't respect my timestamp custom format configured above.
(setopt valign-max-table-size 0)
#+end_src
-** Website generation
-
-#+begin_src elisp
-(defun read-file-as-string (filename)
- "Read file contents from FILENAME."
- (with-temp-buffer
- (insert-file-contents filename)
- (buffer-string)))
-#+end_src
-
-#+begin_src elisp
-(setq noa/website-header (read-file-as-string "/home/noa/projects/org-website/templates/header.html"))
-(setq noa/website-footer (read-file-as-string "/home/noa/projects/org-website/templates/footer.html"))
-#+end_src
-
-The index page generation functions were taken from Dennis Ogbe. Thank you!
-
-#+begin_src elisp
-(defun my-blog-parse-sitemap-list (l)
- "Convert the sitemap list in to a list of filenames."
- ;; LIST looks like:
- ;; (unordered ("[[file:uses.org][Things i use]]") ("[[file:media.org][Media Diary]]") ("[[file:tanklobsters.org][Tank lobsters]]"))
- (mapcar #'(lambda (i)
- (let ((link (with-temp-buffer
- (let ((org-inhibit-startup nil))
- (insert (car i))
- (org-mode)
- (goto-char (point-min))
- (org-element-link-parser)))))
- (when link
- (plist-get (cadr link) :path))))
- (cdr l)))
-#+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))))))
-#+end_src
-
-#+begin_src elisp
-(defun noa/naive-org-first-paragraph (file)
- "Naively returns the first paragraph of FILE.
-
- The way that the first paragraph is determined is to assume that there will be an org metadata block beforehand, so look for the first two consecutive newlines and mark the following paragraph."
- (with-temp-buffer
- (insert-file-contents file)
- (goto-char (point-min))
- (re-search-forward "\n\n")
- (mark-paragraph)
- (let ((beg (mark))
- (end (point)))
- (buffer-substring beg end))))
-#+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)))
-
- (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
- (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 "
+ urls ·
+ uses ·
+ now ·
+ media ·
+
+ ")
+#+end_src
+
+#+begin_src elisp
+ (setq org-publish-project-alist
+ `(("website"
+ :components ("website-pages" "website-assets" "website-feed"))
+ ("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 ;; breaks
tag + :html-head " + " + :auto-sitemap t + :sitemap-filename "/home/noa/data/share/archive.org" + :sitemap-title "Archive" + :sitemap-style list + :sitemap-sort-folders ignore + :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|\\ico" + :recursive t) + ("website-feed" + :base-directory "/home/noa/data/share" + :base-extension "org" + :publishing-directory "~/projects/org-website/" + :publishing-function (org-rss-publish-to-rss) + :html-link-home "https://noa.pub/" + :html-link-use-abs-url t + :exclude ".*" + :include ("index.org"))) + )) +#+end_src + +We also need to install a newer version of htmlize so that we can properly convert syntax highlighted code into html. I wish there was a way to turn this off, but i couldn't easily find it, so we're stuck with it for now. + +#+begin_src elisp + (package-ensure 'htmlize) +#+end_src + * Completing-read everywhere with consult Consult is a package to provide navigation commands that take advantage of completing-read. I set up a nice completing-read environment earlier with vertico. There are a lot of commands built in to consult, and it's possible to define more. But i use it very simply. -- cgit 1.4.1-2-gfad0