summaryrefslogtreecommitdiff
path: root/publish.el
diff options
context:
space:
mode:
Diffstat (limited to 'publish.el')
-rwxr-xr-xpublish.el205
1 files changed, 120 insertions, 85 deletions
diff --git a/publish.el b/publish.el
index a327d02..6786c7d 100755
--- a/publish.el
+++ b/publish.el
@@ -15,6 +15,8 @@
"programs"))
(li (a (@ (href "/math/"))
"math"))
+ (li (a (@ (href "https://git.thomaslabs.org"))
+ "git"))
(li (a (@ (href "/privacy.html"))
"contact & privacy policy"))))))
@@ -22,7 +24,7 @@
(sxml-to-xml
`(footer
(p
- "Copyright © 2021 - 2022 Thomas Albers Raviola"
+ "Copyright © 2021 - 2023 Thomas Albers Raviola"
(br)
"This website and its contents are published under the
following licences, unless otherwise specified"
@@ -51,9 +53,14 @@ following licences, unless otherwise specified"
,(org-html--build-head info))
(body
,(if-let ((title (plist-get info :title)))
- `(header
- (p "Thomas' Labs")
- (h1 ,(org-export-data title info)))
+ (let ((subtitle (plist-get info :subtitle)))
+ `(header
+ (div "Thomas' Labs")
+ (h1 ,(org-export-data title info))
+ ,@(if subtitle
+ `((div (@ (class "subtitle"))
+ ,(car subtitle)))
+ '())))
`(header
(h1 "Thomas' Labs")))
,(thomaslabs-navbar)
@@ -72,7 +79,8 @@ 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)
+ (concat "#+title: " title "\n"
+ "#+setupfile: ../../math_options.org\n\n"
(org-list-to-org entries)))
@@ -82,7 +90,6 @@ they are"))))
description))
(defun org-img-link-export (link description format info)
- (message "%s" info)
(format "<a href=\"%s\">%s</a>"
link
description))
@@ -98,6 +105,18 @@ they are"))))
:follow #'org-local-link-follow
:export #'org-img-link-export)
+(defvar root-dir (expand-file-name ""))
+
+(defun org-export-file-uri (filename)
+ "Return file URI associated to FILENAME."
+ (cond ((not (file-name-absolute-p filename))
+ (string-remove-prefix "site" filename))
+ ((string-suffix-p ".jpg" filename)
+ (concat "/img-small" (string-remove-prefix "/img" filename)))
+ (t
+ (string-remove-prefix (concat root-dir "/site")
+ (expand-file-name filename)))))
+
(org-export-define-derived-backend 'thomaslabs-html 'html
:translate-alist
'((template . thomaslabs-template)))
@@ -110,96 +129,112 @@ they are"))))
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
+(defun image-dimensions (pathname)
+ (with-temp-buffer
+ (call-process "identify" nil (current-buffer) nil
+ "-ping" "-format" "%wx%h" pathname)
+ (mapcar #'cl-parse-integer (split-string (buffer-string) "x"))))
+
+(defun resize-image (factor input output)
+ (let ((percentage (format "%.01f%%" (* 100.0 factor))))
+ (call-process "convert" nil nil nil input "-resize" percentage output)))
+
+(defun thomaslabs-publish-image (_plist filename pub-dir)
+ (unless (file-directory-p pub-dir)
+ (make-directory pub-dir t))
+ (let ((output (expand-file-name (file-name-nondirectory filename) pub-dir)))
+ (unless (file-equal-p (expand-file-name (file-name-directory filename))
+ (file-name-as-directory (expand-file-name pub-dir)))
+ (let* ((dimensions (image-dimensions filename))
+ (width (cl-first dimensions))
+ (height (cl-second dimensions))
+ (factor (min (/ 800.0 width) (/ 800.0 height) 1.0)))
+ (resize-image factor filename output)))
+ ;; Return file name.
+ output))
+
+(defun org-html--wrap-latex-environment (contents _ &optional caption label)
+ "Wrap CONTENTS string within appropriate environment for equations.
+When optional arguments CAPTION and LABEL are given, use them for
+caption and \"id\" attribute."
+ (format "\n<div%s class=\"equation-container\">\n%s%s\n</div>"
+ ;; ID.
+ (if (org-string-nw-p label) (format " id=\"%s\"" label) "")
+ ;; Contents.
+ (format "<span class=\"equation\">\n%s\n</span>" contents)
+ ;; Caption.
+ (if (not (org-string-nw-p caption)) ""
+ (format "\n<span class=\"equation-label\">(%s)</span>"
+ caption))))
+
+(defvar default-html-project-properties
+ '(:publishing-function thomaslabs-publish-to-html
+ :with-toc nil
+ :recursive nil
+
+ :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))
- :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"
+(setq org-publish-project-alist
+ `(("root"
+ :base-directory "src"
+ :publishing-directory "site"
+ ,@default-html-project-properties)
+ ("arm"
+ :base-directory "src/arm"
+ :publishing-directory "site/arm"
+ ,@default-html-project-properties
+ :recursive t)
+ ("programs"
+ :base-directory "src/programs"
+ :publishing-directory "site/programs"
+ ,@default-html-project-properties
+ :recursive t)
+ ("z80"
+ :base-directory "src/z80"
+ :publishing-directory "site/z80"
+ ,@default-html-project-properties
+ :recursive t)
+
+ ("math"
+ :base-directory "src/math"
+ :publishing-directory "site/math"
:publishing-function thomaslabs-publish-to-html
- :with-toc nil
- :recursive t
+ ,@(org-plist-delete default-html-project-properties :html-preamble)
- :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)
+ :sitemap-function math-sitemap)
- ("thomaslabs"
- :components ("thomaslabs_html"
- "thomaslabs_media"
- "thomaslabs_css"))
+ ("img"
+ :base-directory "site/img"
+ :publishing-directory "site/img-small"
+ :base-extension "png\\|jpg\\|gif"
+ :recursive t
+ :publishing-function thomaslabs-publish-image)
- ("thomaslabs_math"
- :components ("math_html"
- "math_css"
- "math_svg"))))
-(plist-put org-format-latex-options :html-foreground "#cccccc")
+ ("thomaslabs"
+ :components ("root" "arm" "programs" "z80" "math" "img"))))
-(org-publish "thomaslabs" t)
-(org-publish "thomaslabs_math" t)
+;; (plist-put org-format-latex-options :html-foreground "#cccccc")
+(plist-put org-format-latex-options :html-foreground "#000000")
-;; (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)))
+(setq org-publish-timestamp-directory (concat (getenv "XDG_CACHE_HOME") "/org-timestamps/"))
+(setq org-preview-latex-image-directory (expand-file-name "site/svg"))
+(setq org-html-htmlize-output-type 'css)
-;; (org-publish "thomaslabs" t)
-;; (org-publish "math_svg" t)
+(org-publish "thomaslabs" t)
+;; fork ox-html?