From 265d2029088a1f49c5716bcb3d96f71dd0845d7e Mon Sep 17 00:00:00 2001 From: William Carroll Date: Fri, 31 Jan 2020 16:13:22 +0000 Subject: Render pandoc output to index.html Using index.html allows us to use the Google AdSense script and extend the styling by adding a CSS stylesheet. --- blog/default.nix | 1 + blog/src/index.html | 8 +++----- blog/src/server.lisp | 21 +++++++++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'blog') diff --git a/blog/default.nix b/blog/default.nix index 1b1cc3974805..ace295385da4 100644 --- a/blog/default.nix +++ b/blog/default.nix @@ -19,6 +19,7 @@ in depot.nix.buildLisp.program { deps = with depot.third_party.lisp; with briefcase.third_party.lisp; [ hunchentoot cl-arrows + cl-ppcre ]; srcs = [ ./src/server.lisp diff --git a/blog/src/index.html b/blog/src/index.html index a9d9cf7eaa25..2ea07d35ade6 100644 --- a/blog/src/index.html +++ b/blog/src/index.html @@ -3,14 +3,12 @@ - - - AI Showcase + + wpcarro.dev | blog -

Welcome

-

To my blog!

+ {{ blog }} diff --git a/blog/src/server.lisp b/blog/src/server.lisp index ad8169fa1af9..d2633a2dbd7b 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) + (:use #:cl-ppcre) (:import-from #:cl-arrows #:->>) (:export :main)) (in-package #:server) @@ -10,25 +11,29 @@ ;; 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") +(defvar *html-template* "./index.html" + "The path to the HTML template used for the blog posts.") + +(defvar *posts* (uiop:directory-files *path-to-posts*) + "List of the paths to the blog posts.") + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Library ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; TODO: Support properly indenting the output from pandoc to nest within the +;; template. Or just use a proper templating 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.") + (cl-ppcre:regex-replace-all + "{{ blog }}" + (uiop:read-file-string *html-template*) + (uiop:run-program (list *pandoc-bin* path "--to" "html") :output :string))) (hunchentoot:define-easy-handler (get-latest :uri "/latest") () -- cgit 1.4.1