Skip to content

Commit dfc0b92

Browse files
committed
Add ability to execute code in blog entries
1 parent e4f47d8 commit dfc0b92

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/blog/entry.lisp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
(title "Untitled")
4545
time
4646
expiry-time
47-
paragraphs
47+
body-function
4848
score
4949
score-update-time)
5050

@@ -111,8 +111,7 @@
111111

112112
(my-defun entry story-ml ()
113113
(<div :class "blog-entry-story"
114-
(loop for p in (my paragraphs)
115-
do (<p (output-raw-ml p)))))
114+
(funcall (my body-function))))
116115

117116
(my-defun entry comments ()
118117
(datastore-retrieve-indexed 'comment 'entry-index-name (my index-name)))
@@ -193,10 +192,24 @@
193192
(setf (entry-channel-entry channel) me))))
194193

195194
(my-defun entry read-paragraphs-from-buffer (buffer)
196-
(setf (my paragraphs)
197-
(split-into-paragraphs
198-
(match-replace-all buffer
199-
("${static-base}" (byte-vector-cat (blog-static-base-url (my blog)) (my name)))))))
195+
(cond ((if-match-bind ((* (space)) "(progn") buffer)
196+
(setf (my body-function)
197+
(compile (gensym (my name))
198+
`(lambda ()
199+
(with-ml-output
200+
,(let ((*package* (find-package '#:tpd2.blog-user))) (read-from-string (force-string buffer)))
201+
)))
202+
))
203+
(t
204+
(let ((paragraphs
205+
(split-into-paragraphs
206+
(match-replace-all buffer
207+
("${static-base}" (byte-vector-cat (blog-static-base-url (my blog)) (my name)))))))
208+
(setf (my body-function)
209+
(lambda ()
210+
(with-ml-output
211+
(loop for p in paragraphs
212+
do (<p (output-raw-ml p))))))))))
200213

201214
(defun parse-time (str)
202215
(match-bind

src/packages.lisp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@
430430
(:nicknames #:tpd2.blog)
431431
(:use #:cl #:tpd2.webapp #:tpd2.ml #:tpd2.ml.html #:tpd2.lib #:tpd2.datastore))
432432

433+
(defpackage #:teepeedee2.blog-user
434+
(:nicknames #:tpd2.blog-user)
435+
(:use #:cl #:tpd2.webapp #:tpd2.ml #:tpd2.ml.html #:tpd2.lib))
436+
433437
(defpackage #:teepeedee2.survey
434438
(:nicknames #:tpd2.survey)
435439
(:use #:cl #:tpd2.webapp #:tpd2.ml #:tpd2.ml.html #:tpd2.lib #:tpd2.datastore))

0 commit comments

Comments
 (0)