« Module:ModSkyrim » : différence entre les versions
De La Confrérie des Traducteurs
(Page créée avec « local p = {} local function fetchJson(id) local url = 'https://www.confrerie-des-traducteurs.fr/api/skyrim/mods/' .. id local response = mw.http.fetch(url) if not response or response.status ~= 200 then return nil end return mw.text.jsonDecode(response.body) end function p.main(frame) local id = frame.args['id'] if not id then return 'Mod ID manquant.' end local data = fetchJson(id) if not data then return 'Impossibl... ») |
(Aucune différence)
|
Version du 5 mai 2025 à 10:18
La documentation pour ce module peut être créée à Module:ModSkyrim/doc
local p = {}
local function fetchJson(id)
local url = 'https://www.confrerie-des-traducteurs.fr/api/skyrim/mods/' .. id
local response = mw.http.fetch(url)
if not response or response.status ~= 200 then
return nil
end
return mw.text.jsonDecode(response.body)
end
function p.main(frame)
local id = frame.args['id']
if not id then return 'Mod ID manquant.' end
local data = fetchJson(id)
if not data then return 'Impossible de récupérer les données pour l’ID ' .. id end
-- Récupération de la preview
local img = ''
for _, imgData in ipairs(data.Images or {}) do
if imgData.IsPreview then
img = imgData.Url
break
end
end
local html = mw.html.create('div'):addClass('modskyrim-box')
if img ~= '' then
html:tag('div'):addClass('modskyrim-thumb')
:tag('img')
:attr('src', img)
:attr('alt', data.Name)
:attr('style', 'max-width: 120px; height: auto; margin-right: 10px; float: left;')
end
local content = html:tag('div'):addClass('modskyrim-info')
content:tag('b'):wikitext(data.Name)
if data.OriginalName and data.OriginalName ~= data.Name then
content:tag('span'):wikitext(' (Titre original : ' .. data.OriginalName .. ')')
end
content:tag('div'):wikitext("**Auteur(s)** : " .. table.concat(data.Authors or {}, ', '))
content:tag('div'):wikitext(data.MiniDescription or '')
return tostring(html)
end
return p