Add markdown post rendering

This commit is contained in:
heyarne 2021-07-07 20:33:27 +02:00
commit 905931b815
4 changed files with 23 additions and 6 deletions

View file

@ -7,7 +7,7 @@
pkgs = nixpkgs.legacyPackages.${platform}; pkgs = nixpkgs.legacyPackages.${platform};
in { in {
devShell.${platform} = pkgs.mkShell { devShell.${platform} = pkgs.mkShell {
buildInputs = [ pkgs.janet ]; buildInputs = with pkgs; [ janet multimarkdown ];
}; };
}; };
} }

View file

@ -1,14 +1,24 @@
(import janet-html :as html) (import janet-html :as html)
(import path)
(defn as-html [h] (defn as-html [h]
(html/encode (html/doctype :html5) h)) (html/encode (html/doctype :html5) [:html h]))
(bagatto/set-output-dir! "site") (bagatto/set-output-dir! "site")
(def img-path-copier (bagatto/path-copier "static")) (def data {:config {:attrs {:title "arnes.space"}}
:posts {:src (bagatto/slurp-* "posts/*.md")
:attrs bagatto/parse-mmarkdown}})
(def data {:dogs {:src (bagatto/* "images/*") (defn header [data]
:attrs bagatto/parse-base}}) [:head
[:meta {:charset "utf-8"}]
[:title (get-in data [:config :title])]])
(def site {:index {:dest "index.html" (def site {:index {:dest "index.html"
:out (fn [_] (as-html [:h1 "Hello World!"]))}}) :out (fn [data]
(as-html [(header data) [:body [:h1 "Hello World"]]]))}
:posts {:each :posts
:dest (bagatto/%p "posts" '%i "title" '% ".html")
:out (fn [data item]
(as-html [(header data) [:body (html/raw (bagatto/mmarkdown->html (item :contents)))]]))}})

View file

@ -0,0 +1,6 @@
title: Let There Be Light
some: frontmatter
---
# Hello World
This is an example post.

View file

@ -0,0 +1 @@
Oh wowzers, this is coming from within another file!