Make metadata accessible from templates
This commit is contained in:
parent
4d59921aee
commit
a6ed61b4eb
1 changed files with 26 additions and 8 deletions
|
@ -1,23 +1,41 @@
|
|||
local vars = {}
|
||||
|
||||
function fileExists(name)
|
||||
local f=io.open(name,"r")
|
||||
if f~=nil then io.close(f) return true else return false end
|
||||
end
|
||||
|
||||
|
||||
local function countWords()
|
||||
local rawText = pandoc.pipe("pdftotext", {"output.pdf", "-"}, "")
|
||||
return pandoc.pipe("wc", {"-w"}, rawText)
|
||||
end
|
||||
|
||||
local function getVars(meta)
|
||||
for k, v in pairs(meta) do
|
||||
if v.t == 'MetaInlines' then
|
||||
vars["$" .. k .. "$"] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
{
|
||||
Meta = function(meta)
|
||||
getVars(meta)
|
||||
if fileExists("output.pdf") then
|
||||
meta["wordcount"] = countWords()
|
||||
meta["secondpass"] = true
|
||||
end
|
||||
return meta
|
||||
end,
|
||||
},
|
||||
{
|
||||
Str = function (el)
|
||||
if vars[el.text] then
|
||||
return pandoc.Span(vars[el.text])
|
||||
else
|
||||
return el
|
||||
end
|
||||
end
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue