Module:ZoteroItem
La documentation pour ce module peut être créée à Module:ZoteroItem/doc
-- Module:ZoteroItem
local p = {}
-- Fonction principale : passez seulement itemKey
function p.getItem(frame)
local key = frame.args[1]
if not key or key == "" then
return "Erreur : veuillez fournir un itemKey (exemple : XNXIG5JQ)"
end
-- ID de votre groupe Zotero (modifiez-le si différent)
local groupId = "4893620"
-- Construction de l'URL complète vers l'API Zotero
local url = mw.uri.encode(
"https://api.zotero.org/groups/" .. groupId .. "/items/" .. key .. "?format=json&include=data"
)
-- Appel HTTP via External Data
local data, errs = mw.ext.externalData.getWebData{
url = url,
format = "JSON"
}
if errs then
return "Erreur lors de la récupération Zotero : " .. table.concat(errs, "; ")
end
local json = data.__json
if not json or not json.data then
return "Aucun item avec la clé " .. mw.text.escape(key)
end
-- Extrait les champs souhaités
local d = json.data
local title = mw.text.escape(d.title or d.caseName or "(sans titre)")
local authors = {}
if d.creators then
for _, c in ipairs(d.creators) do
table.insert(authors, mw.text.escape((c.firstName or "") .. " " .. (c.lastName or "")))
end
end
local dateDecided = mw.text.escape(d.dateDecided or "")
local abstractNote = mw.text.escape(d.abstractNote or "")
local urlField = mw.text.escape(d.url or "")
-- Production du HTML
local out = {}
table.insert(out, "<strong>Titre :</strong> " .. title)
if #authors > 0 then
table.insert(out, "<br><strong>Auteurs :</strong> " .. table.concat(authors, ", "))
end
if dateDecided ~= "" then
table.insert(out, "<br><strong>Date décidée :</strong> " .. dateDecided)
end
if abstractNote ~= "" then
table.insert(out, "<br><strong>Résumé :</strong> " .. abstractNote)
end
if urlField ~= "" then
table.insert(out, '<br><strong>Lien :</strong> <a href="' .. urlField .. '" target="_blank">Voir sur CanLII</a>')
end
return table.concat(out)
end
return p