tlakh/publish.el

154 lines
5.3 KiB
EmacsLisp
Executable File

#!/usr/local/bin/emacs --script
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives
'("org" . "http://orgmode.org/elpa/") t)
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t)
(use-package auto-package-update
:custom
(auto-package-update-interval 7)
(auto-package-update-prompt-before-update nil)
(auto-package-update-hide-results t)
:config
(auto-package-update-maybe))
(use-package org
:pin org)
(use-package htmlize)
(use-package ox-rss)
(require 'ox-publish)
(require 'ox-html)
(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-htmlize-output-type 'css)
(setq org-export-time-stamp-file nil)
(setq org-html-validation-link nil)
(setq org-html-head-include-default-style nil)
(defun fo/format-rss-feed-entry (entry style project)
"Format ENTRY for the RSS feed.
ENTRY is a file name. STYLE is either 'list' or 'tree'.
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
:with-author nil
:with-email nil
:with-timestamps nil
:with-toc nil
:with-creator: nil
:time-stamp-file: nil
:html-postamble "<p class=\"date\">Published: %d</p>
<hr /><footer><nav><a href=\"/\">&lt; Home</a></nav>
Copyright &copy; 2014 - 2023 Florian Obser. All rights reserved.
</footer>"
:html-head-include-default-style: nil
: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=\"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"))))
(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)