Work in progress rewrite to support RSS.

I got this from
https://writepermission.com/org-blogging-rss-feed.html
and
https://gitlab.com/to1ne/blog/-/blob/master/elisp/publish.el

The RSS in rss.xml is not generated correctly. For example it has

<title>file:/var/www/htdocs/sha256.net/fun-with-org-mode-agenda-views.org</title>

The way the site is published is interesting though.
This commit is contained in:
Florian Obser 2023-04-18 13:51:37 +02:00
parent 3f45aea85f
commit 1b1b6d6232

View File

@ -13,6 +13,7 @@
(unless (package-installed-p 'use-package) (unless (package-installed-p 'use-package)
(package-install 'use-package)) (package-install 'use-package))
(require 'use-package) (require 'use-package)
(setq use-package-always-ensure t) (setq use-package-always-ensure t)
@ -28,21 +29,68 @@
:pin org) :pin org)
(use-package htmlize) (use-package htmlize)
(use-package ox-rss)
(require 'ox-publish) (require 'ox-publish)
(require 'ox-html) (require 'ox-html)
(require 'htmlize)
(defvar fo-base-directory "/var/www/htdocs/sha256.net/"
"Where the org files live.")
(defvar fo-url "https://openbsd-build.home.narrans.de/sha256.net/"
"URL where the site will be published.")
(defvar fo-title "sha256.net - Florian Obser"
"Title of the site.")
(setq org-html-doctype "html5") (setq org-html-doctype "html5")
(setq org-html-htmlize-output-type 'css) (setq org-html-htmlize-output-type 'css)
(setq org-export-time-stamp-file nil) (setq org-export-time-stamp-file nil)
(setq org-html-validation-link nil) (setq org-html-validation-link nil)
(setq org-html-head-include-default-style nil) (setq org-html-head-include-default-style nil)
(setq org-publish-project-alist
'(("tlakh" (defun fo/format-rss-feed-entry (entry style project)
:base-directory "/var/www/sha256.net/" "Format ENTRY for the RSS feed.
:publishing-function org-html-publish-to-html ENTRY is a file name. STYLE is either 'list' or 'tree'.
:publishing-directory "/var/www/sha256.net/" PROJECT is the current project."
(cond ((not (directory-name-p entry))
(let* ((file (org-publish--expand-file-name entry project))
(title (org-publish-find-title entry project))
(date (format-time-string "%Y-%m-%d" (org-publish-find-date entry project)))
(link (concat (file-name-sans-extension entry) ".html")))
(with-temp-buffer
(insert (format "* [[file:%s][%s]]\n" file title))
(org-set-property "RSS_PERMALINK" link)
(org-set-property "PUBDATE" date)
(insert-file-contents file)
(buffer-string))))
((eq style 'tree)
;; Return only last subdir.
(file-name-nondirectory (directory-file-name entry)))
(t entry)))
(defun fo/format-rss-feed (title list)
"Generate RSS feed, as a string.
TITLE is the title of the RSS feed. LIST is an internal
representation for the files to include, as returned by
`org-list-to-lisp'. PROJECT is the current project."
(concat "#+TITLE: " title "\n\n"
(org-list-to-subtree list 1 '(:icount "" :istart ""))))
(defun fo/org-rss-publish-to-rss (plist filename pub-dir)
"Publish RSS with PLIST, only when FILENAME is 'rss.org'.
PUB-DIR is when the output will be placed."
(if (equal "rss.org" (file-name-nondirectory filename))
(org-rss-publish-to-rss plist filename pub-dir)))
(defvar fo--publish-project-alist
(list
(list "sha256.net"
:base-directory fo-base-directory
:publishing-function 'org-html-publish-to-html
:publishing-directory fo-base-directory
:exclude (regexp-opt '("rss.org"))
:section-numbers nil :section-numbers nil
:with-author nil :with-author nil
:with-email nil :with-email nil
@ -57,6 +105,49 @@ Copyright &copy; 2014 - 2023 Florian Obser. All rights reserved.
:html-head-include-default-style: nil :html-head-include-default-style: nil
:html-head "<link rel=\"stylesheet\" href=\"simple.min.css\" type=\"text/css\"/> :html-head "<link rel=\"stylesheet\" href=\"simple.min.css\" type=\"text/css\"/>
<link rel=\"stylesheet\" href=\"htmlize.min.css\" type=\"text/css\"/> <link rel=\"stylesheet\" href=\"htmlize.min.css\" type=\"text/css\"/>
<link rel=\"stylesheet\" href=\"custom.css\" type=\"text/css\"/>"))) <link rel=\"stylesheet\" href=\"custom.css\" type=\"text/css\"/>")
(list "sha256.net-rss"
:base-directory fo-base-directory
:publishing-directory fo-base-directory
:base-extension "org"
:recursive nil
:exclude (regexp-opt '("rss.org" "index.org" "404.org" "50x.org"))
:publishing-function 'fo/org-rss-publish-to-rss
:rss-extension "xml"
:html-link-home fo-url
:html-link-use-abs-url t
:html-link-org-files-as-html t
:auto-sitemap t
:sitemap-filename "rss.org"
:sitemap-title fo-title
:sitemap-style 'list
:sitemap-sort-files 'anti-chronologically
:sitemap-function 'fo/format-rss-feed
:sitemap-format-entry 'fo/format-rss-feed-entry
:author "Florian Obser"
:email "")
(list "site"
:components '("sha256.net"))))
(org-publish "tlakh") (defun fo-publish-all ()
"Publish the blog to HTML."
(interactive)
(let ((org-publish-project-alist fo--publish-project-alist)
(org-publish-timestamp-directory "./.timestamps/")
(org-export-with-section-numbers nil)
(org-export-with-smart-quotes t)
(org-export-with-toc nil)
(org-export-with-sub-superscripts '{})
(org-html-divs '((preamble "header" "top")
(content "main" "content")
(postamble "footer" "postamble")))
(org-html-container-element "section")
(org-html-metadata-timestamp-format "%Y-%m-%d")
(org-html-checkbox-type 'html)
(org-html-html5-fancy t)
(org-html-validation-link nil)
(org-html-doctype "html5")
(org-html-htmlize-output-type 'css))
(org-publish-all)))
(fo-publish-all)