--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/templates.lua Tue Mar 09 12:16:56 2021 +0000 @@ -0,0 +1,30 @@ +local lfs = require "lfs"; + +local function readfile(filename) + local fh = assert(io.open(filename)); + local data = fh:read("*a"); + fh:close(); + return data; +end + +local _M = {}; + +local template_base_path = (os.getenv("TEMPLATE_PATH") or ".").."/"; + +function _M.init(config) + local templates = {}; + + local template_path = template_base_path..(config.templates or "html"); + + for filename in lfs.dir(template_path) do + local template_name = filename; + if filename:match("%.html$") then + template_name = filename:gsub("%.html$", ""); + end + templates[template_name] = readfile(template_path.."/"..filename); + end + + return templates; +end + +return _M;