diff options
author | William Carroll <wpcarro@gmail.com> | 2020-01-23T21·58+0000 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-01-23T22·01+0000 |
commit | 6108f8df0140e2f71c9f9b50d530d16400d9cdcb (patch) | |
tree | 8d1fcc3c535cf9e449ec1d114d407391b3ee1de8 | |
parent | 2e3bb0435f2849e2a5d4da0ed8408c2993ca9052 (diff) |
Support proof-of-concept blog
After some toil, I have a working proof-of-concept blog. The idea is simple: write blog posts in markdown and store the posts in the `./posts` directory. Then use the server and `pandoc` to convert these markdown files into HTML at request time. I'm using nix to package everything together. It's far from perfect, but it works at the moment, which is encouraging.
-rw-r--r-- | blog/default.nix | 11 | ||||
-rw-r--r-- | blog/src/server.lisp | 10 | ||||
-rw-r--r-- | default.nix | 5 |
3 files changed, 16 insertions, 10 deletions
diff --git a/blog/default.nix b/blog/default.nix index ed1e405ddca4..5359a0ab6f37 100644 --- a/blog/default.nix +++ b/blog/default.nix @@ -1,23 +1,24 @@ { - pkgs ? import <nixpkgs> {}, + nixpkgs ? import <nixpkgs> {}, depot ? import <depot> {}, universe ? import <universe> {}, ... }: let - injectedPosts = pkgs.writeText "posts.lisp" '' + injectedPosts = nixpkgs.writeText "posts.lisp" '' (in-package #:server) (setq *path-to-posts* "${./posts}") ''; - injectedExecutables = pkgs.writeText "executables.lisp" '' + injectedExecutables = nixpkgs.writeText "executables.lisp" '' (in-package #:server) - (setq *pandoc-bin* "${pkgs.pandoc}/bin/pandoc") + (setq *pandoc-bin* "${nixpkgs.pandoc}/bin/pandoc") ''; in depot.nix.buildLisp.program { name = "server"; - deps = with depot.third_party.lisp; [ + deps = with depot.third_party.lisp; with universe.third_party.lisp; [ hunchentoot + cl-arrows ]; srcs = [ ./src/server.lisp diff --git a/blog/src/server.lisp b/blog/src/server.lisp index 7f669ddd77bf..ad8169fa1af9 100644 --- a/blog/src/server.lisp +++ b/blog/src/server.lisp @@ -2,6 +2,7 @@ (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) @@ -9,7 +10,9 @@ ;; Nix-injected dependencies ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defvar *path-to-posts* "/tmp" +;; 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") @@ -21,7 +24,7 @@ (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)) + :output :string)) ;; TODO: Figure out how to handle this with Nix. (defvar *posts* (uiop:directory-files *path-to-posts*) @@ -29,8 +32,7 @@ (hunchentoot:define-easy-handler (get-latest :uri "/latest") () - (print (parameter "name")) - (uiop:read-file-string (car *posts*))) + (render-post (concatenate 'string *path-to-posts* "/" "test.md"))) (hunchentoot:define-easy-handler (get-posts :uri "/posts") () diff --git a/default.nix b/default.nix index d1fb88e04f93..ff31279941ae 100644 --- a/default.nix +++ b/default.nix @@ -15,8 +15,11 @@ let readTree' = import /home/wpcarro/depot/nix/readTree {}; + # TODO: Find a better way to expose entire monorepo without introducing + # "infinite recursion". localPkgs = readTree: { - third_party = readTree ./third_party; + blog = readTree ./blog; + third_party = readTree ./third_party; }; in fix(self: { config = config self; |