X-Git-Url: http://git.vanrenterghem.biz/www2.vanrenterghem.biz.git/blobdiff_plain/9e5650b786d4657920217a1b9ac610a34cf28fa0..42b72788cacc9411404bddc5498b6ed7b9e62f3e:/maak-website.el diff --git a/maak-website.el b/maak-website.el index 4cc1f9a..c93f1cc 100644 --- a/maak-website.el +++ b/maak-website.el @@ -1,5 +1,13 @@ +(require 'cl-lib) +(require 'org) (require 'ox-publish) -;(require 'ox-rss) +(add-to-list 'load-path "~/.emacs.d/elpa/ox-rss-20230408.231") +(add-to-list 'load-path "~/.emacs.d/elpa/mustache-20230713.514") +(add-to-list 'load-path "~/.emacs.d/elpa/s-20220902.1511") +(add-to-list 'load-path "~/.emacs.d/elpa/dash-20240510.1327") +(add-to-list 'load-path "~/.emacs.d/elpa/f-20240308.906 " ) +(add-to-list 'load-path "~/.emacs.d/elpa/htmlize-20240527.1456") +(require 'ox-rss) (load "~/.emacs.d/lisp/mustache-html.el") (setq org-html-doctype "html5") @@ -7,9 +15,11 @@ (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 org-html-container-element "div") ;; TODO - check (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-target-url "https://www.vanrenterghem.biz/posts/") (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")) @@ -44,14 +54,19 @@ (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") + (let* ((tagfolder (file-name-concat + (plist-get (cdr (assoc "landing" org-publish-project-alist)) :base-directory))) + (postfolder (file-name-concat + (plist-get (cdr (assoc "posts" org-publish-project-alist)) :base-directory))) + (relpostfolder (file-relative-name postfolder tagfolder))) + (unless (file-directory-p my-blog-tags-folder) (make-directory my-blog-tags-folder)) + (with-temp-file (file-name-concat tagfolder "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) (lambda (x y) (string-lessp (car x) (car y))) )) - (insert (concat "- [[file:" (file-name-concat my-blog-posts-folder (concat "tag-" (car tag) ".org")) "][" (car tag) "]]\n")))) + (insert (concat "- [[file:" (file-name-concat relpostfolder (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")) @@ -120,7 +135,6 @@ 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) ; Create additional sitemap - ;(my-blog-publish-rss-sitemap title list) ; Create RSS 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)) @@ -135,25 +149,36 @@ Either the section between #+BEGIN_PREVIEW and +#END_PREVIEW is used, or the fir ) ;; insert a horizontal line before every post, kill the first one ;; before saving - (insert "-----\n") (insert (concat "* [[file:" relpath "][" title "]]\n")) ;; add properties for `ox-rss.el' here - ;(let ((rss-permalink (concat (file-name-sans-extension relpath) ".html")) - ; (rss-pubdate date)) - ; (org-set-property "RSS_PERMALINK" rss-permalink) - ; (org-set-property "PUBDATE" rss-pubdate)) + (let ((rss-permalink (concat (file-name-sans-extension relpath) ".html")) + (rss-pubdate (format-time-string (cdr org-time-stamp-formats) (org-publish-find-date file project-plist)))) + (org-mode) + (org-set-property "HTML_CONTAINER_CLASS" "card mb-2") ;Bootstrap margin border 2 + (org-set-property "HTML_HEADLINE_CLASS" "card-header card-title border-bottom-0 fs-5 fw-bold text-decoration-none") + (org-set-property "RSS_PERMALINK" rss-permalink) + (org-set-property "PUBDATE" rss-pubdate) + (org-set-property "RSS_TITLE" title)) ;; insert the date, preview, & read more link + (insert "#+ATTR_HTML: :class card-header\n") (insert (concat "Published: " date "\n\n")) + (insert "#+BEGIN_export html\n") + (insert "
\n") + (insert "#+END_export\n") (insert preview) ;(insert (concat "#+INCLUDE: \"" relpath "\" :only-contents t :lines \"1-10\"\n")) - (insert "\n") - (insert (concat "[[file:" relpath "][Read More...]]\n")))) + (insert "\n") + (insert (concat "[[file:" relpath "][Read More...]]\n")) + (insert "#+BEGIN_export html\n") + (insert "
\n") + (insert "#+END_export\n") + )) ;; kill the first hrule to make this look OK - (goto-char (point-min)) - (let ((kill-whole-line t)) (kill-line)) + ;(goto-char (point-min)) + ;(let ((kill-whole-line t)) (kill-line)) ;; insert a title and save (insert "#+OPTIONS: title:nil\n") - (insert "#+TITLE: Blog\n") + (insert "#+TITLE: Frederik Vanrenterghem's blog\n") (insert "#+AUTHOR: Frederik Vanrenterghem\n") (insert "#+EMAIL: frederik@vanrenterghem.biz\n") (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript @@ -179,42 +204,20 @@ representation for the files to include, as returned by (goto-char (point-min)) (insert "#+OPTIONS: ^:nil\n")))) ; do not use underscores as subscript -(defun my-blog-publish-rss-sitemap (title list) - "Create a simple site map, as a string. -TITLE is the title of the site map. LIST is an internal -representation for the files to include, as returned by -`org-list-to-lisp'." - (with-temp-buffer - (message "Creating RSS index.") - (let* ((filenames (my-blog-parse-sitemap-list list)) - (project-plist (assoc "posts" org-publish-project-alist)) - ;;(articles (my-blog-sort-article-list filenames project-plist)) - ) - (org-mode) - (insert "#+AUTHOR: Frederik Vanrenterghem\n") - (dolist (file filenames) - (unless (eq (file-name-base file) "rss.org") - (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 (car org-time-stamp-custom-formats) (org-publish-find-date file project-plist))) - (rss-permalink (file-name-sans-extension relpath)) - (preview (my-blog-get-preview abspath))) - (insert (concat "* [[file:" relpath "][" title "]]\n")) - (org-set-property "RSS_PERMALINK" rss-permalink) - (org-set-property "PUBDATE" date) - (org-set-property "RSS_TITLE" title) - (insert preview)))) - (goto-char (point-min)) - (insert "#+OPTIONS: ^:nil\n") - (write-file "~/websites/stage.vanrenterghem.biz/source/posts/rss.org")))) - - (defun my-blog-cleanup-sitemaps (plist) "Clean up temporary files created in the process of publishing" + ;; Create a body-only version of the tags index. Needs absolute path to posts folder. + (with-temp-file (file-name-concat + (plist-get (cdr (assoc "landing" org-publish-project-alist)) :publishing-directory) + "tag-index-body.html") + (insert-file-contents (file-name-concat + (plist-get (cdr (assoc "landing" org-publish-project-alist)) :base-directory) + "tag-index.org")) + (org-export-to-buffer 'mustache-html (current-buffer) nil nil nil t nil) + (replace-string "href=\"posts" "href=\"/posts")) (delete-file (file-name-concat my-blog-source-folder "sitemap.org")) (delete-file (file-name-concat my-blog-posts-folder "sitemap.org")) - ) + (delete-file (file-name-concat my-blog-posts-folder "sitemap.org~"))) (setq org-publish-project-alist `(("landing" @@ -242,7 +245,7 @@ representation for the files to include, as returned by :publishing-function org-mustache-html-publish-to-html :mustache-template ,(file-name-concat my-blog-mustache-folder "post.mustache") :preparation-function my-blog-create-tags-files - :exclude "html*\\|assets*\\|index.org\\|rss.org" ;"assets*\\|sitemap.org\\|index.org" ;; regexp + :exclude "html*\\|assets*\\|index.org\\|sitemap.org" ;"assets*\\|sitemap.org\\|index.org" ;; regexp :html-content-class nil :section-numbers nil :with-toc nil @@ -292,20 +295,18 @@ representation for the files to include, as returned by ("rss" :base-directory ,my-blog-posts-folder :base-extension "org" - :publishing-directory ,my-blog-target-folder + :publishing-directory ,(file-name-concat my-blog-target-folder "posts") :publishing-function org-rss-publish-to-rss :with-author t - - :html-link-home "https://www.vanrenterghem.biz/" + :title "Frederik Vanrenterghem's blog" + :html-link-home ,my-blog-target-url :html-link-use-abs-url t - - :title "Frederik Vanrenterghem" - :rss-image-url "https://test/img/feed-icon-28x28.png" - ;:my-rss-stylesheet "/res/rss.xsl" ; custom style sheet - ;:completion-function my-website-rss-postprocessor - :section-numbers nil + :section-numbers nil :exclude ".*" - :include ("rss.org") - :table-of-contents nil) + :include ("sitemap.org") + :table-of-contents nil + ) ("website" :components ("posts" "rss" "tags" "landing" "assets")))) + +(org-publish-initialize-cache "website")