new-ryuslash.org/publish.el

89 lines
3 KiB
EmacsLisp

;;; publish.el --- Publishing configuration for ryuslash.org -*- lexical-binding: t; -*-
;; Copyright (C) 2020 Tom Willemse
;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'dockerfile-mode)
(require 'ob-dot)
(require 'ox-publish)
(require 'rainbow-delimiters)
(require 'subr-x)
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
(defun publish-calculate-reading-time (buffer)
"Calculate the amount of minutes it would take to read the contents of BUFFER."
(with-current-buffer buffer
(max 1 (/ (count-words (point-min) (point-max)) 228))))
(defun publish-format-reading-time (time)
"Return a string describing TIME."
(format "%d minute%s"
time
(if (= time 1) "" "s")))
(setq org-export-exclude-tags '("noexport" "draft"))
(setq org-confirm-babel-evaluate nil)
(setq org-html-head-include-default-style t)
(setq org-html-htmlize-output-type 'css)
(setq org-publish-timestamp-directory
(concat default-directory "/.org-timestamps/"))
(setq org-publish-project-alist
'(("index"
:base-directory "."
:base-extension "org"
:publishing-directory "public/"
:recursive t
:exclude "^posts/"
:publishing-function org-html-publish-to-html
:html-head "<link rel=\"stylesheet\" href=\"/assets/css/main.css\" type=\"text/css\"/>")
("posts"
:base-directory "posts/"
:base-extension "org"
:publishing-directory "public/posts/"
:recursive t
:publishing-function org-html-publish-to-html
:html-head "<link rel=\"stylesheet\" href=\"/assets/css/main.css\" type=\"text/css\"/>"
:html-preamble (lambda (project)
(let ((buffer (find-file-noselect (buffer-file-name))))
(unless (string= "ryuslash.org"
(car (org-publish-find-property (buffer-file-name) :title project)))
(publish-format-reading-time
(publish-calculate-reading-time buffer))))))
("assets"
:base-directory "."
:recursive t
:exclude "^public/"
:base-extension "svg"
:publishing-function org-publish-attachment
:publishing-directory "public/")
("all" :components ("index" "posts" "assets"))))
(provide 'publish)
;;; publish.el ends here