113 lines
3.3 KiB
EmacsLisp
113 lines
3.3 KiB
EmacsLisp
;; This is a basic configuration of org-publish (built-into org mode)
|
|
;; I keep everything relatively default / best practice.
|
|
;;
|
|
;; emacs --script publish.el
|
|
|
|
(defun with-path (str)
|
|
"Return the current path of the location of this file"
|
|
(concat (file-name-directory load-file-name) str))
|
|
|
|
;; Variables I may want to change on another machine :3
|
|
(defvar input-dir (with-path "/org"))
|
|
(defvar output-dir (with-path "/html"))
|
|
(defvar my-name "knit")
|
|
(defvar domain "https://tilde.green/~knit")
|
|
(defvar my-rss (concat domain "/rss.xml"))
|
|
|
|
;; Include packages I want to use.
|
|
(package-initialize)
|
|
(use-package htmlize :ensure t)
|
|
(use-package ox-rss :ensure t)
|
|
(use-package org)
|
|
(require 'shr)
|
|
(require 'ox)
|
|
|
|
(defun file-to-string (file)
|
|
"Return contents of FILE as a string."
|
|
(with-temp-buffer
|
|
(insert-file-contents file)
|
|
(buffer-string)))
|
|
|
|
(defun link (url label)
|
|
"Make a lisp-style HTML link to URL with label LABEL.
|
|
To be read by 'shr-dom-to-xml'"
|
|
`(a ((href . ,url)) ,label))
|
|
|
|
;; Let sitemap display descriptions
|
|
(add-to-list 'org-export-options-alist '(:desc "DESCRIPTION" "" nil t parse))
|
|
|
|
(defun my-sitemap (entry style project)
|
|
"Create the sitemap by listing every page, along with their description tags."
|
|
(let ((desc (or (org-publish-find-property entry :desc project)
|
|
"no description"))
|
|
(title (or (org-publish-find-title entry project)
|
|
"untitled :3")))
|
|
(if (directory-name-p entry)
|
|
"file is directory 💔"
|
|
(format "[[file:%s][%s]]\n\n/%s/" entry title desc))))
|
|
|
|
;; No default inline CSS.
|
|
(setq org-html-head-include-default-style nil)
|
|
|
|
;; TODO: i can't seem to properly separate 'green-base' and 'sitemap'
|
|
(setq org-publish-project-alist
|
|
(list
|
|
(list "green"
|
|
:base-directory input-dir
|
|
:publishing-directory output-dir
|
|
:html-link-home domain
|
|
:author my-name
|
|
:email ";3"
|
|
:base-extension "org"
|
|
:section-numbers nil
|
|
:with-toc nil
|
|
:auto-sitemap t
|
|
:sitemap-filename "map.org"
|
|
:sitemap-title "all pages :3"
|
|
:sitemap-format-entry 'my-sitemap
|
|
:sitemap-style 'list)))
|
|
|
|
(setq
|
|
org-export-with-timestamps nil
|
|
org-export-with-broken-links t
|
|
org-export-with-section-numbers nil
|
|
org-export-with-tasks 'done
|
|
org-html-metadata-timestamp-format "%Y-%m-%d"
|
|
org-html-htmlize-output-type 'css
|
|
org-html-htmlize-font-prefix ""
|
|
org-html-head-include-default-style nil
|
|
org-html-link-up domain
|
|
org-html-link-home domain
|
|
org-rss-image-url (concat domain "/knit.png"))
|
|
|
|
;; Every page has inline CSS:
|
|
(setq org-html-head
|
|
(concat "<style>"
|
|
(file-to-string "css/base.css")
|
|
"</style>"))
|
|
|
|
;; The page footer:
|
|
(setq org-export-date-timestamp-format "%Y-%m-%d")
|
|
(setq org-html-postamble
|
|
(shr-dom-to-xml
|
|
`(p nil "modified: %C //"
|
|
,(link (concat domain "/curl-me.html") "curl me~"))))
|
|
|
|
;; An HTML link to the index.
|
|
(setq org-html-home/up-format
|
|
(shr-dom-to-xml
|
|
`(nav nil
|
|
(p nil
|
|
,(link domain my-name) " - "
|
|
,(link (concat domain "/links.html") "links") " - "
|
|
,(link (concat domain "/rss.xml") "rss")))))
|
|
|
|
;; Linking to additional stylesheet.
|
|
;; This can't be done with SHR because it hardcodes an ending tag."
|
|
(setq org-html-head-extra
|
|
"<link rel=\"stylesheet\" href=\"https://tilde.green/~knit/css/style.css\" type=\"text/css\" />")
|
|
|
|
;; Finally, publish the website.
|
|
(org-publish "green")
|
|
|