about summary refs log tree commit diff
path: root/web/panettone
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2021-04-06T12·59+0200
committersterni <sternenseemann@systemli.org>2021-04-06T16·34+0000
commit63a0b28bea0cd2829334a880bbdf930c78fd9866 (patch)
tree2ea5e53691d9efb86f8aaa4452c123d906ddbe9e /web/panettone
parentc28d9710d6b84c682f6f6f3001f97e18703fb28a (diff)
refactor(panettone): remove code duplication in render-markdown r/2448
Move the common part (encoding/decoding json and connecting to cheddar)
into request-markdown-from-cheddar. The two render-markdown
implementations are now only thin wrappers around that function.

Change-Id: I81bb34b684af44228dcad02fca541082e6d060ce
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2868
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'web/panettone')
-rw-r--r--web/panettone/src/panettone.lisp33
1 files changed, 13 insertions, 20 deletions
diff --git a/web/panettone/src/panettone.lisp b/web/panettone/src/panettone.lisp
index 10d501d8aea9..52908e147835 100644
--- a/web/panettone/src/panettone.lisp
+++ b/web/panettone/src/panettone.lisp
@@ -8,11 +8,10 @@
    "Render the argument, or the elements of the argument, as markdown, and return
    the same structure"))
 
-(defmethod render-markdown ((markdown string))
-  (cdr
-   (assoc :markdown
-          (cl-json:decode-json
-           (drakma:http-request
+(defun request-markdown-from-cheddar (input)
+  "Send the CL value INPUT encoded as JSON to cheddar's
+  markdown endpoint and return the decoded response."
+  (let ((s (drakma:http-request
             (concatenate 'string
                          *cheddar-url*
                          "/markdown")
@@ -21,24 +20,18 @@
             :content-type "application/json"
             :external-format-out :utf-8
             :external-format-in :utf-8
-            :content (json:encode-json-to-string
-                      `((markdown . ,markdown)))
-            :want-stream t)))))
+            :content (json:encode-json-to-string input)
+            :want-stream t)))
+    (cl-json:decode-json s)))
+
+(defmethod render-markdown ((markdown string))
+  (cdr (assoc :markdown
+              (request-markdown-from-cheddar
+               `((markdown . ,markdown))))))
 
 (defmethod render-markdown ((markdown hash-table))
   (alist-hash-table
-   (cl-json:decode-json
-    (drakma:http-request
-     (concatenate 'string
-                  *cheddar-url*
-                  "/markdown")
-     :accept "application/json"
-     :method :post
-     :content-type "application/json"
-     :external-format-out :utf-8
-     :external-format-in :utf-8
-     :content (json:encode-json-to-string markdown)
-     :want-stream t))))
+   (request-markdown-from-cheddar markdown)))
 
 (defun markdownify-comment-bodies (comments)
   "Convert the bodies of the given list of comments to markdown in-place using