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

Annulation des modifications 17552 de Marc (discussion)
Balise : Annulation
Aucun résumé des modifications
Ligne 157 : Ligne 157 :
function p.relations(frame)
function p.relations(frame)
local itemKey = frame.args[1]
local itemKey = frame.args[1]
local groupName = "alcolois" -- adapter si besoin
local groupName = "alcolois"
local groupId = "4893620"
local groupId = "4893620"


Ligne 164 : Ligne 164 :


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


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


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