« Module:EvenementDuJour » : différence entre les versions
Apparence
Page créée avec « local p = {} -- Liste manuelle des pages d'événements local listeEvenements = { "Guerre sylvestre", } -- Tirage au hasard local function pageAleatoire() math.randomseed(os.time()) return listeEvenements[math.random(#listeEvenements)] end -- Fonction principale : événement du jour function p.evenementDuJour(frame) local titrePage = pageAleatoire() local page = mw.title.new(titrePage) if not page or not page.exists then return... » |
Aucun résumé des modifications |
||
| (4 versions intermédiaires par le même utilisateur non affichées) | |||
| Ligne 3 : | Ligne 3 : | ||
-- Liste manuelle des pages d'événements | -- Liste manuelle des pages d'événements | ||
local listeEvenements = { | local listeEvenements = { | ||
"Guerre | "Guerre Sylvestre", | ||
"Grand Oubli" | |||
} | } | ||
| Ligne 12 : | Ligne 13 : | ||
end | end | ||
-- Fonction principale | -- Fonction principale | ||
function p.evenementDuJour(frame) | function p.evenementDuJour(frame) | ||
local titrePage = pageAleatoire() | local titrePage = pageAleatoire() | ||
| Ligne 25 : | Ligne 26 : | ||
end | end | ||
-- Extraire le thème depuis l'infobox | |||
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 | ||
-- Extraire le bloc entre <!--extrait--> et <!--/extrait--> | |||
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 33 : | Ligne 36 : | ||
end | end | ||
-- Charger Module:Charte pour récupérer la couleur | |||
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" } } | ||
-- Construction HTML | |||
local html = {} | local html = {} | ||
table.insert(html, "<div class='" .. theme .. "-picto' style=' | table.insert(html, "<div class='" .. theme .. "-picto' style='flex: 0 0 59%; border:1px solid #aaa; border-radius:10px; box-shadow:1px 1px 3px #ccc; overflow:hidden; position:relative; background-repeat:no-repeat; background-position:right center; background-size:cover; display:flex; flex-direction:column;'>") | ||
table.insert(html, "<div style='padding:12px;'>") | table.insert(html, "<div style='padding:12px;'>") | ||
table.insert(html, "<div style='font-size:1.2em; font-weight:bold;'> | table.insert(html, "<div style='font-size:1.2em; font-weight:bold;'>Évènement 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='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>") | ||
table.insert(html, mw.getCurrentFrame():preprocess(extrait)) | table.insert(html, mw.getCurrentFrame():preprocess(extrait)) | ||
table.insert(html, "</div>") | table.insert(html, "<div style='text-align:right; font-size:85%; margin-top:8px;'>[[" | ||
.. titrePage .. "|→ Vers l’article]]</div>") | |||
table.insert(html, "</div>") -- fin padding | table.insert(html, "</div>") -- fin padding | ||
table.insert(html, "</div>") -- fin bloc principal | table.insert(html, "</div>") -- fin bloc principal | ||
Dernière version du 18 juillet 2025 à 17:23
La documentation pour ce module peut être créée à Module:EvenementDuJour/doc
local p = {}
-- Liste manuelle des pages d'événements
local listeEvenements = {
"Guerre Sylvestre",
"Grand Oubli"
}
-- Tirage au hasard
local function pageAleatoire()
math.randomseed(os.time())
return listeEvenements[math.random(#listeEvenements)]
end
-- Fonction principale
function p.evenementDuJour(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
-- Extraire le thème depuis l'infobox
local theme = mw.ustring.match(contenu, "|%s*Theme%s*=%s*(%a+)")
if not theme then theme = "defaut" end
-- Extraire le bloc entre <!--extrait--> et <!--/extrait-->
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
-- Charger Module:Charte pour récupérer la couleur
local charteModule = require("Module:Charte")
local couleurHR = charteModule.couleur{ args = { charte = theme, type = "hr" } }
-- Construction HTML
local html = {}
table.insert(html, "<div class='" .. theme .. "-picto' style='flex: 0 0 59%; border:1px solid #aaa; border-radius:10px; box-shadow:1px 1px 3px #ccc; overflow:hidden; position:relative; background-repeat:no-repeat; background-position:right center; background-size:cover; display:flex; flex-direction:column;'>")
table.insert(html, "<div style='padding:12px;'>")
table.insert(html, "<div style='font-size:1.2em; font-weight:bold;'>Évènement 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='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; font-size:85%; margin-top:8px;'>[["
.. titrePage .. "|→ Vers l’article]]</div>")
table.insert(html, "</div>") -- fin padding
table.insert(html, "</div>") -- fin bloc principal
return table.concat(html, "\n")
end
return p