« Module:ZoteroData » : différence entre les versions
Création du module |
Nouvelle mouture -> Erreur Lua dans Module:ZoteroData à la ligne 5: bad argument #1 to 'encode' (string expected, got nil). |
||
| Ligne 2 : | Ligne 2 : | ||
function p.getZoteroItemsFromTitle(frame) | function p.getZoteroItemsFromTitle(frame) | ||
local title = frame.args["title"] | local title = frame.args["title"] or frame.args[1] | ||
if not title or title == "" then | |||
return "Erreur : aucun titre fourni." | |||
end | |||
local url = "https://api.zotero.org/groups/4893620/items?q=" .. mw.uri.encode(title) .. "&qmode=everything&format=json" | local url = "https://api.zotero.org/groups/4893620/items?q=" .. mw.uri.encode(title) .. "&qmode=everything&format=json" | ||
| Ligne 16 : | Ligne 20 : | ||
} | } | ||
} | } | ||
if not data or #data == 0 then | |||
return "Aucun résultat trouvé pour « " .. title .. " »." | |||
end | |||
local html = mw.html.create("table"):addClass("wikitable sortable") | local html = mw.html.create("table"):addClass("wikitable sortable") | ||
| Ligne 27 : | Ligne 35 : | ||
for _, item in ipairs(data) do | for _, item in ipairs(data) do | ||
local row = html:tag("tr") | local row = html:tag("tr") | ||
row:tag("td"):wikitext(item.key) | row:tag("td"):wikitext(item.key or "") | ||
row:tag("td"):wikitext(item.title) | row:tag("td"):wikitext(item.title or "") | ||
row:tag("td"):wikitext(item.creators) | row:tag("td"):wikitext(item.creators or "") | ||
row:tag("td"):wikitext(item.date) | row:tag("td"):wikitext(item.date or "") | ||
row:tag("td"):wikitext(item.type) | row:tag("td"):wikitext(item.type or "") | ||
end | end | ||