« Module:ImageDuJour » : différence entre les versions
Apparence
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 1 : | Ligne 1 : | ||
local p = {} | local p = {} | ||
-- Récupère une image aléatoire depuis Modèle:Liste/ImagesDuJour | |||
function p.afficher(frame) | function p.afficher(frame) | ||
local listeTitle = mw.title.new("Modèle:Liste/ImagesDuJour") | |||
local | if not listeTitle or not listeTitle.exists then | ||
return "<span style='color:red;'>Erreur : la liste des images n'existe pas.</span>" | |||
end | |||
if not contenu | local contenu = listeTitle:getContent() | ||
return "<span style='color: | if not contenu then | ||
return "<span style='color:red;'>Erreur : contenu inaccessible.</span>" | |||
end | end | ||
local | local fichiers = {} | ||
for ligne in mw.text.gsplit(contenu, "\n", true) do | |||
ligne = mw.text.trim(ligne) | |||
if ligne ~= "" then | |||
if | table.insert(fichiers, ligne) | ||
table.insert( | |||
end | end | ||
end | end | ||
if # | if #fichiers == 0 then | ||
return "<span style='color:gray;'>Aucune image trouvée dans la liste.</span>" | return "<span style='color:gray;'>Aucune image trouvée dans la liste.</span>" | ||
end | end | ||
local | math.randomseed(os.time()) | ||
local nomFichier = fichiers[math.random(#fichiers)] | |||
-- | -- HTML stylisé | ||
local html = {} | local html = {} | ||
table.insert(html, "<div style='max-width:60em;float:left; margin:auto; border:1px solid #aaa; border-radius:10px; box-shadow:1px 1px 3px #ccc; padding:12px;'>") | table.insert(html, "<div style='max-width:60em; float:left; margin:auto; border:1px solid #aaa; border-radius:10px; box-shadow:1px 1px 3px #ccc; overflow:hidden; background:#f8f9fa;'>") | ||
table.insert(html, "<div style='font-size:1.2em; font-weight:bold;'> | table.insert(html, "<div style='padding:12px; text-align:center;'>") | ||
table.insert(html, "<hr style='border:none; border-top:1px solid # | table.insert(html, "<div style='font-size:1.2em; font-weight:bold; margin-bottom:8px;'>Image du jour</div>") | ||
table.insert(html, "[[Fichier:" .. | table.insert(html, "<hr style='border:none; border-top:1px solid #ccc; margin:0; margin-bottom:12px;'>") | ||
table.insert(html, "</div>") | table.insert(html, "[[Fichier:" .. nomFichier .. "|300px]]<br>") | ||
table.insert(html, "<div style='font-size:90%; color:#555; margin-top:6px;'>[[:Fichier:" .. nomFichier .. "]]</div>") | |||
table.insert(html, "</div></div>") | |||
return table.concat(html, "\n") | return table.concat(html, "\n") | ||
Version du 13 juillet 2025 à 09:57
La documentation pour ce module peut être créée à Module:ImageDuJour/doc
local p = {}
-- Récupère une image aléatoire depuis Modèle:Liste/ImagesDuJour
function p.afficher(frame)
local listeTitle = mw.title.new("Modèle:Liste/ImagesDuJour")
if not listeTitle or not listeTitle.exists then
return "<span style='color:red;'>Erreur : la liste des images n'existe pas.</span>"
end
local contenu = listeTitle:getContent()
if not contenu then
return "<span style='color:red;'>Erreur : contenu inaccessible.</span>"
end
local fichiers = {}
for ligne in mw.text.gsplit(contenu, "\n", true) do
ligne = mw.text.trim(ligne)
if ligne ~= "" then
table.insert(fichiers, ligne)
end
end
if #fichiers == 0 then
return "<span style='color:gray;'>Aucune image trouvée dans la liste.</span>"
end
math.randomseed(os.time())
local nomFichier = fichiers[math.random(#fichiers)]
-- HTML stylisé
local html = {}
table.insert(html, "<div style='max-width:60em; float:left; margin:auto; border:1px solid #aaa; border-radius:10px; box-shadow:1px 1px 3px #ccc; overflow:hidden; background:#f8f9fa;'>")
table.insert(html, "<div style='padding:12px; text-align:center;'>")
table.insert(html, "<div style='font-size:1.2em; font-weight:bold; margin-bottom:8px;'>Image du jour</div>")
table.insert(html, "<hr style='border:none; border-top:1px solid #ccc; margin:0; margin-bottom:12px;'>")
table.insert(html, "[[Fichier:" .. nomFichier .. "|300px]]<br>")
table.insert(html, "<div style='font-size:90%; color:#555; margin-top:6px;'>[[:Fichier:" .. nomFichier .. "]]</div>")
table.insert(html, "</div></div>")
return table.concat(html, "\n")
end
return p