From 6e368141cbc2ecf1c450eae89a821ce7a864ccca Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sun, 23 Feb 2020 20:23:42 -0800 Subject: Dynamically generate the index file --- project-config.el | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'project-config.el') diff --git a/project-config.el b/project-config.el index 4a9447b..944313e 100644 --- a/project-config.el +++ b/project-config.el @@ -10,7 +10,10 @@ :exclude "\\`README.org\\'" :base-extension "org" :publishing-function org-html-publish-to-html - :html-head "") + :html-head "" + :html-link-home "https://ryuslash.gitlab.io/ryuslash.org/" + :html-link-user-abs-url t + :recursive t) ("ryuslash-rss" :base-directory "." :publishing-directory "public_html" @@ -20,4 +23,40 @@ :publishing-function org-rss-publish-to-rss))) (defun publish-ryuslash.org () + (with-current-buffer (find-file "index.org") + (org-update-all-dblocks) + (save-buffer)) (org-publish-all)) + +(defun project-config-parse-element (org-element) + (pcase org-element + (`(keyword ,something) (cons (plist-get something :key) + (plist-get something :value))) + (`(paragraph ,something) (cons + "BODY" + (buffer-substring-no-properties + (plist-get something :contents-begin) + (plist-get something :contents-end)))))) + +(defun project-config-parse-document (document) + (with-current-buffer (find-file document) + (goto-char (point-min)) + (let (alist) + (while (not (alist-get "BODY" alist nil nil #'equal)) + (setq alist (cons (project-config-parse-element (org-element-at-point)) + alist)) + (org-forward-element)) + alist))) + +(defun project-config-print-element (filename alist) + (format "* %s\n :PROPERTIES:\n :ID: %s\n :PUBDATE: %s\n :END:\n\n %s\n[[file:%s][Read more]]\n" + (alist-get "TITLE" alist nil nil #'equal) + (alist-get "ID" alist nil nil #'equal) + (alist-get "PUBDATE" alist nil nil #'equal) + (alist-get "BODY" alist nil nil #'equal) + filename)) + +(defun org-dblock-write:blog-posts (params) + (let ((files (cl-remove-if (lambda (item) (string-prefix-p "." item)) (directory-files "posts")))) + (insert (format "%s" (apply #'concat (mapcar (lambda (file) (project-config-print-element (concat "posts/" file) (project-config-parse-document (concat "posts/" file)))) + files)))))) -- cgit v1.2.3-54-g00ecf