1 ;; Inspiration: https://gitlab.com/ambrevar/ambrevar.gitlab.io.
3 ;; TODO: use git time-stamps
7 (add-to-list 'load-path
".")
9 (add-to-list 'load-path
"../xah-replace-pairs")
10 (require 'xah-replace-pairs
)
12 (defun aminb--readfile (filepath)
13 "Return filepath's content."
15 (insert-file-contents filepath
)
18 (defun aminb--find-replace (match-with replace-with string
)
19 "Return the string resulting from replacing `match-with' with
20 `replace-with' in `string'."
21 (when (string-match match-with string
)
22 (replace-match replace-with nil nil string
)))
24 (defun aminb--my-html-body-light-filter (output backend info
)
25 "Make adjustments needed for dark/light mode <input> tag to work."
26 (when (eq backend
'html
)
32 "<body>\n<input class=\"light-off\" id=\"light-off\" type=\"checkbox\">\n<div class=\"page\">"
35 (add-to-list 'org-export-filter-final-output-functions
36 'aminb--my-html-body-light-filter
)
38 ;; re-defining this (originally in `ox-html.el') to add `?g'
39 (defun org-html-format-spec (info)
40 "Return format specification for preamble and postamble.
41 INFO is a plist used as a communication channel."
42 (let ((timestamp-format (plist-get info
:html-metadata-timestamp-format
))
43 (git-repo "<a href=\"https://git.sr.ht/~aminb/aminb.org/commit/?id=%s\">@%s</a>")
44 (git-rev (shell-command-to-string "git rev-parse HEAD"))
45 (git-rev-short (shell-command-to-string "git rev-parse --short HEAD")))
46 `((?t .
,(org-export-data (plist-get info
:title
) info
))
47 (?s .
,(org-export-data (plist-get info
:subtitle
) info
))
48 (?d .
,(org-export-data (org-export-get-date info timestamp-format
)
50 (?T .
,(format-time-string timestamp-format
))
51 (?a .
,(org-export-data (plist-get info
:author
) info
))
53 (lambda (e) (format "<a href=\"mailto:%s\">%s</a>" e e
))
54 (split-string (plist-get info
:email
) ",+ *")
56 (?g .
,(format git-repo git-rev git-rev-short
))
57 (?c .
,(plist-get info
:creator
))
58 (?C .
,(let ((file (plist-get info
:input-file
)))
59 (format-time-string timestamp-format
60 (and file
(nth 5 (file-attributes file
))))))
61 (?v .
,(or (plist-get info
:html-validation-link
) "")))))
63 ;; timestamps can be used to avoid rebuilding everything
64 ;; should probably be put inside the public/ directory
65 (setq org-publish-use-timestamps-flag t
66 org-publish-timestamp-directory
"./")
68 ;; get rid of index.html~ and other backup files that may be created during generation
69 (setq make-backup-files nil
)
71 (setq org-export-with-section-numbers nil
72 org-export-with-smart-quotes t
73 org-export-with-email t
74 org-export-with-date t
75 org-export-with-tags
'not-in-toc
76 org-export-with-toc t
)
78 (setq org-html-divs
'((preamble "header" "preamble")
79 (content "main" "content")
80 (postamble "footer" "postamble"))
81 ;; TODO: link last update to commit history of file
84 org-html-preamble-format
`(("en" ,(aminb--readfile "partials/preamble.html")))
85 org-html-postamble-format
`(("en" ,(aminb--readfile "partials/postamble.html")))
86 org-html-container-element
"section"
87 org-html-metadata-timestamp-format
"%Y-%m-%d"
88 org-html-checkbox-type
'html
89 org-html-html5-fancy t
91 ;; this removes the dependency on `htmlize',
92 ;; but we also lose syntax highlighting.
93 org-html-htmlize-output-type nil
94 org-html-validation-link nil
95 org-html-doctype
"html5")
97 (setq org-publish-project-alist
100 :base-directory
"./source/"
101 :exclude
"macros.org"
103 :publishing-function
'(org-html-publish-to-html)
104 :publishing-directory
"./public/"
105 :html-head-include-default-style nil
106 :html-head-include-scripts nil
)
108 :base-directory
"source/"
111 :publishing-directory
"./public"
112 :publishing-function
'org-publish-attachment
114 (list "site" :components
'("site-org"))))
116 (defun aminb/publish
()