« 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 = {} | ||
local listePersonnages = { | local listePersonnages = { | ||
"Gore Sinkelk", | "Gore Sinkelk", | ||
| Ligne 14 : | Ligne 13 : | ||
} | } | ||
local function pageAleatoire() | local function pageAleatoire() | ||
math.randomseed(os.time()) | math.randomseed(os.time()) | ||
| Ligne 20 : | Ligne 18 : | ||
end | end | ||
function p.personnageDuJour(frame) | function p.personnageDuJour(frame) | ||
local titrePage = pageAleatoire() | local titrePage = pageAleatoire() | ||
| Ligne 33 : | Ligne 30 : | ||
end | end | ||
local theme = mw.ustring.match(contenu, "|%s*Theme%s*=%s*(%a+)") | local theme = mw.ustring.match(contenu, "|%s*Theme%s*=%s*(%a+)") | ||
if not theme then theme = "defaut" end | if not theme then theme = "defaut" end | ||
local extrait = mw.ustring.match(contenu, "<!%-%-%s*extrait%s*%-%->(.-)<!%-%-%s*/extrait%s*%-%->") | local extrait = mw.ustring.match(contenu, "<!%-%-%s*extrait%s*%-%->(.-)<!%-%-%s*/extrait%s*%-%->") | ||
if not extrait then | if not extrait then | ||
| Ligne 43 : | Ligne 38 : | ||
end | end | ||
local charteModule = require("Module:Charte") | local charteModule = require("Module:Charte") | ||
local couleurHR = charteModule.couleur{ args = { charte = theme, type = "hr" } } | local couleurHR = charteModule.couleur{ args = { charte = theme, type = "hr" } } | ||
local html = {} | local html = {} | ||
table.insert(html, "<div class='" .. theme .. "-picto' style=' | table.insert(html, "<div class='" .. theme .. "-picto' style='flex: 1 1 43%; margin-right:1.5em; border:1px solid #aaa; border-radius:10px; box-shadow:1px 1px 3px #ccc; overflow:hidden; background-repeat:no-repeat; background-position:right center; background-size:cover; display:flex; flex-direction:column;'>") | ||
table.insert(html, "<div style='padding:12px; flex:1;'>") | |||
table.insert(html, "<div style='font-size:1.2em; font-weight:bold;'>Personnage du jour</div>") | table.insert(html, "<div style='font-size:1.2em; font-weight:bold;'>Personnage du jour</div>") | ||
table.insert(html, "<hr style='border:none; border-top:1px solid " .. couleurHR .. "; margin:0; margin-bottom:12px;'>") | table.insert(html, "<hr style='border:none; border-top:1px solid " .. couleurHR .. "; margin:0; margin-bottom:12px;'>") | ||
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 auto; width:150px; position:relative;'>") | table.insert(html, "<div style='flex:0 0 auto; width:150px; position:relative;'>") | ||
table.insert(html, "[[Fichier:Portrait " .. titrePage .. ".png|150px|class=portrait-image]]") | table.insert(html, "[[Fichier:Portrait " .. titrePage .. ".png|150px|class=portrait-image]]") | ||
| Ligne 61 : | Ligne 54 : | ||
table.insert(html, "</div>") | table.insert(html, "</div>") | ||
table.insert(html, "<div style='flex:1;'>") | table.insert(html, "<div style='flex:1;'>") | ||
table.insert(html, "<div style='font-size:1.1em; font-weight:bold; margin-bottom:4px;'>[[" .. titrePage .. "]]</div>") | table.insert(html, "<div style='font-size:1.1em; font-weight:bold; margin-bottom:4px;'>[[" .. titrePage .. "]]</div>") | ||
| Ligne 67 : | Ligne 59 : | ||
table.insert(html, "<div style='text-align:right; margin-top:10px; font-size:90%;'>[[" | table.insert(html, "<div style='text-align:right; margin-top:10px; font-size:90%;'>[[" | ||
.. titrePage .. "|→ Vers l’article]]</div>") | .. titrePage .. "|→ Vers l’article]]</div>") | ||
table.insert(html, "</div> | table.insert(html, "</div></div></div></div>") | ||
return table.concat(html, "\n") | return table.concat(html, "\n") | ||
Version du 13 juillet 2025 à 18:18
La documentation pour ce module peut être créée à Module:Personnagedujour/doc
local p = {}
local listePersonnages = {
"Gore Sinkelk",
"Borald Kan",
"Harald Kan",
"Cerald Kan",
"Imrald Kan",
"Aldwimn Myłähył",
"Kyoto Anashi",
"Dante Terhunt",
"Seliaroth Melkitim",
}
local function pageAleatoire()
math.randomseed(os.time())
return listePersonnages[math.random(#listePersonnages)]
end
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 theme = mw.ustring.match(contenu, "|%s*Theme%s*=%s*(%a+)")
if not theme then theme = "defaut" 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
local charteModule = require("Module:Charte")
local couleurHR = charteModule.couleur{ args = { charte = theme, type = "hr" } }
local html = {}
table.insert(html, "<div class='" .. theme .. "-picto' style='flex: 1 1 43%; margin-right:1.5em; border:1px solid #aaa; border-radius:10px; box-shadow:1px 1px 3px #ccc; overflow:hidden; background-repeat:no-repeat; background-position:right center; background-size:cover; display:flex; flex-direction:column;'>")
table.insert(html, "<div style='padding:12px; flex:1;'>")
table.insert(html, "<div style='font-size:1.2em; font-weight:bold;'>Personnage du jour</div>")
table.insert(html, "<hr style='border:none; border-top:1px solid " .. couleurHR .. "; margin:0; margin-bottom:12px;'>")
table.insert(html, "<div style='display:flex; align-items:flex-start; gap:12px;'>")
table.insert(html, "<div style='flex:0 0 auto; width:150px; position:relative;'>")
table.insert(html, "[[Fichier:Portrait " .. titrePage .. ".png|150px|class=portrait-image]]")
table.insert(html, "<div style='position:absolute; bottom:0; left:0; width:100%; text-align:center; font-size:80%; font-weight:bold; color:white; background:rgba(0,0,0,0.6); padding:2px;'>Portrait</div>")
table.insert(html, "</div>")
table.insert(html, "<div style='flex:1;'>")
table.insert(html, "<div style='font-size:1.1em; font-weight:bold; margin-bottom:4px;'>[[" .. titrePage .. "]]</div>")
table.insert(html, mw.getCurrentFrame():preprocess(extrait))
table.insert(html, "<div style='text-align:right; margin-top:10px; font-size:90%;'>[["
.. titrePage .. "|→ Vers l’article]]</div>")
table.insert(html, "</div></div></div></div>")
return table.concat(html, "\n")
end
return p