summaryrefslogtreecommitdiff
path: root/publish.el
diff options
context:
space:
mode:
authorThomas Albers <thomas@thomaslabs.org>2022-07-27 18:13:20 +0200
committerThomas Albers <thomas@thomaslabs.org>2022-07-27 18:13:20 +0200
commit561bac75579391c14e47eaccfabdf9eda98855da (patch)
tree00a65bb3c590a072beb9552ccdea8bfa096b8502 /publish.el
Initial commit
Diffstat (limited to 'publish.el')
-rwxr-xr-xpublish.el205
1 files changed, 205 insertions, 0 deletions
diff --git a/publish.el b/publish.el
new file mode 100755
index 0000000..a327d02
--- /dev/null
+++ b/publish.el
@@ -0,0 +1,205 @@
+#!/usr/bin/env -S emacs -Q --batch --script
+
+(require 'ox)
+(require 'esxml)
+
+(defun thomaslabs-navbar ()
+ (sxml-to-xml
+ `(nav
+ (ul
+ (li (a (@ (href "/"))
+ "Home"))
+ (li (a (@ (href "/z80/"))
+ "Z80"))
+ (li (a (@ (href "/programs/"))
+ "programs"))
+ (li (a (@ (href "/math/"))
+ "math"))
+ (li (a (@ (href "/privacy.html"))
+ "contact &amp; privacy policy"))))))
+
+(defun thomaslabs-footer ()
+ (sxml-to-xml
+ `(footer
+ (p
+ "Copyright © 2021 - 2022 Thomas Albers Raviola"
+ (br)
+ "This website and its contents are published under the
+following licences, unless otherwise specified"
+ (ul
+ (li "Website and images:"
+ (a (@ (href "https://creativecommons.org/licenses/by-nc-sa/4.0/"))
+ "CC BY-NC-SA 4.0"))
+ (li "Schematics:"
+ (a (@ (href "https://creativecommons.org/licenses/by-nc-nd/4.0/"))
+ "CC BY-NC-ND 4.0"))
+ (li "Code:"
+ (a (@ (href "https://www.gnu.org/licenses/gpl-3.0.html"))
+ "GPL-3.0")))))))
+
+(defun thomaslabs-template (contents info)
+ (concat
+ "<!DOCTYPE html>\n"
+ (sxml-to-xml
+ `(html (@ (lang "en"))
+ (head
+ ,(org-html--build-meta-info
+ `(:title ,(if (plist-get info :title)
+ (format "Thomas' Labs | %s" (car (plist-get info :title)))
+ "Thomas' Labs")
+ ,@info))
+ ,(org-html--build-head info))
+ (body
+ ,(if-let ((title (plist-get info :title)))
+ `(header
+ (p "Thomas' Labs")
+ (h1 ,(org-export-data title info)))
+ `(header
+ (h1 "Thomas' Labs")))
+ ,(thomaslabs-navbar)
+ (div (@ (class "content"))
+ (main
+ (article ,contents)))
+ (hr)
+ ,(thomaslabs-footer))))))
+
+(defun math-preamble (&rest args)
+ (sxml-to-xml
+ '(div
+ (h2 "Disclaimer")
+ (p "This site as of now just a technology demonstration and its claims
+should not be taken as true (even though I myself am pretty confident
+they are"))))
+
+(defun math-sitemap (title entries)
+ (concat (format "#+TITLE: %s\n#+SETUPFILE: ../math_options.org\n\n" title)
+ (org-list-to-org entries)))
+
+
+(defun org-local-link-export (link description format info)
+ (format "<a href=\"%s\">%s</a>"
+ link
+ description))
+
+(defun org-img-link-export (link description format info)
+ (message "%s" info)
+ (format "<a href=\"%s\">%s</a>"
+ link
+ description))
+
+(defun org-local-link-follow (&rest args)
+ t)
+
+(org-link-set-parameters "local"
+ :follow #'org-local-link-follow
+ :export #'org-local-link-export)
+
+(org-link-set-parameters "img"
+ :follow #'org-local-link-follow
+ :export #'org-img-link-export)
+
+(org-export-define-derived-backend 'thomaslabs-html 'html
+ :translate-alist
+ '((template . thomaslabs-template)))
+
+(defun thomaslabs-publish-to-html (plist filename pub-dir)
+ "Publish an org file to HTML, using the FILENAME as the output directory."
+ (org-publish-org-to 'thomaslabs-html
+ filename
+ ".html"
+ plist
+ pub-dir))
+
+(setq org-publish-project-alist
+ `(("thomaslabs_html"
+ :base-directory "~/Code/websites/thomaslabs/src"
+ :publishing-directory "/srv/web/thomaslabs"
+ :publishing-function thomaslabs-publish-to-html
+ :with-toc nil
+ :recursive t
+
+ :language "en_US"
+
+ :html-head-include-default-style nil
+ :html-head-include-scripts nil
+ :html-preamble nil
+ :html-postamble nil
+ :html-use-infojs nil
+ :html-html5-fancy t
+ :html-doctype "html5"
+ :with-toc nil
+ :section-numbers nil
+ :with-latex dvisvgm)
+
+ ("math_html"
+ :base-directory "~/Code/websites/thomaslabs/math"
+ :publishing-directory "/srv/web/thomaslabs/math"
+ :publishing-function thomaslabs-publish-to-html
+ :with-toc nil
+ :recursive t
+
+ :language "en_US"
+
+ :html-head-include-default-style nil
+ :html-head-include-scripts nil
+ :html-preamble math-preamble
+ :html-postamble nil
+ :html-use-infojs nil
+ :html-html5-fancy t
+ :html-doctype "html5"
+ :with-toc nil
+
+ :auto-sitemap t
+ :sitemap-filename "index.org"
+ :sitemap-title "Math and Physics articles"
+ :sitemap-function math-sitemap
+
+ :section-numbers nil
+ :with-latex dvisvgm)
+
+ ("math_svg"
+ :base-directory "~/Code/websites/thomaslabs/math/ltximg"
+ :base-extension "svg"
+ :publishing-directory "/srv/web/thomaslabs/math/ltximg"
+ :publishing-function org-publish-attachment)
+
+ ("math_css"
+ :base-directory "~/Code/websites/thomaslabs/math"
+ :base-extension "css"
+ :publishing-directory "/srv/web/thomaslabs"
+ :publishing-function org-publish-attachment)
+
+ ("thomaslabs_css"
+ :base-directory "~/Code/websites/thomaslabs/src"
+ :base-extension "css"
+ :publishing-directory "/srv/web/thomaslabs"
+ :publishing-function org-publish-attachment)
+
+ ("thomaslabs_media"
+ :base-directory "~/Code/websites/thomaslabs/media"
+ :base-extension "jpg\\|gif\\|png"
+ :publishing-directory "/srv/web/thomaslabs/media"
+ :publishing-function org-publish-attachment)
+
+ ("thomaslabs"
+ :components ("thomaslabs_html"
+ "thomaslabs_media"
+ "thomaslabs_css"))
+
+ ("thomaslabs_math"
+ :components ("math_html"
+ "math_css"
+ "math_svg"))))
+
+(plist-put org-format-latex-options :html-foreground "#cccccc")
+
+(org-publish "thomaslabs" t)
+(org-publish "thomaslabs_math" t)
+
+;; (let ((opt "--delete -Prlpte 'ssh -p 1764'")
+;; (src "'/srv/web/thomaslabs/'")
+;; (dst "'root@thomaslabs.org:/var/www/math/'"))
+;; (call-process-shell-command (format "rsync %s %s %s" opt src dst)))
+
+;; (org-publish "thomaslabs" t)
+;; (org-publish "math_svg" t)