From 731a1f0551a15d6ba7e3ab0d0de46b3c164a44f6 Mon Sep 17 00:00:00 2001 From: Frederik Vanrenterghem Date: Sun, 17 Dec 2023 22:16:51 +0800 Subject: [PATCH] Voeg script toe dat tags kan verwerken. --- maak-website.el | 123 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 105 insertions(+), 18 deletions(-) diff --git a/maak-website.el b/maak-website.el index 3c6326e..3fb3b9c 100644 --- a/maak-website.el +++ b/maak-website.el @@ -4,15 +4,75 @@ (setq org-html-doctype "html5") (setq org-html-head-include-default-style nil) (setq org-html-htmlize-output-type 'css) ; default: 'inline-css +(setq org-time-stamp-custom-formats '("%A %e %B %Y" . "%A %e %B %Y at %H:%M")) +(setq org-display-custom-times t) +(setq my-blog-base-folder "~/websites/stage.vanrenterghem.biz") +(setq my-blog-source-folder "~/websites/stage.vanrenterghem.biz/source") +(setq my-blog-target-folder "~/websites/stage.vanrenterghem.biz/target") +(setq my-blog-mustache-folder (file-name-concat my-blog-base-folder "html")) +(setq my-blog-tags-folder (file-name-concat my-blog-source-folder "tags")) +(setq my-blog-posts-folder (file-name-concat my-blog-source-folder "posts")) +(defun my-org-get-all-filetags () + "Get list of filetags from all org-files in my-blog-posts-folder." + (let ((files (directory-files my-blog-posts-folder t nil nil nil)) + tagslist x) + (save-window-excursion + (while (setq x (pop files)) + (set-buffer (find-file-noselect x)) + (mapc + (lambda (y) + (let ((tagfiles (assoc y tagslist))) + (if tagfiles + (setcdr tagfiles (cons x (cdr tagfiles))) + (add-to-list 'tagslist (list y x))))) + (my-org-get-filetags))) + tagslist))) + +(defun my-org-get-filetags () + "Get list of filetags for current buffer" + (let ((ftags org-file-tags) + x) + (mapcar + (lambda (x) + (org-no-properties x)) + ftags))) + +(defun my-blog-create-tags-files (plist) + "Create org files for each tag defined in FILETAGS in posts, storing them in my-blog-tags-folder." + (unless (file-directory-p my-blog-tags-folder) (make-directory my-blog-tags-folder)) + (with-temp-file (file-name-concat my-blog-source-folder "tag-index.org") + (insert (concat "#+mustache-template: " (file-name-concat my-blog-mustache-folder "tags-index.mustache") "\n")) + (insert (concat "#+TITLE: Blog - All tags\n")) + (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript + (insert "\n") + (dolist (tag (sort (my-org-get-all-filetags) #'<)) + (insert (concat "- [[file:" (file-name-concat my-blog-posts-folder (concat "tag-" (car tag) ".org")) "][" (car tag) "]]\n")))) + (dolist (tag (my-org-get-all-filetags)) + (with-temp-file (file-name-concat my-blog-tags-folder (concat "tag-" (car tag) ".org")) + (insert (concat "#+mustache-template: " (file-name-concat my-blog-mustache-folder "tags.mustache") "\n")) + (insert (concat "#+TITLE: " (car tag) "\n")) + (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript + (insert "\n") + (insert (concat "# " (car tag) "\n\n")) + (dolist (tagfile (cdr tag)) + (let ((relpath (file-relative-name tagfile my-blog-posts-folder)));;not used + (message (concat "Processing " tagfile)) + (insert (concat "- " (format "%s - [[file:%s][%s]]" ;;the date and filename are added after the entry + (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date tagfile plist)) + relpath + (org-publish-find-title tagfile plist)) + "\n"))))))) + ;(my-org-publish-sitemap-default-entry tagfile nil plist) "\n"))))))) + (defun my-org-publish-sitemap-default-entry (entry style project) "My 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]]" ;;the date and filename are added after the entry - (format-time-string "%e %b %Y" (org-publish-find-date entry project)) + (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) @@ -56,7 +116,7 @@ Either the section between #+BEGIN_PREVIEW and +#END_PREVIEW is used, or the fir (defun my-blog-sitemap (title list) "Generate the sitemap landing page for my blog." - (my-plain-publish-sitemap-default title list) + (my-plain-publish-sitemap-default title list) ; Create additional sitemap (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)) @@ -66,7 +126,7 @@ Either the section between #+BEGIN_PREVIEW and +#END_PREVIEW is used, or the fir (let* ((abspath (file-name-concat "/home/frederik/websites/stage.vanrenterghem.biz/source/posts" file)) (relpath (file-relative-name abspath "/home/frederik/websites/stage.vanrenterghem.biz/source/posts/")) (title (org-publish-find-title file project-plist)) - (date (format-time-string (car org-time-stamp-formats) (org-publish-find-date file project-plist))) + (date (format-time-string (cdr org-time-stamp-custom-formats) (org-publish-find-date file project-plist))) (preview (my-blog-get-preview abspath)) ) ;; insert a horizontal line before every post, kill the first one @@ -93,7 +153,7 @@ Either the section between #+BEGIN_PREVIEW and +#END_PREVIEW is used, or the fir (insert "#+AUTHOR: Frederik Vanrenterghem\n") (insert "#+EMAIL: frederik@vanrenterghem.biz\n") (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript - (insert "#+mustache-template: ~/websites/stage.vanrenterghem.biz/html/post-index.mustache\n") + (insert (concat "#+mustache-template: " (file-name-concat my-blog-mustache-folder "post-index.mustache") "\n")) (insert "\n") (buffer-string)))) @@ -110,19 +170,24 @@ representation for the files to include, as returned by (let* ((abspath (file-name-concat "/home/frederik/websites/stage.vanrenterghem.biz/source/posts" file)) (relpath (file-relative-name abspath "/home/frederik/websites/stage.vanrenterghem.biz/source/")) (title (org-publish-find-title file project-plist)) - (date (format-time-string "%e %b %Y" (org-publish-find-date file project-plist)))) - (insert (concat "* [[file:" relpath "][" date " - " title "]]\n")))) + (date (format-time-string (car org-time-stamp-custom-formats) (org-publish-find-date file project-plist)))) + (insert (concat "* " date " - [[file:" relpath "][" title "]]\n")))) (goto-char (point-min)) (insert "#+OPTIONS: ^:nil\n")))) ; do not use underscores as subscript +(defun my-blog-cleanup-sitemaps (plist) + "Clean up temporary files created in the process of publishing" + (delete-file (file-name-concat my-blog-source-folder "sitemap.org")) + (delete-file (file-name-concat my-blog-posts-folder "sitemap.org")) + ) + (setq org-publish-project-alist - '(("landing" - :base-directory "~/websites/stage.vanrenterghem.biz/source/" + `(("landing" + :base-directory ,my-blog-source-folder :base-extension "org" - ;:include ("posts/sitemap.org") - :publishing-directory "~/websites/stage.vanrenterghem.biz/target" + :publishing-directory ,my-blog-target-folder :publishing-function org-mustache-html-publish-to-html - :mustache-template "~/websites/stage.vanrenterghem.biz/html/landing.mustache" + :mustache-template ,(file-name-concat my-blog-mustache-folder "landing.mustache") :headline-levels 2 :section-numbers nil :with-toc nil @@ -136,11 +201,12 @@ representation for the files to include, as returned by ) ("posts" - :base-directory "~/websites/stage.vanrenterghem.biz/source/posts/" + :base-directory ,my-blog-posts-folder :base-extension "org" - :publishing-directory "~/websites/stage.vanrenterghem.biz/target/posts" + :publishing-directory ,(file-name-concat my-blog-target-folder "posts") :publishing-function org-mustache-html-publish-to-html - :mustache-template "~/websites/stage.vanrenterghem.biz/html/post.mustache" + :mustache-template ,(file-name-concat my-blog-mustache-folder "post.mustache") + :preparation-function my-blog-create-tags-files :exclude "html*\\|assets*\\|index.org" ;"assets*\\|sitemap.org\\|index.org" ;; regexp :html-content-class nil :section-numbers nil @@ -162,11 +228,32 @@ representation for the files to include, as returned by :sitemap-filename "sitemap.org" ) + ("tags" + :base-directory ,(file-name-concat my-blog-source-folder "tags") + :base-extension "org" + :publishing-directory ,(file-name-concat my-blog-target-folder "posts") + :publishing-function org-mustache-html-publish-to-html + :mustache-template ,(file-name-concat my-blog-mustache-folder "tags.mustache") + :html-content-class nil + :section-numbers nil + :with-toc nil + :with-title nil + :html-head-include-default-style nil + :html-head nil + :html-divs nil + :recursive nil + :auto-sitemap nil + :html-preamble nil + :html-postamble nil + ) + ("assets" - :base-directory "~/websites/stage.vanrenterghem.biz/source/assets/" + :base-directory ,(file-name-concat my-blog-source-folder "assets") :base-extension any :recursive t - :publishing-directory "~/websites/stage.vanrenterghem.biz/target/assets/" - :publishing-function org-publish-attachment) + :publishing-directory ,(file-name-concat my-blog-target-folder "assets") + :publishing-function org-publish-attachment + :completion-function my-blog-cleanup-sitemaps + ) - ("website" :components ("posts" "landing" "assets")))) + ("website" :components ("posts" "tags" "landing" "assets")))) -- 2.39.5