(require 'ox-publish)
(setq org-html-doctype "html5")
-(setq org-html-divs '((preamble "header" "top")
- (content "main" "content")
- (postamble "footer" "postamble"))
- org-html-container-element "section")
(setq org-html-head-include-default-style nil)
;(setq org-html-htmlize-output-type 'css) ; default: 'inline-css
-(defun website-header (info)
- (with-temp-buffer
- (insert-file-contents "~/websites/stage.vanrenterghem.biz/html/navbar.html")
- (buffer-string)))
-
-(defun post-header (exp-plist)
- (with-temp-buffer
- (insert (format "<nav aria-label=\"breadcrumb\">
- <ol class=\"breadcrumb\">
- <li class=\"breadcrumb-item\"><a href=\"/\">Home</a></li>
- <li class=\"breadcrumb-item\"><a href=\"/sitemap.html\">Blog</a></li>
- <li class=\"breadcrumb-item active\" aria-current=\"page\">%s</li>
- </ol>
- </nav>"
- (or (org-export-data (plist-get exp-plist ':title) exp-plist)
- "none")))
- (goto-char (point-min))
- (insert-file-contents "~/websites/stage.vanrenterghem.biz/html/post-header.html")
- ;(goto-char (point-max))
- ;(insert (format "<p>Tags: %s</p>"
- ; (or (org-export-data (plist-get exp-plist :filetags) exp-plist)
- ; "none")))
- (buffer-string)))
-
-(defun website-footer (info)
- (with-temp-buffer
- (insert-file-contents "~/websites/stage.vanrenterghem.biz/html/footer.html")
- (buffer-string)))
(defun my-org-publish-sitemap-default-entry (entry style project)
"My format for site map ENTRY, as a string.
(file-name-nondirectory (directory-file-name entry)))
(t entry)))
+(defun my-blog-parse-sitemap-list (l)
+ "Convert the sitemap list in to a list of filenames."
+ (mapcar #'(lambda (i)
+ (let ((link (with-temp-buffer
+ (let ((org-inhibit-startup nil))
+ (insert (car i))
+ (org-mode)
+ (goto-char (point-min))
+ (org-element-link-parser)))))
+ (when link
+ (plist-get (cadr link) :path))))
+ (cdr l)))
+
+(defun my-blog-sort-article-list (l p)
+ "sort the article list anti-chronologically."
+ (sort l #'(lambda (a b)
+ (let ((d-a (org-publish-find-date a p))
+ (d-b (org-publish-find-date b p)))
+ (not (time-less-p d-a d-b))))))
+
+(defun my-blog-get-preview (file)
+ "Clips a section of a post in FILE to be used as preview in the sitemap.
+Either the section between #+BEGIN_PREVIEW and +#END_PREVIEW is used, or the first section between 2 blank lines."
+ (with-temp-buffer
+ (insert-file-contents file)
+ (goto-char (point-min))
+ (let* ((beg (or (re-search-forward "^#\\+BEGIN_PREVIEW$" nil t 1)
+ (re-search-forward "^$")))
+ (end (or (if (re-search-forward "^#\\+END_PREVIEW$" nil t 1)
+ (match-beginning 0))
+ (progn (goto-char (+ 1 beg))
+ (re-search-forward "^$" nil t 2)))))
+ (buffer-substring beg end))))
+
+(defun my-blog-sitemap (title list)
+ "Generate the sitemap landing page for my blog."
+ (my-plain-publish-sitemap-default title list)
+ (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))
+ (project-plist (assoc "posts" org-publish-project-alist))
+ (articles (my-blog-sort-article-list filenames project-plist)))
+ (dolist (file filenames)
+ (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/"))
+ (title (org-publish-find-title file project-plist))
+ (date (format-time-string (car org-time-stamp-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
+ ;; 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))
+ ;; insert the date, preview, & read more link
+ (insert (concat "Published: " date "\n\n"))
+ (insert preview)
+ ;(insert (concat "#+INCLUDE: \"" relpath "\" :only-contents t :lines \"1-10\"\n"))
+ (insert "\n")
+ (insert (concat "[[file:" relpath "][Read More...]]\n"))))
+ ;; kill the first hrule to make this look OK
+ (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 "#+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 "\n")
+ (buffer-string))))
+
+(defun my-plain-publish-sitemap-default (title list)
+ "Default 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'. PROJECT is the current project."
+ (with-temp-file "~/websites/stage.vanrenterghem.biz/source/sitemap.org"
+ (insert "#+OPTIONS: ^:nil\n") ; do not use underscores as subscript
+ (insert (concat "#+TITLE: " title "\n\n"))
+ (insert (org-list-to-org list))))
+
(setq org-publish-project-alist
- '(("pages"
+ '(("landing"
:base-directory "~/websites/stage.vanrenterghem.biz/source/"
:base-extension "org"
+ :include ("posts/sitemap.org")
:publishing-directory "~/websites/stage.vanrenterghem.biz/target"
- :publishing-function org-html-publish-to-html
+ :publishing-function org-mustache-html-publish-to-html
+ :mustache-template "~/websites/stage.vanrenterghem.biz/html/landing.mustache"
:headline-levels 3
:section-numbers nil
:with-toc nil
:html-head-include-default-style nil
- :html-head "<link href=\"/assets/styles/bootstrap-5.3.0/css/bootstrap.min.css\" rel=\"stylesheet\" />"
- :html-preamble t
- :html-preamble website-header
- :html-postamble website-footer
+ :html-head nil
+ :html-divs nil
+ :html-preamble nil
+ :html-postamble nil
)
("posts"
:base-directory "~/websites/stage.vanrenterghem.biz/source/posts/"
:base-extension "org"
- :publishing-directory "~/websites/stage.vanrenterghem.biz/target"
- :publishing-function org-html-publish-to-html
- :exclude "assets*\\|sitemap.org\\|index.org" ;; regexp
- :html-content-class "container content inlinepage card h-entry"
- :headline-levels 3
+ :publishing-directory "~/websites/stage.vanrenterghem.biz/target/posts"
+ :publishing-function org-mustache-html-publish-to-html
+ :mustache-template "~/websites/stage.vanrenterghem.biz/html/post.mustache"
+ :exclude "assets*\\|index.org" ;"assets*\\|sitemap.org\\|index.org" ;; regexp
+ :html-content-class nil
:section-numbers nil
:with-toc nil
:with-title nil
+ :sitemap-title "All posts"
:html-head-include-default-style nil
- :html-head "<link href=\"/assets/styles/bootstrap-5.3.0/css/bootstrap.min.css\" rel=\"stylesheet\" />\n
- <link href=\"/assets/styles/org-htmlize.css\" rel=\"stylesheet\" />"
- :html-preamble t
- :html-divs ((preamble "header" "preamble")
- (content "article" "inlinepage card h-entry")
- (postamble "footer" "postamble"))
+ :html-head nil
+ :html-divs nil
:recursive t
:auto-sitemap t
- :html-preamble post-header
- :html-postamble website-footer
+ :html-preamble nil
+ :html-postamble nil
:sitemap-sort-folders ignore-errors
- :sitemap-format-entry my-org-publish-sitemap-default-entry
+ :sitemap-function my-blog-sitemap
+ ;:sitemap-function org-publish-sitemap-default
+ ;:sitemap-format-entry my-org-publish-sitemap-default-entry
:sitemap-sort-files anti-chronologically
+ :sitemap-filename "sitemap.org"
)
("assets"
:publishing-directory "~/websites/stage.vanrenterghem.biz/target/assets/"
:publishing-function org-publish-attachment)
- ("website" :components ("posts" "pages" "assets"))))
+ ("website" :components ("posts" "landing" "assets"))))