From 63ea67e4c3c8caa2cf0dc6d7c940981bd40b3974 Mon Sep 17 00:00:00 2001 From: Stanisław Zagórowski Date: Mon, 15 Jan 2024 14:21:34 +0100 Subject: all: move out from luax/ --- blog/cache.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 blog/cache.lua (limited to 'blog/cache.lua') diff --git a/blog/cache.lua b/blog/cache.lua new file mode 100644 index 0000000..e8f5b0c --- /dev/null +++ b/blog/cache.lua @@ -0,0 +1,23 @@ +local md = require "libs.markdown" + +local blog_cache = {} + +local function get_blog_post_content(post) + local slug = post.slug + if blog_cache[slug] then + return blog_cache[slug] + end + -- pull markdown content from file + local content = io.open("blog/" .. slug .. ".md", "r"):read("*a") + + if content then + -- convert markdown to html + content = md(content) + end + + blog_cache[slug] = content + + return content +end + +return get_blog_post_content -- cgit v1.3.1