-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish.el
296 lines (251 loc) · 10.1 KB
/
publish.el
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
;; package --- Summary:
;; org-publish.el --- publish related org-mode files as a website
;;; Commentary:
;;;
;;; How to run this:
;;; * eval the buffer
;;; * M-x site-publish
;;;
(require 'citeproc)
(require 'find-lisp)
(require 'htmlize)
(require 'oc-csl)
(require 'org)
(require 'org-roam)
(require 'org-roam-export)
(require 'ox)
(require 'ox-html)
(require 'ox-publish)
(require 'ox-rss)
;;; org-babel configuration
;;; Functions:
;;;; http://xahlee.info/emacs/emacs/elisp_read_file_content.html
(defun get-string-from-file (filePath)
"Return file content as string from FILEPATH."
(with-temp-buffer
(insert-file-contents filePath)
(buffer-string)))
(defun patch-string-with-path (str filePath n)
"Patch a STR with FILEPATH and do so N times."
(apply 'format str (make-list n filePath)))
(defun patch-list-with-prefix (prefix strings)
"Prepend PREFIX to every string in STRINGS."
(mapcar (lambda (s) (concat prefix s)) strings))
;;;; Taken from:
;;;; https://commonplace.doubleloop.net/publish.el
(defun notes/generate-backlinks (backend backlinks)
"Insert BACKLINKS into org file before parsing it, targets BACKEND."
(when (org-roam-node-at-point)
(goto-char (point-max))
;; Add a new header for the links
(insert "* Backlinks:\n")
(dolist (backlink backlinks)
(let* ((source-node (org-roam-backlink-source-node backlink))
(point (org-roam-backlink-point backlink)))
(insert
(format "- [[./%s][%s]]\n"
(file-name-nondirectory (org-roam-node-file source-node))
(org-roam-node-title source-node)))))))
(defun notes/collect-backlinks (backend)
"Generate backlinks if they exist at all, targets BACKEND."
(when (org-roam-node-at-point)
(goto-char (point-max))
(let* ((backlinks (org-roam-backlinks-get (org-roam-node-at-point))))
(cond ((if (eq nil backlinks) t nil)
(message "Ignoring backlink generation..."))
(t (notes/generate-backlinks backend backlinks))))))
(defun notes/add-extra-sections (backend)
"Insert extra sections on a note BACKEND before being published."
(when (org-roam-node-at-point)
(save-excursion
(goto-char (point-max))
(insert "\n* References:\n#+print_bibliography:\n")
(notes/collect-backlinks backend))))
;;;; Only to be used within CI environments, to generate the ORG-ROAM db
(defun notes/generate-sqlite-db ()
"Bootstraps the ORG-ROAM db."
(cond ((if (string= (getenv "IS_CI") "1") t nil)
(progn (message "Running ORG-ROAM DB sync")
(org-roam-db-sync)))
(t (message "Not running on CI, ignoring block"))))
;;;; CV-related
(defun cv/org-cv-publish-resume (file dest)
"Publish FILE using org-cv moderncv to DEST."
(setq-default outfile "cv.tex")
(setq-default outpdf "cv.pdf")
(message (format "CHECK IF CV %s EXISTS: %s" file (file-exists-p file)))
(with-current-buffer
(find-file-noselect file)
(org-mode)
(message "CV OUTFILE: %S" outfile)
(org-export-to-file 'moderncv outfile)
(org-latex-compile "cv.tex"))
(copy-file outpdf dest t))
;;; Project variables:
;;;; don't ask for confirmation before evaluating a code block
(setq org-confirm-babel-evaluate nil)
(setq org-export-use-babel t)
(setq org-export-with-broken-links nil)
(setq org-element-use-cache nil)
(setq org-src-preserve-indentation t)
(setq org-src-fontify-natively t)
;;;; No need for backup files
(setq make-backup-files nil)
;; Don't show validation link
(setq org-html-validation-link t)
;; Use our own scripts
(setq org-html-head-include-scripts nil)
;; Use our own styles
(setq org-html-head-include-default-style nil)
;;;; Settings
(setq-default root-dir (concat (getenv "PWD") "/"))
(setq-default static-dir (concat root-dir "static"))
(setq-default static-html-dir (concat static-dir "/" "html"))
(setq-default static-img-dir (concat static-dir "/" "img"))
(setq-default static-css-dir (concat static-dir "/" "css"))
(setq-default org-blog-dir (concat root-dir "blog"))
(setq-default org-roam-dir (concat root-dir "notes"))
(setq-default bibtex-dir (concat root-dir "refs"))
(message (format "SETTING ROOT DIR: %s" root-dir))
(message (format "SETTING STATIC DIR: %s" static-dir))
(message (format "SETTING BLOG DIR: %s" org-blog-dir))
(message (format "SETTING NOTES DIR: %s" org-roam-dir))
(message (format "SETTING BIBTEX DIR: %s" bibtex-dir))
(defcustom out-dir (format "%spublic" root-dir) "Directory where the HTML files are going to be exported.")
(message (format "SETTING OUT DIR: %s" out-dir))
(setq-default url-dir (if (string= (getenv "ENVIRONMENT") "dev") out-dir "https://schonfinkel.github.io"))
(message (format "SETTING URL: %s" url-dir))
(setq-default out-rss-dir (concat out-dir "/" "blog"))
(setq-default out-static-dir (concat out-dir "/static/"))
(setq-default out-css-dir (concat out-static-dir "css"))
(setq-default out-img-dir (concat out-static-dir "img"))
(setq-default out-html-dir (concat out-static-dir "html"))
(setq-default out-blog-dir (concat out-dir "/blog"))
(setq-default out-notes-dir (concat out-dir "/notes"))
;;;; Fix bibliography
(setq org-cite-refs-list '("articles.bib"
"beam.bib"
"classic_studies.bib"
"databases.bib"
"fp_general.bib"
"haskell.bib"
"leadership.bib"
"math_and_logic.bib"
"nixos.bib"
"software_engineering.bib"
"sysadmin.bib"))
(setq org-cite-refs-path (patch-list-with-prefix (concat bibtex-dir "/") org-cite-refs-list))
(setq org-cite-global-bibliography org-cite-refs-path)
(setq org-cite-export-processors '((latex biblatex)
(moderncv basic)
(html csl)
(t csl)))
;;;; Org-Roam Settings
(setq org-roam-directory org-roam-dir)
(setq org-roam-db-location (concat org-roam-dir "/org-roam.db"))
(message (format "SETTING OUT ORG-ROAM DB LOCATION: %s" org-roam-db-location))
;;;; Adds backlinks to the notes
(add-hook 'org-export-before-processing-hook 'notes/add-extra-sections)
;; RSS
(setq org-rss-use-entry-url-as-guid nil)
;;;; Customize the HTML output
(setq-default html-head-prefix-file (get-string-from-file (concat static-html-dir "/" "header.html")))
(setq-default html-head-prefix (patch-string-with-path html-head-prefix-file url-dir 1))
(message (format "HTML PREFIX: %s" html-head-prefix))
(setq-default website-html-head html-head-prefix)
(setq-default html-nav-file (get-string-from-file (concat static-html-dir "/" "nav.html")))
(setq-default html-nav (patch-string-with-path html-nav-file url-dir 7))
(message (format "HTML NAV: %s" html-nav))
(setq-default website-html-preamble html-nav)
(setq-default html-footer (get-string-from-file (concat static-html-dir "/" "footer.html")))
(message (format "HTML FOOTER: %s" html-footer))
(setq-default website-html-postamble html-footer)
;;; Code:
(setq org-publish-project-alist
`(("site"
:base-directory ,root-dir
:base-extension "org"
:publishing-directory ,out-dir
:publishing-function org-html-publish-to-html
:title "Benevides' Blog"
:author "Marcos Benevides"
:email "(concat \"marcos.schonfinkel\" \"@\" \"gmail.com\")"
:recursive t
:with-creator t
:with-tags t
:with-title t
:with-toc nil
:with-date t
:export-with-tags t
:exclude-tags ("todo" "noexport")
:exclude "cv.org\\|level-.*\\|.*\.draft\.org\\|.direnv*"
:section-numbers nil
:headline-levels 5
:auto-sitemap nil
:sitemap-filename "index.org"
:sitemap-title "Home"
:sitemap-sort-files anti-chronologically
:sitemap-file-entry-format "%d - %t"
:sitemap-style list
:html-doctype "html5"
:html-html5-fancy t
:html-divs ((preamble "header" "preamble")
(content "main" "content")
(postamble "footer" "postamble"))
:html-head ,website-html-head
:html-preamble ,website-html-preamble
:html-postamble ,website-html-postamble)
("rss"
:base-directory ,org-blog-dir
:publishing-directory ,out-dir
:html-link-home ,(concat url-dir "/blog")
:html-link-use-abs-url t
:rss-extension "xml"
:publishing-function (org-rss-publish-to-rss)
:section-numbers nil
:table-of-contents nil)
("images"
:base-directory ,static-img-dir
:base-extension "png\\|jpg\\|gif"
:publishing-directory ,out-img-dir
:recursive t
:publishing-function org-publish-attachment)
("css"
:base-directory ,static-css-dir
:base-extension "css"
:publishing-directory ,out-css-dir
:recursive t
:publishing-function org-publish-attachment)
("html"
:base-directory ,static-html-dir
:base-extension "html"
:publishing-directory ,out-html-dir
:recursive t
:publishing-function org-publish-attachment)
("other"
:base-directory ,static-dir
:base-extension "json\\|xml\\|pdf"
:publishing-directory ,out-static-dir
:recursive t
:publishing-function org-publish-attachment)
("all" :components ("css" "images" "html" "other" "rss" "site"))))
;; Generate CV output
;;; We need to keep a local copy of org-cv
;;; and use only "moderncv".
(setq-default org-cv-path (concat root-dir "org-cv/"))
(setq-default cv-path (concat root-dir "cv.org"))
(setq-default cv-out (concat static-dir "/" "cv.pdf"))
(message (format "ORG-CV LIB PATH: %s" org-cv-path))
(message (format "ORG CV PATH: %s" cv-path))
(message (format "PDF CV PATH: %s" cv-out))
(use-package ox-moderncv
:load-path org-cv-path
:init (require 'ox-moderncv))
(cv/org-cv-publish-resume cv-path cv-out)
(message "CV build complete!")
;; Generate the site output
(notes/generate-sqlite-db)
(org-roam-update-org-id-locations)
(org-publish-all t)
(message "Website build complete!")
;;; publish.el ends here