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

Aucun résumé des modifications
Balise : Révoqué
Annulation des modifications 17552 de Marc (discussion)
Balise : Annulation
Ligne 142 : Ligne 142 :


-- Collections
-- Collections
function p.collections(frame)
local itemKey = frame.args[1]
local data = fetchZoteroData(itemKey)
if not data or not data.data or not data.data.collections then return "" end
if #data.data.collections == 0 then return "" end
local out = {}
for _, id in ipairs(data.data.collections) do
table.insert(out, mw.text.nowiki(id))
end
return table.concat(out, ", ")
end
-- Relations
function p.relations(frame)
function p.relations(frame)
local itemKey = frame.args[1]
local itemKey = frame.args[1]
local groupName = "alcolois"
local groupName = "alcolois" -- adapter si besoin
local groupId = "4893620"
local groupId = "4893620"


Ligne 151 : Ligne 164 :


local rel = data.data.relations
local rel = data.data.relations
local urls = {}
local out = {}


for k, v in pairs(rel) do
for k, v in pairs(rel) do
if k == "dc:relation" then
if k == "dc:relation" and type(v) == "table" then
if type(v) == "string" then
for _, zoteroUrl in ipairs(v) do
local id = v:match("/items/(%w+)$")
local id = tostring(zoteroUrl):match("/items/(%w+)$")
if id then
if id then
table.insert(urls, string.format(
local fullUrl = string.format(
"https://www.zotero.org/groups/%s/%s/items/%s",
"https://www.zotero.org/groups/%s/%s/items/%s",
groupId, groupName, id
groupId,
))
groupName,
end
id
elseif type(v) == "table" then
)
for _, url in ipairs(v) do
table.insert(out, '<li><a href="' .. fullUrl .. '" target="_blank">' .. fullUrl .. '</a></li>')
local id = tostring(url):match("/items/(%w+)$")
if id then
table.insert(urls, string.format(
"https://www.zotero.org/groups/%s/%s/items/%s",
groupId, groupName, id
))
end
end
end
end
elseif type(v) == "string" then
-- single relation
local id = v:match("/items/(%w+)$")
if id then
local fullUrl = string.format(
"https://www.zotero.org/groups/%s/%s/items/%s",
groupId,
groupName,
id
)
table.insert(out, '<li><a href="' .. fullUrl .. '" target="_blank">' .. fullUrl .. '</a></li>')
end
end
end
end
end
end


if #urls == 0 then
if #out > 0 then
return ""
return "dc:relation:<ul>" .. table.concat(out, "") .. "</ul>"
end
end


return table.concat(urls, ", ")
return ""
end
end


return p
return p