« Module:ZoteroItem » : différence entre les versions
Aucun résumé des modifications |
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 groupId = "4893620" | |||
local data = fetchZoteroData(itemKey) | local data = fetchZoteroData(itemKey) | ||
if not data or not data.data or not data.data.relations then return "" end | if not data or not data.data or not data.data.relations then return "" end | ||
local rel = data.data.relations | local rel = data.data.relations | ||
local out = {} | local out = {} | ||
for k, v in pairs(rel) do | for k, v in pairs(rel) do | ||
if k == "dc:relation" and type(v) == "table" then | |||
for _, zoteroUrl in ipairs(v) do | |||
local id = tostring(zoteroUrl):match("/items/(%w+)$") | |||
elseif type(v) == " | 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 | |||
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 | ||
return table.concat(out, " | |||
if #out > 0 then | |||
return "dc:relation:<ul>" .. table.concat(out, "") .. "</ul>" | |||
end | |||
return "" | |||
end | end | ||
return p | return p | ||