bunbun.dev/page-handler.fnl

20 lines
654 B
Plaintext
Raw Normal View History

2024-05-20 20:23:38 -07:00
(local cmark (require :cmark))
(local lfs (require :lfs))
(local page-handler {})
(fn page-handler.read-pages []
(each [file (lfs.dir :pages)]
(when (and (not= file ".") (not= file ".."))
(local markdown (with-open [markdown-file (io.open (.. :pages/ file) :r)]
(markdown-file:read :*a)))
(local html-template (with-open [html-template-file (io.open :template.html :r)]
(html-template-file:read :*a)))
(local html (cmark.markdown_to_html markdown (markdown:len) cmark.OPT_UNSAFE))
(tset _G.files (file:match "(.+)%..+") (html-template:format html)))))
page-handler