diff options
author | William Carroll <wpcarro@gmail.com> | 2020-01-29T14·43+0000 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-01-29T14·43+0000 |
commit | 5c9079a41059e077f2b71b68eb83ff9fcb2e38d1 (patch) | |
tree | dce7e3566b04213228fb3c92fc593ca18841d972 /blog/src/server.lisp | |
parent | fb9380ba268b3cd27372acadb87b14cc96163374 (diff) |
Splice ./universe directory into ./
Manually merging: - README.md: I added the description from universe/README.md into the heading of dotfiles/README.md. - .envrc: dotfiles/.envrc was a superset of universe/.envrc - .gitignore: Adding some of the ignored patterns from universe/.gitignore to dotfiles/.gitignore Everything else here should be a simple rename.
Diffstat (limited to 'blog/src/server.lisp')
-rw-r--r-- | blog/src/server.lisp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/blog/src/server.lisp b/blog/src/server.lisp new file mode 100644 index 000000000000..ad8169fa1af9 --- /dev/null +++ b/blog/src/server.lisp @@ -0,0 +1,49 @@ +(in-package #:cl-user) +(defpackage #:server + (:documentation "Robot condemned to a life of admin work for my blog.") + (:use #:cl) + (:import-from #:cl-arrows #:->>) + (:export :main)) +(in-package #:server) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Nix-injected dependencies +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; TODO: Wrap this in an assert or ensure that there's a trailing slash so it's +;; treated as a directory. +(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 :string)) + +;; 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") () + (render-post (concatenate 'string *path-to-posts* "/" "test.md"))) + +(hunchentoot:define-easy-handler + (get-posts :uri "/posts") () + "Working!") + +(defun main () + "This is the main entrypoint for our application." + (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)))) |