« Module:Personnagedujour » : différence entre les versions
Apparence
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 1 : | Ligne 1 : | ||
local p = {} | local p = {} | ||
-- Fonction | -- Liste manuelle des pages de personnages | ||
local listePersonnages = { | |||
"Zahak Sinkelk", | |||
"Gore Sinkelk", | |||
"Har", | |||
"Ald", | |||
"Zah", -- ajoute autant de noms que tu veux ici | |||
} | |||
-- Fonction de tirage aléatoire depuis la liste | |||
local function pageAleatoire() | |||
math.randomseed(os.time()) | |||
return listePersonnages[math.random(#listePersonnages)] | |||
end | |||
-- Fonction principale | |||
function p.personnageDuJour(frame) | function p.personnageDuJour(frame) | ||
local titrePage = | local titrePage = pageAleatoire() | ||
local page = mw.title.new(titrePage) | local page = mw.title.new(titrePage) | ||
| Ligne 23 : | Ligne 35 : | ||
end | end | ||
-- | -- Génère le HTML stylisé | ||
local html = {} | local html = {} | ||
table.insert(html, "<div style='border:1px solid #aaa; background:#f8f9fa; padding:12px; margin:12px 0; border-radius:10px; box-shadow:1px 1px 3px #ccc;'>") | table.insert(html, "<div style='border:1px solid #aaa; background:#f8f9fa; padding:12px; margin:12px 0; border-radius:10px; box-shadow:1px 1px 3px #ccc;'>") | ||
table.insert(html, "<div style='font-size:1.2em; font-weight:bold; margin-bottom:8px;'>👤 Personnage du jour</div>") | table.insert(html, "<div style='font-size:1.2em; font-weight:bold; margin-bottom:8px;'>👤 Personnage du jour</div>") | ||
table.insert(html, "<div style='display:flex; align-items:flex-start; gap:12px;'>") | table.insert(html, "<div style='display:flex; align-items:flex-start; gap:12px;'>") | ||
table.insert(html, "<div style='flex:0 0 200px;'> | table.insert(html, "<div style='flex:0 0 200px;'>[[Fichier:" .. titrePage .. ".png|200px]]<br/><div style='text-align:center; font-size:90%;'><i>[[" .. titrePage .. "]]</i></div></div>") | ||
table.insert(html, "<div style='flex:1;'>" .. mw.getCurrentFrame():preprocess(extrait) .. "</div>") | table.insert(html, "<div style='flex:1;'>" .. mw.getCurrentFrame():preprocess(extrait) .. "</div>") | ||
table.insert(html, "</div></div>") | table.insert(html, "</div></div>") | ||
return table.concat(html, "\n") | return table.concat(html, "\n") | ||
end | end | ||
return p | return p | ||
Version du 12 juillet 2025 à 19:23
La documentation pour ce module peut être créée à Module:Personnagedujour/doc
local p = {}
-- Liste manuelle des pages de personnages
local listePersonnages = {
"Zahak Sinkelk",
"Gore Sinkelk",
"Har",
"Ald",
"Zah", -- ajoute autant de noms que tu veux ici
}
-- Fonction de tirage aléatoire depuis la liste
local function pageAleatoire()
math.randomseed(os.time())
return listePersonnages[math.random(#listePersonnages)]
end
-- Fonction principale
function p.personnageDuJour(frame)
local titrePage = pageAleatoire()
local page = mw.title.new(titrePage)
if not page or not page.exists then
return "<span style='color:red;'>Erreur : la page '" .. titrePage .. "' n'existe pas.</span>"
end
local contenu = page:getContent()
if not contenu then
return "<span style='color:red;'>Erreur : contenu inaccessible.</span>"
end
local extrait = mw.ustring.match(contenu, "<!%-%-%s*extrait%s*%-%->(.-)<!%-%-%s*/extrait%s*%-%->")
if not extrait then
return "<span style='color:gray;'>Aucun extrait trouvé dans la page.</span>"
end
-- Génère le HTML stylisé
local html = {}
table.insert(html, "<div style='border:1px solid #aaa; background:#f8f9fa; padding:12px; margin:12px 0; border-radius:10px; box-shadow:1px 1px 3px #ccc;'>")
table.insert(html, "<div style='font-size:1.2em; font-weight:bold; margin-bottom:8px;'>👤 Personnage du jour</div>")
table.insert(html, "<div style='display:flex; align-items:flex-start; gap:12px;'>")
table.insert(html, "<div style='flex:0 0 200px;'>[[Fichier:" .. titrePage .. ".png|200px]]<br/><div style='text-align:center; font-size:90%;'><i>[[" .. titrePage .. "]]</i></div></div>")
table.insert(html, "<div style='flex:1;'>" .. mw.getCurrentFrame():preprocess(extrait) .. "</div>")
table.insert(html, "</div></div>")
return table.concat(html, "\n")
end
return p