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.
This commit is contained in:
William Carroll 2020-01-31 16:13:22 +00:00
parent 837cfe07c7
commit 265d202908
3 changed files with 17 additions and 13 deletions

View file

@ -19,6 +19,7 @@ in depot.nix.buildLisp.program {
deps = with depot.third_party.lisp; with briefcase.third_party.lisp; [ deps = with depot.third_party.lisp; with briefcase.third_party.lisp; [
hunchentoot hunchentoot
cl-arrows cl-arrows
cl-ppcre
]; ];
srcs = [ srcs = [
./src/server.lisp ./src/server.lisp

View file

@ -3,14 +3,12 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Showcase of AI bots at DeepMind" /> <meta name="description" content="wpcarro.dev | blog" />
<link rel="stylesheet" href="/index.css"> <title>wpcarro.dev | blog</title>
<title>AI Showcase</title>
<script data-ad-client="ca-pub-6018268443649487" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script data-ad-client="ca-pub-6018268443649487" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>
<h1>Welcome</h1> {{ blog }}
<p>To my blog!</p>
</body> </body>
</html> </html>

View file

@ -2,6 +2,7 @@
(defpackage #:server (defpackage #:server
(:documentation "Robot condemned to a life of admin work for my blog.") (:documentation "Robot condemned to a life of admin work for my blog.")
(:use #:cl) (:use #:cl)
(:use #:cl-ppcre)
(:import-from #:cl-arrows #:->>) (:import-from #:cl-arrows #:->>)
(:export :main)) (:export :main))
(in-package #:server) (in-package #:server)
@ -10,25 +11,29 @@
;; Nix-injected dependencies ;; 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/" (defvar *path-to-posts* "/tmp/"
"File path pointing to the posts directory.") "File path pointing to the posts directory.")
(defvar *pandoc-bin* "/usr/bin/pandoc") (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 ;; 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) (defun render-post (path)
"Render the markdown file stored at PATH to HTML using pandoc." "Render the markdown file stored at PATH to HTML using pandoc."
(uiop:run-program (list *pandoc-bin* path "--to" "html") (cl-ppcre:regex-replace-all
:output :string)) "{{ blog }}"
(uiop:read-file-string *html-template*)
;; TODO: Figure out how to handle this with Nix. (uiop:run-program (list *pandoc-bin* path "--to" "html") :output :string)))
(defvar *posts* (uiop:directory-files *path-to-posts*)
"List of the paths to the blog posts.")
(hunchentoot:define-easy-handler (hunchentoot:define-easy-handler
(get-latest :uri "/latest") () (get-latest :uri "/latest") ()