392 lines
16 KiB
EmacsLisp
392 lines
16 KiB
EmacsLisp
(defun z/posts-sitemap (title list)
|
|
"sitemap that lists post links as bullet points with dates and tags."
|
|
(concat
|
|
"#+TITLE: " title "\n"
|
|
"#+OPTIONS: toc:nil num:nil \n\n"
|
|
"See the categories: @@html:<a href=\"../categories.html\">Categories</a>@@\n\n"
|
|
"* Posts:\n"
|
|
(mapconcat
|
|
(lambda (entry)
|
|
(let* ((link (car entry))
|
|
;; extract relative file name from the link
|
|
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
|
|
(match-string 1 link)
|
|
link))
|
|
(full-path (expand-file-name filename "~/master-folder/org_files/org_web/posts/"))
|
|
(date-str "no date")
|
|
(tags-str ""))
|
|
;; Get publish date
|
|
(let ((date (org-publish-find-date full-path org-publish-project-alist)))
|
|
(when date
|
|
(setq date-str (format-time-string "%d-%m-%Y %H:%M" date))))
|
|
;; Get FILETAGS from file buffer
|
|
(when (file-exists-p full-path)
|
|
(with-temp-buffer
|
|
(insert-file-contents full-path)
|
|
(org-mode)
|
|
(let* ((tags (cadr (assoc "FILETAGS" (org-collect-keywords '("FILETAGS"))))))
|
|
(when tags
|
|
(setq tags-str (mapconcat (lambda (tag)
|
|
(format "@@html:<a href=\"/tags/%s.html\"> <span class=\"post-tag\">%s</span> </a>@@" tag tag))
|
|
(split-string tags ":" t) ;; <- Splits by ":" and removes empty strings
|
|
" "))))))
|
|
;; Final line output
|
|
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s" link date-str tags-str)))
|
|
(cdr list)
|
|
"\n")))
|
|
|
|
|
|
(defun z/blogs-sitemap (title list)
|
|
"sitemap that lists blog links as bullet points with dates and tags."
|
|
(concat
|
|
"#+TITLE: " title "\n"
|
|
"#+OPTIONS: toc:nil num:nil \n\n"
|
|
"See the categories: @@html:<a href=\"../categories.html\">Categories</a>@@\n\n"
|
|
"* Blogs:\n"
|
|
(mapconcat
|
|
(lambda (entry)
|
|
(let* ((link (car entry))
|
|
;; extract relative file name from the link
|
|
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
|
|
(match-string 1 link)
|
|
link))
|
|
(full-path (expand-file-name filename "~/master-folder/org_files/org_web/blogs/"))
|
|
(date-str "no date")
|
|
(tags-str ""))
|
|
;; Get publish date
|
|
(let ((date (org-publish-find-date full-path org-publish-project-alist)))
|
|
(when date
|
|
(setq date-str (format-time-string "%d-%m-%Y %H:%M" date))))
|
|
;; Get FILETAGS from file buffer
|
|
(when (file-exists-p full-path)
|
|
(with-temp-buffer
|
|
(insert-file-contents full-path)
|
|
(org-mode)
|
|
(let* ((tags (cadr (assoc "FILETAGS" (org-collect-keywords '("FILETAGS"))))))
|
|
(when tags
|
|
(setq tags-str (mapconcat (lambda (tag)
|
|
(format "@@html:<a href=\"/tags/%s.html\"> <span class=\"post-tag\">%s</span> </a>@@" tag tag))
|
|
(split-string tags ":" t) ;; <- Splits by ":" and removes empty strings
|
|
" "))))))
|
|
;; Final line output
|
|
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s" link date-str tags-str)))
|
|
(cdr list)
|
|
"\n")))
|
|
|
|
|
|
(defun z/books-sitemap (title list)
|
|
"sitemap that lists books."
|
|
(concat
|
|
"#+TITLE: " title "\n"
|
|
"#+OPTIONS: toc:nil num:nil \n\n"
|
|
"See the categories: @@html:<a href=\"../categories.html\">Categories</a>@@\n\n"
|
|
"* Book Notes:\n"
|
|
(mapconcat
|
|
(lambda (entry)
|
|
(let* ((link (car entry))
|
|
;; extract relative file name from the link
|
|
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
|
|
(match-string 1 link)
|
|
link))
|
|
(full-path (expand-file-name filename "~/master-folder/org_files/org_web/books/"))
|
|
(date-str "no date")
|
|
(tags-str ""))
|
|
;; Get publish date
|
|
(let ((date (org-publish-find-date full-path org-publish-project-alist)))
|
|
(when date
|
|
(setq date-str (format-time-string "%d-%m-%Y %H:%M" date))))
|
|
;; Get FILETAGS from file buffer
|
|
(when (file-exists-p full-path)
|
|
(with-temp-buffer
|
|
(insert-file-contents full-path)
|
|
(org-mode)
|
|
(let* ((tags (cadr (assoc "FILETAGS" (org-collect-keywords '("FILETAGS"))))))
|
|
(when tags
|
|
(setq tags-str (mapconcat (lambda (tag)
|
|
(format "@@html:<a href=\"/tags/%s.html\"> <span class=\"post-tag\">%s</span> </a>@@" tag tag))
|
|
(split-string tags ":" t) ;; <- Splits by ":" and removes empty strings
|
|
" "))))))
|
|
;; Final line output
|
|
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s" link date-str tags-str)))
|
|
(cdr list)
|
|
"\n")))
|
|
|
|
(defun z/2025-sitemap (title list)
|
|
"Sitemap that lists 2025 posts grouped by month, with dates and FILETAGS."
|
|
(let ((output (concat
|
|
"#+TITLE: " title "\n"
|
|
"#+OPTIONS: toc:nil num:nil \n\n"
|
|
"See the categories: @@html:<a href=\"../../categories.html\">Categories</a>@@\n\n"
|
|
"* 2025\n"))
|
|
(current-month nil))
|
|
|
|
;; `list` is what org-publish passes in; we skip its car (top-level title node)
|
|
(dolist (entry (cdr list))
|
|
;; In this setup each ENTRY is usually (LINK . OTHER-STUFF)
|
|
(when (consp entry)
|
|
(let* ((link (car entry))
|
|
;; Extract relative filename from the [[file:...][...]] link
|
|
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
|
|
(match-string 1 link)
|
|
link))
|
|
(full-path (expand-file-name
|
|
filename
|
|
"~/master-folder/org_files/org_web/blogs/2025/"))
|
|
(date (when (file-exists-p full-path)
|
|
(org-publish-find-date full-path org-publish-project-alist)))
|
|
(date-str (if date
|
|
(format-time-string "%d-%m-%Y %H:%M" date)
|
|
"no date"))
|
|
(month-str (if date
|
|
(format-time-string "%B %Y" date) ; e.g. "August 2025"
|
|
"No date"))
|
|
(tags-str ""))
|
|
|
|
;; Collect FILETAGS from the file
|
|
(when (file-exists-p full-path)
|
|
(with-temp-buffer
|
|
(insert-file-contents full-path)
|
|
(org-mode)
|
|
(let ((tags (cadr (assoc "FILETAGS"
|
|
(org-collect-keywords '("FILETAGS"))))))
|
|
(when tags
|
|
(setq tags-str
|
|
(mapconcat
|
|
(lambda (tag)
|
|
(format "@@html:<a href=\"/tags/%s.html\"> \
|
|
<span class=\"post-tag\">%s</span> </a>@@" tag tag))
|
|
(split-string tags ":" t)
|
|
" "))))))
|
|
|
|
;; Insert month heading whenever month changes
|
|
(unless (equal month-str current-month)
|
|
(setq current-month month-str)
|
|
(setq output (concat output "\n** " month-str "\n")))
|
|
|
|
;; Insert the actual entry
|
|
(setq output
|
|
(concat output
|
|
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s\n"
|
|
link date-str tags-str))))))
|
|
|
|
output))
|
|
|
|
(defun z/2026-sitemap (title list)
|
|
"Sitemap that lists 2026 blogs grouped by month, with dates and FILETAGS."
|
|
(let ((output (concat
|
|
"#+TITLE: " title "\n"
|
|
"#+OPTIONS: toc:nil num:nil \n\n"
|
|
"See the categories: @@html:<a href=\"../../categories.html\">Categories</a>@@\n\n"
|
|
"* 2026\n"))
|
|
(current-month nil))
|
|
|
|
(dolist (entry (cdr list))
|
|
(when (consp entry)
|
|
(let* ((link (car entry))
|
|
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
|
|
(match-string 1 link)
|
|
link))
|
|
(full-path (expand-file-name
|
|
filename
|
|
"~/master-folder/org_files/org_web/blogs/2026/"))
|
|
(date (when (file-exists-p full-path)
|
|
(org-publish-find-date full-path org-publish-project-alist)))
|
|
(date-str (if date
|
|
(format-time-string "%d-%m-%Y %H:%M" date)
|
|
"no date"))
|
|
(month-str (if date
|
|
(format-time-string "%B %Y" date)
|
|
"No date"))
|
|
(tags-str ""))
|
|
|
|
(when (file-exists-p full-path)
|
|
(with-temp-buffer
|
|
(insert-file-contents full-path)
|
|
(org-mode)
|
|
(let ((tags (cadr (assoc "FILETAGS"
|
|
(org-collect-keywords '("FILETAGS"))))))
|
|
(when tags
|
|
(setq tags-str
|
|
(mapconcat
|
|
(lambda (tag)
|
|
(format "@@html:<a href=\"/tags/%s.html\"> \
|
|
<span class=\"post-tag\">%s</span> </a>@@" tag tag))
|
|
(split-string tags ":" t)
|
|
" "))))))
|
|
|
|
(unless (equal month-str current-month)
|
|
(setq current-month month-str)
|
|
(setq output (concat output "\n** " month-str "\n")))
|
|
|
|
(setq output
|
|
(concat output
|
|
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s\n"
|
|
link date-str tags-str))))))
|
|
|
|
output))
|
|
|
|
|
|
|
|
(defun z/career-sitemap (title list)
|
|
"Sitemap that lists careers posts grouped by month, with dates and FILETAGS."
|
|
(let ((output (concat
|
|
"#+TITLE: " title "\n"
|
|
"#+OPTIONS: toc:nil num:nil \n\n"
|
|
"See the categories: @@html:<a href=\"../../categories.html\">Categories</a>@@\n\n"
|
|
"* 2025\n"
|
|
"See the following page for more details: @@html:<a href=\"./career-intro.html\">Career Intro</a>@@\n"
|
|
))
|
|
(current-month nil))
|
|
|
|
(dolist (entry (cdr list))
|
|
(when (consp entry)
|
|
(let* ((link (car entry))
|
|
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
|
|
(match-string 1 link)
|
|
link))
|
|
(full-path (expand-file-name
|
|
filename
|
|
"~/master-folder/org_files/org_web/posts/career/"))
|
|
(date (when (file-exists-p full-path)
|
|
(org-publish-find-date full-path org-publish-project-alist)))
|
|
(date-str (if date
|
|
(format-time-string "%d-%m-%Y %H:%M" date)
|
|
"no date"))
|
|
(month-str (if date
|
|
(format-time-string "%B %Y" date) ; e.g. "August 2025"
|
|
"No date"))
|
|
(tags-str ""))
|
|
|
|
(when (file-exists-p full-path)
|
|
(with-temp-buffer
|
|
(insert-file-contents full-path)
|
|
(org-mode)
|
|
(let ((tags (cadr (assoc "FILETAGS"
|
|
(org-collect-keywords '("FILETAGS"))))))
|
|
(when tags
|
|
(setq tags-str
|
|
(mapconcat
|
|
(lambda (tag)
|
|
(format "@@html:<a href=\"/tags/%s.html\"> \
|
|
<span class=\"post-tag\">%s</span> </a>@@" tag tag))
|
|
(split-string tags ":" t)
|
|
" "))))))
|
|
|
|
;; Insert month heading whenever month changes
|
|
(unless (equal month-str current-month)
|
|
(setq current-month month-str)
|
|
(setq output (concat output "\n** " month-str "\n")))
|
|
|
|
(setq output
|
|
(concat output
|
|
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s\n"
|
|
link date-str tags-str))))))
|
|
|
|
output))
|
|
|
|
|
|
|
|
(defun z/categories-sitemap (title _list)
|
|
"Generate a categories page by scanning tags across org-posts and org-blogs."
|
|
(let* ((expanded (org-publish-expand-projects org-publish-project-alist))
|
|
(posts (assoc "org-posts" expanded))
|
|
(blogs (assoc "org-blogs" expanded))
|
|
;; DO NOT set :exclude to "" — it excludes everything
|
|
(files (cl-remove-duplicates
|
|
(append (and posts (org-publish-get-base-files posts))
|
|
(and blogs (org-publish-get-base-files blogs)))
|
|
:test #'file-equal-p))
|
|
;; optional: drop the generated sitemaps
|
|
(files (cl-remove-if
|
|
(lambda (f)
|
|
(member (file-name-nondirectory f)
|
|
'("posts-list.org" "blogs-list.org" "sitemap.org" "categories.org")))
|
|
files))
|
|
(counts (make-hash-table :test 'equal)))
|
|
;;(message "files I will scan: %S" files)
|
|
(dolist (f files)
|
|
(when (file-readable-p f)
|
|
(with-temp-buffer
|
|
(insert-file-contents f)
|
|
(org-mode)
|
|
(let* ((kw (org-collect-keywords '("FILETAGS" "TAGS")))
|
|
(raw (car (or (cdr (assoc "FILETAGS" kw))
|
|
(cdr (assoc "TAGS" kw))))))
|
|
(when raw
|
|
(dolist (tag (split-string raw ":" t))
|
|
(puthash tag (1+ (gethash tag counts 0)) counts)))))))
|
|
|
|
(let (tags)
|
|
(maphash (lambda (k _) (push k tags)) counts)
|
|
(setq tags (sort tags #'string-lessp))
|
|
(concat
|
|
"#+TITLE: " title "\n#+OPTIONS: toc:nil num:nil title:nil\n\n* Categories (Includes both blogs and posts)\n"
|
|
(if tags
|
|
(mapconcat
|
|
(lambda (tag)
|
|
(format "- [[file:tags/%s.org][@@html:<span class=\"post-tag\">%s</span>@@]] (%d)"
|
|
(z/tag-slug tag) tag (gethash tag counts))
|
|
)
|
|
tags
|
|
"\n")
|
|
"_No tags found yet._")))))
|
|
|
|
(defun z/wip-file-p (file)
|
|
"Return non-nil if FILE should be treated as WIP.
|
|
A file is WIP if:
|
|
- It has a #+WIP: keyword with any non-empty value, or
|
|
- Its FILETAGS contain :WIP:, or
|
|
- Any top-level heading contains the string \"WIP\" (case-insensitive)."
|
|
(when (file-exists-p file)
|
|
(with-temp-buffer
|
|
(insert-file-contents file)
|
|
(org-mode)
|
|
(let* ((case-fold-search t)
|
|
(keywords (org-collect-keywords '("WIP" "FILETAGS")))
|
|
(wip (cadr (assoc "WIP" keywords)))
|
|
(filetags (cadr (assoc "FILETAGS" keywords))))
|
|
(or
|
|
(and wip (string-match-p "\\S-" wip))
|
|
(and filetags
|
|
(string-match-p ":WIP:" (concat ":" filetags ":")))
|
|
(save-excursion
|
|
(goto-char (point-min))
|
|
(re-search-forward "^\\*+ .*WIP.*" nil t)))))))
|
|
|
|
|
|
(defun z/wip-sitemap (title list)
|
|
"Sitemap that lists only entries whose source files are WIP."
|
|
(let* ((root-dir "~/master-folder/org_files/org_web/") ;; adjust if needed
|
|
(items
|
|
(delq
|
|
nil
|
|
(mapcar
|
|
(lambda (entry)
|
|
(when (consp entry)
|
|
(let* ((link (car entry))
|
|
;; Extract relative filename from [[file:...]] link if present
|
|
(filename (if (string-match "\\[\\[file:\\([^]]+\\)\\]" link)
|
|
(match-string 1 link)
|
|
link))
|
|
(full-path (expand-file-name filename root-dir)))
|
|
(when (z/wip-file-p full-path)
|
|
(let* ((date (org-publish-find-date full-path org-publish-project-alist))
|
|
(date-str (if date
|
|
(format-time-string "%d-%m-%Y %H:%M" date)
|
|
"")))
|
|
(format "- %s @@html:<span class=\"post-date\">%s</span>@@"
|
|
link date-str))))))
|
|
(cdr list))))) ; skip sitemap root
|
|
(concat
|
|
"#+TITLE: " title "\n"
|
|
"#+OPTIONS: toc:nil num:nil\n\n"
|
|
"* Work in progress\n"
|
|
(if items
|
|
(mapconcat #'identity items "\n")
|
|
"No items currently marked as WIP.\n"))))
|
|
|
|
|
|
|
|
|
|
(provide 'sitemaps)
|