Matches the existing frontmatter.lua memoization pattern. Avoids re-dofile'ing markdown.lua per successful load_for call (matters once L.9 rolls out manifest.launcher.md to every module and the init-time call count goes from 1 to N).
34 lines
996 B
Lua
34 lines
996 B
Lua
local M = {}
|
|
|
|
local fm, md
|
|
|
|
local function ensure_deps()
|
|
if not fm then
|
|
fm = dofile(engine.module.dir_of("lib-management.launcher") .. "/frontmatter.lua")
|
|
end
|
|
if not md then
|
|
md = dofile(engine.module.dir_of("lib-management.launcher") .. "/markdown.lua")
|
|
end
|
|
end
|
|
|
|
-- Returns:
|
|
-- meta = { summary, description_md, author, tags, teaser_images,
|
|
-- carousel_interval_seconds, ... }
|
|
-- body_blocks = output of markdown.parse(body) — pre-parsed for cache reuse
|
|
-- On any failure (file missing, parse error): meta = {}, body_blocks = {}.
|
|
function M.load_for(module_id)
|
|
ensure_deps()
|
|
local content, err = engine.module.read_file(module_id, "manifest.launcher.md")
|
|
if not content then
|
|
return { _missing = true, _err = err }, {}
|
|
end
|
|
local meta, body, perr = fm.parse(content)
|
|
if not meta then
|
|
return { _missing = false, _err = perr }, {}
|
|
end
|
|
local blocks = md.parse(body)
|
|
return meta, blocks
|
|
end
|
|
|
|
return M
|