summaryrefslogtreecommitdiff
path: root/publish.el
blob: a327d028792555a4260bf34202f902cbe55a345c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
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 & 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)