notes/export.el
2025-05-05 16:18:04 +01:00

160 lines
11 KiB
EmacsLisp
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(setq user-full-name "Mez")
(setq org-export-with-toc nil)
(setq org-export-global-macros
'(("theboy" . "[[https://kes.praze.net/@adt][@adt]]")
("dwuser" . "[[https://$1.dreamwidth.org][~$1]]")
("dwcomm" . "[[https://$1.dreamwidth.org][/$1]]")))
(setq org-html-doctype "html5")
(setq org-html-head-include-default-style nil)
(setq org-html-head-include-scripts nil)
(setq org-html-use-infojs nil)
(setq org-html-divs
'((preamble "nav" "nav")
(content "main" "content")
(postamble "footer" "postamble")))
(setq org-html-preamble "<input type=\"checkbox\" id=\"toggle\" name=\"toggle\">\n<label class=\"toggle-btn\" for=\"toggle\">Menu</label>\n<ul>\n<li>Fundamentals\n<ul>\n<li><a href=\"/\">Home</a></li>\n<li><a href=\"/about\">About + listings</a></li>\n<li><a href=\"/follow\">Follow</a></li>\n<li><a href=\"/feed.xml\">Changelog</a> <a href=\"/feed.xml\"><span class=\"rss\"></span></a></li>\n<li><a href=\"/sitemap.xml\">Sitemap</a></li>\n<li><a href=\"/siteroll\">Siteroll</a></li>\n</ul>\n</li>\n<li>Projects\n<ul>\n<li><a href=\"/fic\">Fanfiction</a> <a href=\"/fic/feed.xml\"><span class=\"rss\"></span></a></li>\n<li><a href=\"/music\">Music</a></li>\n<li><a href=\"/notes\">Journal</a></li>\n<li><a href=\"/trackers\">Trackers</a></li>\n<li><a href=\"https://git.praze.net/tre\" target=\"_blank\">Code</a> <a href=\"https://git.praze.net/tre.rss\"><span class=\"rss\"></span></a></li>\n<li><a href=\"https://img.praze.net\" target=\"_blank\">Photos</a> <a href=\"https://img.praze.net/feed.php\"><span class=\"rss\"></span></a></li>\n</ul>\n</li>\n<li>Fan content\n<ul>\n<li><a href=\"/ffx\">FFX</a></li>\n<li><a href=\"/xvi\">FF16</a></li>\n<li><a href=\"https://morgan.praze.net\" target=\"_blank\">Dermot Morgan</a> <a href=\"https://morgan.praze.net/feed.xml\"><span class=\"rss\"></span></a></li>\n</ul>\n</li>\n<li>Misc.\n<ul>\n<li><a href=\"https://tcg.praze.net\" target=\"_blank\">TCG</a></li>\n<li><a href=\"https://links.praze.net\" target=\"_blank\">Bookmarks</a> <a href=\"https://links.praze.net/feed/rss\"><span class=\"rss\"></span></a></li>\n<li><a href=\"https://kes.praze.net/@tre\" target=\"_blank\">Fediverse</a> <a href=\"https://kes.praze.net/@tre/feed.rss\"><span class=\"rss\"></span></a></li>\n</ul>\n</li>\n</ul>")
(setq org-html-postamble "<ul>\n<li><a href=\"/notes\">Back to notes</a></li>\n</ul>")
(setq thetitle (cadar (org-collect-keywords '("TITLE"))))
(setq pageurl (replace-regexp-in-string "-" "" (file-name-base)))
(setq thedesc (cadar (org-collect-keywords '("OGDESC"))))
(setq thecategory (cadar (org-collect-keywords '("CATEGORY"))))
(setq havecomments (if
(string-match
(cadar (org-collect-keywords '("COMMENTS"))) "t")
t
nil))
(setq org-html-head (concat "<meta property=\"og:title\" content=\"" thetitle "\">\n<meta property=\"og:type\" content=\"article\">\n<meta property=\"og:image\" content=\"https://tre.praze.net/ab.png\">\n<meta property=\"og:url\" content=\"https://tre.praze.net/notes/" pageurl "\">\n<meta name=\"description\" property=\"og:description\" content=\"" thedesc "\">\n<meta property=\"og:locale\" content=\"en_GB\">\n<meta property=\"og:site_name\" content=\"tre.praze.net\">\n<meta name=\"fediverse:creator\" content=\"@tre@praze.net\">\n<link rel=\"stylesheet\" href=\"/new.css\">\n<link rel=\"me\" href=\"https://kes.praze.net/@tre\">\n<link rel=\"alternate\" type=\"application/rss+xml\" title=\"tre.praze.net\" href=\"/feed.xml\">\n<link rel=\"alternate\" type=\"application/activity+json\" href=\"https://fed.brid.gy/r/https://tre.praze.net/notes/" pageurl "\">\n<meta name=\"theme-color\" content=\"#f2f2f2\" />\n<noscript>\n <style>.jsonly{display:none;}</style>\n</noscript>"))
(defun org-html-template (contents info)
"Return complete document string after HTML conversion.
CONTENTS is the transcoded contents string. INFO is a plist
holding export options."
(concat
(when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
(let* ((xml-declaration (plist-get info :html-xml-declaration))
(decl (or (and (stringp xml-declaration) xml-declaration)
(cdr (assoc (plist-get info :html-extension)
xml-declaration))
(cdr (assoc "html" xml-declaration))
"")))
(when (not (or (not decl) (string= "" decl)))
(format "%s\n"
(format decl
(or (and org-html-coding-system
;; FIXME: Use Emacs 22 style here, see `coding-system-get'.
(coding-system-get org-html-coding-system 'mime-charset))
"iso-8859-1"))))))
(org-html-doctype info)
"\n"
(concat "<html"
(cond ((org-html-xhtml-p info)
(format
" xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
(plist-get info :language) (plist-get info :language)))
((org-html-html5-p info)
(format " lang=\"%s\"" (plist-get info :language))))
">\n")
"<head>\n"
(org-html--build-meta-info info)
(org-html--build-head info)
(org-html--build-mathjax-config info)
"</head>\n"
"<body>\n"
(let ((link-up (org-trim (plist-get info :html-link-up)))
(link-home (org-trim (plist-get info :html-link-home))))
(unless (and (string= link-up "") (string= link-home ""))
(format (plist-get info :html-home/up-format)
(or link-up link-home)
(or link-home link-up))))
;; Preamble.
(org-html--build-pre/postamble 'preamble info)
"<div>\n"
;; Document contents.
(let ((div (assq 'content (plist-get info :html-divs))))
(format "<%s id=\"%s\" class=\"%s h-entry\">\n"
(nth 1 div)
(nth 2 div)
(plist-get info :html-content-class)))
"<section>\n"
;; Document title.
(when (plist-get info :with-title)
(let ((title (and (plist-get info :with-title)
(plist-get info :title)))
(subtitle (plist-get info :subtitle))
(html5-fancy (org-html--html5-fancy-p info)))
(when title
(format
(if html5-fancy
"<header>\n<h1 class=\"p-name\">%s</h1>\n%s</header>"
"<h1 class=\"p-name\">%s%s</h1>\n")
(org-export-data title info)
(if subtitle
(format
(if html5-fancy
"<p class=\"subtitle\" role=\"doc-subtitle\">%s</p>\n"
(concat "\n" (org-html-close-tag "br" nil info) "\n"
"<span class=\"subtitle\">%s</span>\n"))
(org-export-data subtitle info))
"")))))
"<p class=\"date\"><time class=\"dt-published\" datetime=\"" (file-name-base) " 00:00:00\">" (file-name-base) "</time></p>\n"
"<div class=\"e-content\">\n"
contents
"</div>\n"
(if havecomments
"<div id=\"comments\">\n<h2>Comments</h2>\n<noscript>\n<p><b>JavaScript is unavailable.</b> Please <a href=\"mailto:tre@praze.net\">email me</a> any comments.</p>\n</noscript>\n<p class=\"jsonly\">You can comment on this post if you like. Comments will be posted below after moderation.</p>\n<form id=\"theform\" onsubmit=\"sendContact(event)\" class=\"jsonly\">\n<input type=\"text\" id=\"nameInput\" required placeholder=\"Pseudonym (required)\">\n<input type=\"email\" id=\"emailInput\" placeholder=\"Email (if you want email notification of reply)\">\n<input type=\"url\" id=\"siteInput\" placeholder=\"Site (if you want a link back)\">\n<textarea id=\"messageInput\" rows=\"5\" maxlength=\"4800\" required placeholder=\"Your comment (required, include whatever markup [or down] you like)\"></textarea>\n<button type=\"submit\">Submit</button>\n</form>\n</div>\n")
"</section>\n"
"<div id=\"federation\" hidden=\"from-humans\">\n<a class=\"u-bridgy-fed\" href=\"https://fed.brid.gy/\"></a>\n<a rel=\"author\" class=\"p-author h-card\" href=\"/\">Mez<img class=\"u-photo\" src=\"/ab.png\"></a>\n<a class=\"u-url\" href=\"/notes/" pageurl "/\"></a>\n<span class=\"p-category\">" thecategory "</span>\n</div>\n"
"<!-- comments go here -->\n"
(format "</%s>\n" (nth 1 (assq 'content (plist-get info :html-divs))))
;; Postamble.
(org-html--build-pre/postamble 'postamble info)
"</div>\n"
"<a href=\"/\"><img src=\"/a.png\" style=\"position:fixed;bottom:2px;right:2px;\" title=\"home\"></a>\n"
;; Possibly use the Klipse library live code blocks.
(when (plist-get info :html-klipsify-src)
(concat "<script>" (plist-get info :html-klipse-selection-script)
"</script><script src=\""
org-html-klipse-js
"\"></script><link rel=\"stylesheet\" type=\"text/css\" href=\""
org-html-klipse-css "\"/>"))
(if havecomments
"<script>\nasync function sendContact(ev) {\nev.preventDefault();\nconst thePage = window.location.href;\nconst senderName = document.getElementById('nameInput').value;\nconst senderAddress = document.getElementById('emailInput').value;\nconst senderSite = document.getElementById('siteInput').value;\nconst senderMessage = document.getElementById('messageInput').value;\nconst gtsUrl = 'https://kes.praze.net/api/v1/statuses';\nconst response = await fetch(gtsUrl, {\nmethod: 'POST',\nheaders: {\n'Content-Type': 'application/json',\n'Authorization': 'Bearer OTBKMDFMMJMTMZNKYY0ZMGQZLWJJMJUTYJE0MMY5ZJK3NJU4',\n},\nbody: JSON.stringify({'status' : 'new comment on ' + thePage + ' from ' + senderName + ' (' + senderAddress + ', ' + senderSite + ')\n\n' + senderMessage}),\n});\nif (response.ok) {\nalert('Comment submitted, thank you!');\n} else {\nalert('This is fucked, sorry. Email me instead, whatever at praze dot net!');\n}\ndocument.getElementById(\"theform\").reset();\n}\n</script>\n")
;; Closing document.
"</body>\n</html>"))
(defun my-html-filter-nobreaks (text backend info)
"Keep non-breaking spaces in HTML org export"
(when (org-export-derived-backend-p backend 'html)
(replace-regexp-in-string " " "&nbsp;" text)))
(if (string-equal system-type "android")
(setq org-export-filter-plain-text-functions
'my-html-filter-nobreaks)
(add-to-list 'org-export-filter-plain-text-functions
'my-html-filter-nobreaks))
(defun my-org-export-add-target-blank-to-http-links (text backend info)
"Add target=\"_blank\" to external links."
(when (and
(org-export-derived-backend-p backend 'html)
(string-match "href=\"http[^\"]+" text)
(not (string-match "target=\"" text)))
(string-match "<a " text)
(replace-match "<a target=\"_blank\" " nil nil text)))
(add-to-list 'org-export-filter-link-functions
'my-org-export-add-target-blank-to-http-links)
(defun my-org-export-correct-file-links (text backend info)
"Remove generated file:// in relative links."
(when (and
(org-export-derived-backend-p backend 'html)
(string-match "href=\"file[^\"]+" text))
(string-match "file://" text)
(replace-match "" nil nil text)))
(add-to-list 'org-export-filter-link-functions
'my-org-export-correct-file-links)