robin/maivi

a tiny cute lua web framework

git clone https://git.robinwobin.dev/robin/maivi

robindocs: meow1be4c9c

push-srxvuswpkqxx
562 B26 linesraw
1local md4c ---@module 'md4c'
2
3do
4  local ok
5  ok, md4c = pcall(require, "md4c")
6  if not ok then
7    error(("could not initialise markdown plugin:\n\t%s"):format(md4c))
8    return
9  end
10end
11
12local function skip_frontmatter(str)
13  if string.sub(str, 0, 3) ~= "+++" then
14    return str
15  end
16
17  local pat = "\n+++"
18  local i = string.find(str, pat)
19  return string.sub(str, i and i + #pat or 0)
20end
21
22maivi.hook("read_data", { pattern = "%.md$" }, function(ctx)
23  local content = skip_frontmatter(ctx.content)
24  local ret = md4c.tohtml(content)
25  ctx:use(ret)
26end)