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
297
298
299
300
|
;;; emacsconf-pad.el --- Working with Etherpad -*- lexical-binding: t; -*-
;; Copyright (C) 2022 Sacha Chua
;; Author: Sacha Chua <sacha@sachachua.com>
;; Keywords: convenience
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Prepopulate the Etherpad
(defcustom emacsconf-pad-base "https://pad.emacsconf.org/"
"Base URL for the Etherpad. Include trailing slash.
Use \"wikimedia\" to use etherpad.wikimedia.org instead."
:group 'emacsconf
:type 'string)
(defcustom emacsconf-pad-api-key nil
"API key for authenticating against the Etherpad.
You can find it in $ETHERPAD_PATH/APIKEY.txt"
:group 'emacsconf
:type 'string)
(defcustom emacsconf-pad-slug-base (concat emacsconf-year)
"Base for the pad IDs"
:group 'emacsconf
:type 'string)
(defcustom emacsconf-pad-directory ""
"Set to /p/ if you don't have friendly URLs set up in the proxy."
:group 'emacsconf
:type 'string)
;;; Code:
(defun emacsconf-pad-delete-pad (pad-id)
(interactive "MPad ID: ")
(switch-to-buffer (url-retrieve-synchronously (format "%sapi/1/deletePad?apikey=%s&padID=%s" emacsconf-pad-base emacsconf-pad-api-key pad-id))))
(defun emacsconf-pad-json-request (url &optional display-result)
(with-current-buffer (url-retrieve-synchronously url)
(goto-char (point-min))
(re-search-forward "^$")
(let ((result (json-read)))
(when display-result (prin1 result))
(kill-buffer)
result)))
(defun emacsconf-pad-create-pad (pad-id)
(interactive "MPad ID: ")
(emacsconf-pad-json-request (format "%sapi/1/createPad?apikey=%s&padID=%s" emacsconf-pad-base
(url-hexify-string emacsconf-pad-api-key)
(url-hexify-string pad-id))
(called-interactively-p 'any)))
(defun emacsconf-pad-delete-pad (pad-id)
(interactive "MPad ID: ")
(emacsconf-pad-json-request (format "%sapi/1/deletePad?apikey=%s&padID=%s" emacsconf-pad-base
(url-hexify-string emacsconf-pad-api-key)
(url-hexify-string pad-id))
(called-interactively-p 'any)))
(defun emacsconf-pad-get-text (pad-id)
(interactive "MPad ID: ")
(emacsconf-pad-json-request (format "%sapi/1/getText?apikey=%s&padID=%s" emacsconf-pad-base
(url-hexify-string emacsconf-pad-api-key)
(url-hexify-string pad-id))
(called-interactively-p 'any)))
(defun emacsconf-pad-set-text (pad-id text)
(interactive "MPad ID: \nMText: ")
(emacsconf-pad-json-request (format "%sapi/1/setText?apikey=%s&padID=%s&text=%s"
emacsconf-pad-base
(url-hexify-string emacsconf-pad-api-key)
(url-hexify-string pad-id)
(url-hexify-string text))
(called-interactively-p 'any)))
(defun emacsconf-pad-append-text (pad-id text)
(interactive "MPad ID: \nMText: ")
(emacsconf-pad-json-request (format "%sapi/1/appendText?apikey=%s&padID=%s&text=%s"
emacsconf-pad-base
(url-hexify-string emacsconf-pad-api-key)
(url-hexify-string pad-id)
(url-hexify-string text))
(called-interactively-p 'any)))
(defun emacsconf-pad-get-html (pad-id)
(interactive "MPad ID: ")
(emacsconf-pad-json-request (format "%sapi/1/getHTML?apikey=%s&padID=%s"
emacsconf-pad-base
(url-hexify-string emacsconf-pad-api-key)
(url-hexify-string pad-id))
(called-interactively-p 'any)))
(defun emacsconf-pad-set-html (pad-id html)
(interactive "MPad ID: \nMHTML: ")
(let ((url-request-data (concat "html=" (url-hexify-string html)))
(url-request-method "POST")
(url-request-extra-headers '(("Content-Type" . "application/x-www-form-urlencoded"))))
(emacsconf-pad-json-request (format "%sapi/1/setHTML?apikey=%s&padID=%s"
emacsconf-pad-base
(url-hexify-string emacsconf-pad-api-key)
(url-hexify-string pad-id))
(called-interactively-p 'any))))
;; (emacsconf-pad-append-text "emacsconf-2022-journalism" "Hello again")
;; (emacsconf-pad-get-html "emacsconf-2022-journalism")
;; (emacsconf-pad-set-html "emacsconf-2022-journalism" "<div><strong>Hello</strong> world</div>")
(defun emacsconf-pad-get-last-edited (pad-id)
(interactive "MPad ID: ")
(emacsconf-pad-json-request (format "%sapi/1/getLastEdited?apikey=%s&padID=%s"
emacsconf-pad-base
(url-hexify-string emacsconf-pad-api-key)
(url-hexify-string pad-id))
(called-interactively-p 'any)))
(defun emacsconf-pad-id (o)
(concat emacsconf-pad-slug-base "-" (plist-get o :slug)))
(defun emacsconf-pad-url (o)
(if (string= emacsconf-pad-base "wikimedia")
(format "https://etherpad.wikimedia.org/p/emacsconf-%s-%s"
emacsconf-year
(plist-get o :slug))
(concat emacsconf-pad-base emacsconf-pad-directory (emacsconf-pad-id o))))
(defvar emacsconf-pad-number-of-next-talks 3 "Integer limiting the number of next talks to link to from the pad.")
(defun emacsconf-pad-initial-content (o)
(emacsconf-replace-plist-in-string
(append (list :base-url emacsconf-base-url
:channel (concat "emacsconf-" (plist-get (emacsconf-get-track (plist-get o :track)) :id))
:bbb-info
(cond
((null (plist-get o :q-and-a))
"<div>Q&A: none</div>")
((string-match "live" (plist-get o :q-and-a))
(format "<div>Q&A room: %s</div>" (plist-get o :bbb-redirect)))
(t "<div>Q&A: IRC</div>"))
:next-talk-list
(if (plist-get o :next-talks)
(concat "<div>Next talks:\n<ul>"
(mapconcat
(lambda (o)
(format "<li>%s: %s %s</li>"
(plist-get o :track)
(plist-get o :title)
(emacsconf-pad-url o)))
(plist-get o :next-talks)
"\n")
"</ul></div>")
"")
:track-id
(plist-get (emacsconf-get-track (plist-get o :track)) :id)
:watch
(concat emacsconf-base-url emacsconf-year "/watch/" (plist-get (emacsconf-get-track (plist-get o :track)) :id) "/")
:talks
(concat emacsconf-base-url emacsconf-year "/talks/")
:notes
(string-join (make-list 6 "<li></li>"))
:questions
(string-join (make-list 6 "<li>Q: <ul><li>A: </li></ul></li>"))
:conf-pad-url
(concat "https://pad.emacsconf.org/" emacsconf-year)
:irc-nick-details
(if (plist-get o :irc)
(concat "Speaker nick: " (plist-get o :irc) " - ")
"")
:irc-url (concat "" ))
o)
"<div>
<div>All talks: ${talks}</div>
<div><strong>${title}</strong></div>
<div>${base-url}${url} - ${speakers} - Track: ${track}</div>
<div>Watch/participate: ${watch}</div>
${bbb-info}
<div>IRC: ${irc-nick-details} https://chat.emacsconf.org/#/connect?join=emacsconf,emacsconf-${track-id} or #emacsconf-${track-id} on libera.chat network</div>
<div>Guidelines for conduct: ${base-url}conduct</div>
<div>See end of file for license (CC Attribution-ShareAlike 4.0 + GPLv3 or later)</div>
<div>----------------------------------------------------------------</div>
<div>Notes, discussions, links, feedback:</div>
<ul>${notes}</ul>
<div>----------------------------------------------------------------</div>
<div>Questions and answers go here:</div>
<ul>${questions}</ul>
<div>----------------------------------------------------------------</div>
${next-talk-list}
<div>Questions/comments related to EmacsConf ${year} as a whole? ${conf-pad-url}
<div>----------------------------------------------------------------</div>
<div>This pad will be archived at ${base-url}${url} after the conference.</div>
<div>Except where otherwise noted, the material on the EmacsConf pad are dual-licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International Public License; and the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) an later version. Copies of these two licenses are included in the EmacsConf wiki repository, in the COPYING.GPL and COPYING.CC-BY-SA files (https://emacsconf.org/COPYING/)</div>
<div>By contributing to this pad, you agree to make your contributions available under the above licenses. You are also promising that you are the author of your changes, or that you copied them from a work in the public domain or a work released under a free license that is compatible with the above two licenses. DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION.</div></div>"))
(defun emacsconf-pad-prepopulate-main-pad ()
(interactive)
(let ((pad-id emacsconf-year))
(emacsconf-pad-create-pad pad-id)
(emacsconf-pad-set-html
pad-id
(emacsconf-replace-plist-in-string
(list
:base-url emacsconf-base-url
:notes (string-join (make-list 6 "<li></li>"))
:questions
(string-join (make-list 6 "<li>Q: <ul><li>A: </li></ul></li>"))
:year emacsconf-year)
"<div><strong>EmacsConf ${year}</strong> - this pad is for general conference-related questions and feedback</div>
<div>All talks: ${base-url}${year}/talks - see specific talk pages for links to their Etherpads</div>
<div>Conference hallway IRC channel: https://chat.emacsconf.org/#/connect?join=emacsconf or #emacsconf on libera.chat network</div>
<div>Organizers channel: https://chat.emacsconf.org/#/connect?join=emacsconf,emacsconf-org or #emacsconf-org on libera.chat network</div>
<div>Guidelines for conduct: ${base-url}conduct</div>
<div>See end of file for license (CC Attribution-ShareAlike 4.0 + GPLv3 or later)</div>
<div>----------------------------------------------------------------</div>
<div>Notes, discussions, links, feedback: </div>
<ul>${notes}</ul>
<div>----------------------------------------------------------------</div>
<div>Questions and answers go here:</div>
<ul>${questions}</ul>
<div>----------------------------------------------------------------</div>
<div>This pad will be archived at ${base-url}${url} after the conference.</div>
<div>Except where otherwise noted, the material on the EmacsConf pad are dual-licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International Public License; and the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) an later version. Copies of these two licenses are included in the EmacsConf wiki repository, in the COPYING.GPL and COPYING.CC-BY-SA files (https://emacsconf.org/COPYING/)</div>
<div>By contributing to this pad, you agree to make your contributions available under the above licenses. You are also promising that you are the author of your changes, or that you copied them from a work in the public domain or a work released under a free license that is compatible with the above two licenses. DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION.</div></div>"))))
(defvar emacsconf-pad-force-all nil "Set to t to clear everything.")
(defun emacsconf-pad-prepopulate-talk-pad (o)
(interactive (list (let ((info (emacsconf-include-next-talks (emacsconf-get-talk-info) emacsconf-pad-number-of-next-talks)))
(emacsconf-complete-talk-info info))))
(let ((pad-id (emacsconf-pad-id o)))
(emacsconf-pad-create-pad pad-id)
(when (or emacsconf-pad-force-all
(not (emacsconf-pad-modified-p pad-id))
(progn
(browse-url (emacsconf-pad-url o))
(y-or-n-p (format "%s might have been modified. Reset? " (plist-get o :slug)))))
(emacsconf-pad-set-html
pad-id
(emacsconf-pad-initial-content o))
(save-window-excursion
(emacsconf-with-talk-heading (plist-get o :slug)
(let-alist (emacsconf-pad-get-last-edited pad-id)
(org-entry-put (point) "PAD_RESET" (number-to-string .data.lastEdited))))))))
(defun emacsconf-pad-prepopulate-all-talks (&optional info)
(interactive)
(mapc #'emacsconf-pad-prepopulate-talk-pad
(emacsconf-include-next-talks (or info (emacsconf-get-talk-info)) emacsconf-pad-number-of-next-talks)))
(defun emacsconf-pad-export-initial-content (o file)
(interactive
(list (let ((info (emacsconf-include-next-talks (emacsconf-get-talk-info) emacsconf-pad-number-of-next-talks)))
(emacsconf-complete-talk-info info))
(read-file-name "Output file: ")))
(when (file-directory-p file) (setq file (expand-file-name (concat (plist-get o :slug) ".html") file)))
(with-temp-file file
(insert (emacsconf-pad-initial-content o))))
(defun emacsconf-pad-export-initial-content-for-all-talks (dir &optional info)
(interactive (list (read-file-name "Output directory: " nil nil nil nil 'file-directory-p)))
(setq info (emacsconf-include-next-talks (or info (emacsconf-get-talk-info))
emacsconf-pad-number-of-next-talks))
(mapcar (lambda (o)
(emacsconf-pad-export-initial-content o dir))
(emacsconf-active-talks (emacsconf-filter-talks info))))
(defmacro emacsconf-pad-with-heading (pad-id &rest body)
(declare (indent 1) (debug t))
`(progn
(with-current-buffer (find-file emacsconf-org-file)
(goto-char (org-find-property "CUSTOM_ID"
(if (string-match "^[0-9]+-\\(.*\\)$" ,pad-id)
(match-string 1 ,pad-id)
"meta")))
,@body)))
(defun emacsconf-pad-modified-p (pad-id)
(save-window-excursion
(save-excursion
(let ((cached-last-modified (emacsconf-pad-with-heading pad-id (org-entry-get (point) "PAD_RESET")))
(result (emacsconf-pad-get-last-edited pad-id)))
(let-alist result
(not (string= cached-last-modified
(number-to-string .data.lastEdited))))))))
(provide 'emacsconf-pad)
;;; emacsconf-pad.el ends here
|