about summary refs log tree commit diff
path: root/blog
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-01-23T18·27+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-01-23T21·57+0000
commit81d7bc405eaf631bf58377c629af6d461021bb67 (patch)
tree45668541e03254747419a350f63bf37d29e6ec6c /blog
parentb25d06db7e924effcb304645ab6121aad4b18ce5 (diff)
Extend blog server to consume nix injections
All of this is still a work-in-progress. Just checking in my work.

Also:
- Write function `render-post` to convert a markdown file into HTML. This is
  still a work-in-progress since we need to capture the output and not just have
  it printed to *standard-out*.
- Return dummy data in /posts
Diffstat (limited to 'blog')
-rw-r--r--blog/src/server.lisp39
1 files changed, 38 insertions, 1 deletions
diff --git a/blog/src/server.lisp b/blog/src/server.lisp
index 63323e933bd3..7f669ddd77bf 100644
--- a/blog/src/server.lisp
+++ b/blog/src/server.lisp
@@ -5,6 +5,43 @@
   (:export :main))
 (in-package #:server)
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Nix-injected dependencies
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defvar *path-to-posts* "/tmp"
+  "File path pointing to the posts directory.")
+
+(defvar *pandoc-bin* "/usr/bin/pandoc")
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Library
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defun render-post (path)
+  "Render the markdown file stored at PATH to HTML using pandoc."
+  (uiop:run-program (list *pandoc-bin* path "--to" "html")
+                    :output t))
+
+;; TODO: Figure out how to handle this with Nix.
+(defvar *posts* (uiop:directory-files *path-to-posts*)
+  "List of the paths to the blog posts.")
+
+(hunchentoot:define-easy-handler
+    (get-latest :uri "/latest") ()
+  (print (parameter "name"))
+  (uiop:read-file-string (car *posts*)))
+
+(hunchentoot:define-easy-handler
+    (get-posts :uri "/posts") ()
+  "Working!")
+
 (defun main ()
   "This is the main entrypoint for our application."
-  (hunchentoot))
+  (hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port 4242))
+  (print "Listing on port 4242...")
+  (sb-thread:join-thread
+   (find-if (lambda (th)
+              (string= (sb-thread:thread-name th)
+                       "hunchentoot-listener-*:4242"))
+            (sb-thread:list-all-threads))))