« 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 | local out = {} | ||
for k, v in pairs(rel) do | for k, v in pairs(rel) do | ||
if k == "dc:relation" | if k == "dc:relation" and type(v) == "table" then | ||
for _, zoteroUrl in ipairs(v) do | |||
local id = | local id = tostring(zoteroUrl):match("/items/(%w+)$") | ||
if id then | if id then | ||
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, | |||
id | |||
) | |||
table.insert(out, '<li><a href="' .. fullUrl .. '" target="_blank">' .. fullUrl .. '</a></li>') | |||
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 # | if #out > 0 then | ||
return "" | return "dc:relation:<ul>" .. table.concat(out, "") .. "</ul>" | ||
end | end | ||
return | return "" | ||
end | end | ||
return p | return p | ||