aboutsummaryrefslogtreecommitdiff
path: root/blog/cache.lua
blob: e8f5b0cf07fbc967a2221539a3ff558d9c7bd339 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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