« Module:ZoteroItem » : différence entre les versions

Aucun résumé des modifications
Aucun résumé des modifications
Ligne 206 : Ligne 206 :


return table.concat(urls, ", ")
return table.concat(urls, ", ")
end
function p.notes(frame)
local itemKey = frame.args[1]
if not itemKey or itemKey == "" then return "" end
local url = string.format(
"https://api.zotero.org/groups/4893620/items/%s/children?format=json&include=data",
mw.uri.encode(itemKey)
)
local data, errors = mw.ext.externalData.getExternalData{
url = url,
format = "JSON",
data = { notes = "__json" }
}
if errors or not data or not data.notes then
return ""
end
local output = {}
for _, item in ipairs(data.notes) do
if item.data and item.data.itemType == "note" then
local noteHtml = item.data.note or ""
local url = (item.links and item.links.alternate and item.links.alternate.href) or ""
if noteHtml ~= "" then
table.insert(output, mw.text.nowiki(noteHtml))
end
if url ~= "" then
table.insert(output, mw.text.nowiki(url))
end
end
end
return table.concat(output, "\n\n")
end
end
return p
return p