weekly updates
This commit is contained in:
@@ -81,6 +81,92 @@
|
||||
"\n")))
|
||||
|
||||
|
||||
|
||||
(defun z/blogs-grouped-sitemap (title list)
|
||||
"Sitemap grouped by year and month with dates and FILETAGS."
|
||||
(let ((data (make-hash-table :test 'equal)))
|
||||
|
||||
;; STEP 1: Collect entries into (year -> month -> entries)
|
||||
(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 (site-path "blogs/")))
|
||||
(date (when (file-exists-p full-path)
|
||||
(org-publish-find-date full-path org-publish-project-alist))))
|
||||
|
||||
(when date
|
||||
(let* ((year (format-time-string "%Y" date))
|
||||
(month (format-time-string "%B %Y" date))
|
||||
(date-str (format-time-string "%d-%m-%Y %H:%M" date))
|
||||
(tags-str ""))
|
||||
|
||||
;; Get tags
|
||||
(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 into hash table
|
||||
(let ((year-table (or (gethash year data)
|
||||
(puthash year (make-hash-table :test 'equal) data))))
|
||||
(let ((month-list (gethash month year-table)))
|
||||
(puthash month
|
||||
(cons (list link date-str tags-str date)
|
||||
month-list)
|
||||
year-table))))))))
|
||||
|
||||
;; STEP 2: Render output
|
||||
(let ((output (concat
|
||||
"#+TITLE: " title "\n"
|
||||
"#+OPTIONS: toc:nil num:nil \n\n"
|
||||
"See the categories: @@html:<a href=\"../home/categories.html\">Categories</a>@@\n\n")))
|
||||
|
||||
;; Sort years descending
|
||||
(dolist (year (sort (hash-table-keys data) #'string>))
|
||||
(setq output (concat output "* " year "\n"))
|
||||
|
||||
(let ((year-table (gethash year data)))
|
||||
|
||||
;; Sort months by actual date (descending)
|
||||
(dolist (month
|
||||
(sort (hash-table-keys year-table)
|
||||
(lambda (a b)
|
||||
(time-less-p
|
||||
(date-to-time (concat "01 " b))
|
||||
(date-to-time (concat "01 " a))))))
|
||||
|
||||
(setq output (concat output "\n** " month "\n"))
|
||||
|
||||
;; Sort entries by date descending
|
||||
(dolist (entry
|
||||
(sort (gethash month year-table)
|
||||
(lambda (a b)
|
||||
(time-less-p (nth 3 b) (nth 3 a)))))
|
||||
|
||||
(let ((link (nth 0 entry))
|
||||
(date-str (nth 1 entry))
|
||||
(tags-str (nth 2 entry)))
|
||||
|
||||
(setq output
|
||||
(concat output
|
||||
(format "- %s @@html:<span class=\"post-date\">%s</span>@@ %s\n"
|
||||
link date-str tags-str))))))))
|
||||
|
||||
output)))
|
||||
|
||||
(defun z/books-sitemap (title list)
|
||||
"sitemap that lists books."
|
||||
(concat
|
||||
|
||||
Reference in New Issue
Block a user