blob: 83dd7aea6ac40b583a81819af0cff16b6c18cb90 (
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
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
|
#+title: Org static blog
#+PROPERTY: header-args :tangle no :comments yes :results silent
* Vars and setup
#+begin_src emacs-lisp
(jao-load-path "org-static-blog")
(when (> emacs-major-version 26) (use-package htmlize :ensure t))
(defvar jao-blog-base-dir "~/doc/jao.io")
(defun jao-blog-dir (p) (expand-file-name p jao-blog-base-dir))
(setq jao-org-blog-tag-files
(seq-difference (directory-files (jao-blog-dir "blog") nil "tag-.*")
"tag-norss.html")
jao-org-blog-tags
(mapcar (lambda (f)
(string-match "tag-\\(.+\\)\\.html" f)
(format "<a href=\"/blog/%s\">%s</a>"
f (match-string 1 f)))
jao-org-blog-tag-files)
jao-org-blog-tag-rss
(mapcar (lambda (f)
(string-match "\\(.+\\)-rss\\.xml" f)
(format "<a href=\"/blog/%s\">%s</a>"
f (match-string 1 f)))
(directory-files (jao-blog-dir "blog") nil ".*-rss.xml"))
jao-org-blog-tag-names
(mapcar (lambda (f)
(string-match "tag-\\(.+\\)\\.html" f)
(match-string 1 f))
jao-org-blog-tag-files))
#+end_src
* HTML headers and footers
*** Header
#+begin_src emacs-lisp
(setq org-static-blog-page-header
(concat
"<meta name=\"author\" content=\"jao\">\n"
"<meta name=\"referrer\" content=\"no-referrer\">\n"
"<link rel=\"stylesheet\" href=\"/static/style.css\""
" type=\"text/css\">\n"
"<link rel=\"apple-touch-icon\" sizes=\"180x180\""
" href=\"/static/apple-touch-icon.png\" >\n"
"<link rel=\"icon\" type=\"image/png\""
" sizes=\"32x32\" href=\"/static/favicon-32x32.png\">\n"
"<link rel=\"icon\" type=\"image/png\""
" sizes=\"16x16\" href=\"/static/favicon-16x16.png\">\n"
"<link rel=\"icon\" href=\"/static/favicon.ico\">\n"
"<link rel=\"manifest\" href=\"/static/site.webmanifest\">\n")
org-static-blog-page-preamble
(concat
"<div class=\"header\">"
" <a href=\"https://jao.io\">programming (and other) musings</a>"
" <div class=\"sitelinks\">"
" <a href=\"/blog/about.html\">about</a>"
" | <a href=\"/blog/hacking.html\">hacking</a>"
" | <a href=\"/blog/archive.html\">archive</a>"
" | <div class=\"dropdown\">"
" <a href=\"/blog/tags.html\" class=\"dropbtn\">tags</a>"
" <div class=\"dropdown-content\">"
(mapconcat #'identity jao-org-blog-tags "")
" </div>"
" </div>"
" | <div class=\"dropdown\">"
" <a href=\"/blog/rss.xml\" class=\"dropbtn\">rss</a>"
" <div class=\"dropdown-content\">"
(mapconcat #'identity jao-org-blog-tag-rss "")
" </div>"
" </div>"
" </div>"
"</div>"))
#+end_src
*** Footer
#+begin_src html :tangle ~/.emacs.d/commons.html :comments no
<center>
<a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">
<img alt="Creative Commons License" style="border-width:0"
src="https://i.creativecommons.org/l/by-sa/3.0/88x31.png" />
</a>
<br />
<span xmlns:dct="https://purl.org/dc/terms/"
href="https://purl.org/dc/dcmitype/Text" property="dct:title"
rel="dct:type">jao.io</span> by
<a xmlns:cc="https://creativecommons.org/ns#" href="https://jao.io"
property="cc:attributionName" rel="cc:attributionURL">jao</a>
is licensed under a
<a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">
Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.
</center>
#+end_src
#+begin_src emacs-lisp
(setq org-static-blog-page-postamble
(with-temp-buffer
(insert-file-contents "~/.emacs.d/commons.html")
(buffer-string)))
#+end_src
* Package
#+begin_src emacs-lisp
(use-package org-static-blog
:ensure t
:init
(setq org-static-blog-use-preview nil
org-static-blog-preview-link-p t
org-static-blog-index-length 10
org-static-blog-preview-convert-titles t
org-static-blog-preview-ellipsis "more ..."
org-static-blog-enable-tags t
org-static-blog-tags-file "tags.html"
org-static-blog-rss-file "rss.xml"
org-static-blog-publish-url "https://jao.io/blog/"
org-static-blog-publish-title "programming (and other) musings"
org-static-blog-posts-directory (jao-blog-dir "posts/")
org-static-blog-drafts-directory (jao-blog-dir "drafts/")
org-static-blog-publish-directory (jao-blog-dir "blog/")
org-static-blog-rss-extra "" ; "<author>mail@jao.io</author>\n"
org-static-blog-rss-max-entries 30
org-static-blog-rss-excluded-tag "norss"
org-static-blog-enable-tag-rss t
org-export-with-toc nil
org-export-with-section-numbers nil)
:config
(defun jao-org-static-post-path (pf dt)
(cond ((string-match-p "pages/.*" pf) (file-name-nondirectory pf))
((string-match-p "drafts/.*" pf) pf)
((string-match-p "^[[:digit:]]+-.*" pf) pf)
(t (concat (format-time-string "%Y-%m-%d-" dt)
(file-name-nondirectory pf)))))
(advice-add 'org-static-blog-generate-post-path :override
#'jao-org-static-post-path)
:bind (("H-s-b" . jao-hydra-org-blog/body)
:map org-mode-map (("C-c B" . jao-hydra-org-blog/body))))
#+end_src
* Commands
*** New entries
#+begin_src emacs-lisp
(defun jao-org-blog-publish-file (fname)
(interactive (list (read-file-name "Publish: "
nil
(buffer-file-name)
t
(buffer-file-name))))
(let ((geiser-active-implementations '(guile))
(geiser-default-implementation 'guile))
(org-static-blog-publish-file fname)))
(defun jao-org-static-blog-next-sundry ()
(require 'rst)
(let* ((nos (mapcar (lambda (d)
(string-match ".*-\\([ixvldc]+\\)\\.org" d)
(rst-roman-to-arabic (match-string 1 d)))
(directory-files org-static-blog-posts-directory
nil
"in-no-particular-order")))
(n (rst-arabic-to-roman (+ 1 (car (sort nos #'>))))))
(format "in no particular order %s" (downcase n))))
(defun jao-org-static-blog-create-new-post (&optional draft)
(interactive)
(let* ((kind (completing-read "Kind: " '(regular book sundry)))
(title (if (string= "sundry" kind)
(jao-org-static-blog-next-sundry)
(read-string "Title: ")))
(file (replace-regexp-in-string "\s" "-" (downcase title))))
(find-file (expand-file-name (concat file ".org")
(if draft
org-static-blog-drafts-directory
org-static-blog-posts-directory)))
(insert "#+title: " title "\n"
"#+date: " (format-time-string "<%Y-%m-%d %H:%M>") "\n"
"#+filetags: ")
(cond ((string= "book" kind)
(insert "books\n\n[[https://jao.io/img/" file ".jpg]]\n\n"))
((string= "sundry" kind)
(insert "sundry\n\nInteresting bits elsewhere:\n\n- "))
(t (insert (completing-read "Tag: " jao-org-blog-tag-names)
"\n\n")))))
#+end_src
*** Drafts
#+begin_src emacs-lisp
(defun jao-org-static-blog-create-new-draft ()
(interactive)
(jao-org-static-blog-create-new-post t))
(defun jao-org-static-blog-publish-draft ()
(interactive)
(let* ((from (read-file-name "Post: "
org-static-blog-drafts-directory
nil t))
(to (expand-file-name (file-name-nondirectory from)
org-static-blog-posts-directory)))
(rename-file from to)
(when-let ((b (get-buffer from)))
(kill-buffer b))
(find-file to)
(when (y-or-n-p "Update date? ")
(goto-char (point-min))
(when (re-search-forward "^#\\+date: " nil t)
(let ((kill-whole-line nil)) (kill-line))
(insert (format-time-string "<%Y-%m-%d %H:%M>"))
(save-buffer)))
(when (y-or-n-p "Generate HTML? ")
(jao-org-blog-publish))))
(defun jao-org-static-blog-edit-draft ()
(interactive)
(find-file (read-file-name "Edit: "
org-static-blog-drafts-directory
nil
t)))
#+end_src
*** Publish
#+begin_src emacs-lisp
(defun jao-org-blog-publish (&optional force)
(interactive "P")
(let ((geiser-active-implementations '(guile))
(geiser-default-implementation 'guile))
(org-static-blog-publish force)))
(defun jao-org-blog-republish ()
(interactive)
(jao-org-blog-publish t))
#+end_src
* Hydras
#+begin_src emacs-lisp
(pretty-hydra-define jao-hydra-org-blog (:color blue :quit-key "q")
("Edit"
(("n" jao-org-static-blog-create-new-post "create post")
("d" jao-org-static-blog-create-new-draft "create draft")
("e" jao-org-static-blog-edit-draft "edit draft"))
"Publish"
(("D" jao-org-static-blog-publish-draft "publish draft")
("f" jao-org-blog-publish-file "publish single file")
("p" jao-org-blog-publish "publish all")
("r" jao-org-blog-republish "republish"))))
(major-mode-hydra-define+ org-mode nil
("Utilities" (("b" jao-hydra-org-blog/body "Blog ops"))))
#+end_src
|