Aller au contenu

« Module:Personnagedujour » : différence entre les versions

De Wikiquestia
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 1 : Ligne 1 :
local p = {}
local p = {}


-- Liste manuelle des pages de personnages
local listePersonnages = {
local listePersonnages = {
     "Gore Sinkelk",
     "Gore Sinkelk",
}
}


-- Fonction : récupère une page au hasard
-- Fonction : sélection aléatoire dans la liste
local function pageAleatoire()
local function pageAleatoire()
     math.randomseed(os.time())
     math.randomseed(os.time())
Ligne 12 : Ligne 11 :
end
end


-- Fonction principale
function p.personnageDuJour(frame)
function p.personnageDuJour(frame)
     local titrePage = pageAleatoire()
     local titrePage = pageAleatoire()
Ligne 25 : Ligne 23 :
     end
     end


    -- Extrait 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 30 : Ligne 29 :
     end
     end


     -- Récupération de la charte et du thème
     -- Récupérer la charte (pour la couleur) et le thème (pour le fond pictogramme)
     local charte = contenu:match("|%s*[Cc]harte%s*=%s*(.-)\n") or "defaut"
     local charte = contenu:match("|%s*[Cc]harte%s*=%s*(.-)\n") or "defaut"
     local theme = contenu:match("|%s*[Tt]heme%s*=%s*(.-)\n") or "personnage"
     local theme = contenu:match("|%s*[Tt]heme%s*=%s*(.-)\n") or "biographie"
 
    -- Couleur <hr> via le Module:Charte
     local couleurHR = mw.getCurrentFrame():callParserFunction("#invoke:Charte|couleur", "charte=" .. charte, "type=hr")
     local couleurHR = mw.getCurrentFrame():callParserFunction("#invoke:Charte|couleur", "charte=" .. charte, "type=hr")


     -- Construction HTML stylisé
     -- Construction HTML
     local html = {}
     local html = {}
     table.insert(html, "<div style=\"max-width:900px; margin:auto; border:1px solid #aaa; background:#f8f9fa; padding:12px; border-radius:10px; box-shadow:1px 1px 3px #ccc; position:relative; overflow:hidden;\">")
     table.insert(html, "<div class='" .. theme .. "' style=\"max-width:900px; margin:auto; border:1px solid #aaa; background:#f8f9fa; padding:12px; border-radius:10px; box-shadow:1px 1px 3px #ccc; position:relative; overflow:hidden;\">")


    -- Filigrane (pictogramme transparent à droite)
     -- Titre + ligne colorée
    table.insert(html, "<div style='position:absolute; right:10px; top:10px; font-size:6em; color:#0002; pointer-events:none; z-index:0;'>" .. mw.text.nowiki(picto(theme)) .. "</div>")
     table.insert(html, "<div style='font-size:1.3em; font-weight:bold;'>👤 Personnage du jour</div>")
 
     -- Titre
     table.insert(html, "<div style='font-size:1.3em; font-weight:bold; z-index:1; position:relative;'>👤 Personnage du jour</div>")
     table.insert(html, "<hr style='border:none; height:4px; background:" .. couleurHR .. "; margin:4px 0;' />")
     table.insert(html, "<hr style='border:none; height:4px; background:" .. couleurHR .. "; margin:4px 0;' />")


     -- Contenu principal
     -- Contenu principal (image + extrait)
     table.insert(html, "<div style='display:flex; align-items:flex-start; gap:12px; position:relative; z-index:1;'>")
     table.insert(html, "<div style='display:flex; align-items:flex-start; gap:12px;'>")


     -- Image
     -- Bloc image avec étiquette
     table.insert(html, "<div style='flex:0 0 200px; position:relative;'>")
     table.insert(html, "<div style='flex:0 0 200px; position:relative;'>")
     table.insert(html, "[[Fichier:" .. titrePage .. ".png|200px|class=portrait-image]]")
     table.insert(html, "[[Fichier:" .. titrePage .. ".png|200px|class=portrait-image]]")
Ligne 64 : Ligne 58 :


     table.insert(html, "</div></div>")
     table.insert(html, "</div></div>")
     return table.concat(html, "\n")
     return table.concat(html, "\n")
end
-- Fonction : retourne un pictogramme unicode selon le thème
function picto(theme)
    local icones = {
        personnage = "👤",
        langue = "🗣️",
        ordre = "🛡️",
        image = "🖼️",
        geographie = "🗺️",
        pays = "🌍",
        ["légende et contes"] = "📖",
        default = "📘"
    }
    return icones[theme] or icones["default"]
end
end


return p
return p

Version du 12 juillet 2025 à 19:59

La documentation pour ce module peut être créée à Module:Personnagedujour/doc

local p = {}

local listePersonnages = {
    "Gore Sinkelk",
}

-- Fonction : sélection aléatoire dans la liste
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

    -- Extrait 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

    -- Récupérer la charte (pour la couleur) et le thème (pour le fond pictogramme)
    local charte = contenu:match("|%s*[Cc]harte%s*=%s*(.-)\n") or "defaut"
    local theme = contenu:match("|%s*[Tt]heme%s*=%s*(.-)\n") or "biographie"
    local couleurHR = mw.getCurrentFrame():callParserFunction("#invoke:Charte|couleur", "charte=" .. charte, "type=hr")

    -- Construction HTML
    local html = {}
    table.insert(html, "<div class='" .. theme .. "' style=\"max-width:900px; margin:auto; border:1px solid #aaa; background:#f8f9fa; padding:12px; border-radius:10px; box-shadow:1px 1px 3px #ccc; position:relative; overflow:hidden;\">")

    -- Titre + ligne colorée
    table.insert(html, "<div style='font-size:1.3em; font-weight:bold;'>👤 Personnage du jour</div>")
    table.insert(html, "<hr style='border:none; height:4px; background:" .. couleurHR .. "; margin:4px 0;' />")

    -- Contenu principal (image + extrait)
    table.insert(html, "<div style='display:flex; align-items:flex-start; gap:12px;'>")

    -- Bloc image avec étiquette
    table.insert(html, "<div style='flex:0 0 200px; position:relative;'>")
    table.insert(html, "[[Fichier:" .. titrePage .. ".png|200px|class=portrait-image]]")
    table.insert(html, "<div style='position:absolute; bottom:6px; 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>")

    -- Nom + extrait
    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>")

    table.insert(html, "</div></div>")

    return table.concat(html, "\n")
end

return p