« Module:Episode/index » : différence entre les versions
Apparence
Contenu supprimé Contenu ajouté
Page créée avec « local p = {} local sources = { "Module:Episode/SG1Season1", "Module:Episode/SG1Season2", "Module:Episode/SG1Season3", "Module:Episode/SG1Season4", "Module:Episode/SG1Season5", "Module:Episode/SG1Season6", "Module:Episode/SG1Season7", "Module:Episode/SG1Season8", "Module:Episode/SG1Season9", "Module:Episode/SG1Season10", "Module:Episode/SGASeason1", "Module:Episode/SGASeason2", "Module:Episode/SGASeason3", "Module:Episode/SGASeason4", "Module:Episo... » |
Aucun résumé des modifications |
||
| Ligne 2 : | Ligne 2 : | ||
local sources = { |
local sources = { |
||
"Module:Episode/SG1Season1", |
|||
"Module:Episode/SG1Season2", |
|||
"Module:Episode/SG1Season3", |
|||
"Module:Episode/SG1Season4", |
|||
"Module:Episode/SG1Season5", |
|||
"Module:Episode/SG1Season6", |
|||
"Module:Episode/SG1Season7", |
|||
"Module:Episode/SG1Season8", |
|||
"Module:Episode/SG1Season9", |
|||
"Module:Episode/SG1Season10", |
|||
"Module:Episode/SGASeason1", |
|||
"Module:Episode/SGASeason2", |
|||
"Module:Episode/SGASeason3", |
|||
"Module:Episode/SGASeason4", |
|||
"Module:Episode/SGASeason5", |
|||
"Module:Episode/SGUSeason1", |
|||
"Module:Episode/SGUSeason2", |
|||
"Module:Episode/SGISeason1", |
|||
"Module:Episode/SGOSeason1", |
|||
"Module:Episode/SGUMovies", |
|||
} |
} |
||
| Ligne 27 : | Ligne 27 : | ||
local function normalize(s) |
local function normalize(s) |
||
-- Default to empty string if nil |
|||
s = s or "" |
s = s or "" |
||
-- Trim leading and trailing whitespace |
|||
s = mw.text.trim(s) |
s = mw.text.trim(s) |
||
-- Normalize Unicode to NFD (decomposed form) |
|||
-- This allows us to remove accents by stripping combining marks |
|||
s = mw.ustring.toNFD(s) |
s = mw.ustring.toNFD(s) |
||
-- Remove combining diacritical marks (U+0300 to U+036F) |
|||
local combining_start = mw.ustring.char(0x0300) |
local combining_start = mw.ustring.char(0x0300) |
||
local combining_end = mw.ustring.char(0x036F) |
local combining_end = mw.ustring.char(0x036F) |
||
s = mw.ustring.gsub(s, "[" .. combining_start .. "-" .. combining_end .. "]", "") |
s = mw.ustring.gsub(s, "[" .. combining_start .. "-" .. combining_end .. "]", "") |
||
-- Normalize apostrophes to a single straight apostrophe |
|||
s = mw.ustring.gsub(s, "[’‘´`]", "'") |
s = mw.ustring.gsub(s, "[’‘´`]", "'") |
||
-- Normalize curly quotes to straight quotes |
|||
s = mw.ustring.gsub(s, "[“”]", "\"") |
s = mw.ustring.gsub(s, "[“”]", "\"") |
||
-- Normalize all dash types to a simple hyphen |
|||
s = mw.ustring.gsub(s, "[–—−]", "-") |
s = mw.ustring.gsub(s, "[–—−]", "-") |
||
-- Collapse multiple spaces into a single space |
|||
s = mw.ustring.gsub(s, "%s+", " ") |
s = mw.ustring.gsub(s, "%s+", " ") |
||
-- Convert to lowercase |
|||
s = mw.ustring.lower(s) |
s = mw.ustring.lower(s) |
||
-- Final trim |
|||
s = mw.text.trim(s) |
s = mw.text.trim(s) |
||
| Ligne 63 : | Ligne 45 : | ||
end |
end |
||
-- Génère automatiquement une version sans tirets |
|||
-- Building the multi-key index |
|||
local function alias_no_dash(a) |
|||
| ⚫ | |||
return mw.ustring.gsub(a, "[-–—]", "") |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
nkey, |
|||
| ⚫ | |||
| ⚫ | |||
)) |
|||
else |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
end |
|||
end |
|||
end |
end |
||
-- Construction de l’index multi‑clé |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
-- 1) alias original |
|||
local variants = { key } |
|||
-- 2) alias sans tirets (si différent) |
|||
-- Access function |
|||
local nd = alias_no_dash(key) |
|||
if nd ~= key then |
|||
table.insert(variants, nd) |
|||
end |
|||
-- Indexation de toutes les variantes |
|||
for _, raw in ipairs(variants) do |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
nkey, |
|||
| ⚫ | |||
| ⚫ | |||
)) |
|||
else |
|||
| ⚫ | |||
end |
|||
end |
|||
end |
|||
end |
|||
| ⚫ | |||
| ⚫ | |||
-- Fonction d'accès |
|||
function p.get(key) |
function p.get(key) |
||
local ep = p.index[normalize(key)] |
|||
if not ep then return nil end |
|||
return { |
|||
id = ep.id, |
|||
namespace = ep.namespace or "", |
|||
page_title = ep.page_title, |
|||
title_fr = ep.title_fr, |
|||
title_qc = ep.title_qc, |
|||
title_vo = ep.title_vo, |
|||
property = ep.property, |
|||
season = ep.season or "", |
|||
episode = ep.episode or "", |
|||
} |
|||
} |
|||
end |
end |
||
Version du 28 mai 2026 à 12:53
| Il sera peut-être nécessaire de créer une page documentation pour ce module Scribunto programmé dans la page créer Les éditeurs peuvent faire des tests sur les pages bac à sable (créer | miroir) et études de cas (créer) du module. Veuillez ajouter les catégories dans la sous-page /documentation. Sous-pages de ce module. |
local p = {}
local sources = {
"Module:Episode/SG1Season1",
"Module:Episode/SG1Season2",
"Module:Episode/SG1Season3",
"Module:Episode/SG1Season4",
"Module:Episode/SG1Season5",
"Module:Episode/SG1Season6",
"Module:Episode/SG1Season7",
"Module:Episode/SG1Season8",
"Module:Episode/SG1Season9",
"Module:Episode/SG1Season10",
"Module:Episode/SGASeason1",
"Module:Episode/SGASeason2",
"Module:Episode/SGASeason3",
"Module:Episode/SGASeason4",
"Module:Episode/SGASeason5",
"Module:Episode/SGUSeason1",
"Module:Episode/SGUSeason2",
"Module:Episode/SGISeason1",
"Module:Episode/SGOSeason1",
"Module:Episode/SGUMovies",
}
p.index = {}
local function normalize(s)
s = s or ""
s = mw.text.trim(s)
s = mw.ustring.toNFD(s)
local combining_start = mw.ustring.char(0x0300)
local combining_end = mw.ustring.char(0x036F)
s = mw.ustring.gsub(s, "[" .. combining_start .. "-" .. combining_end .. "]", "")
s = mw.ustring.gsub(s, "[’‘´`]", "'")
s = mw.ustring.gsub(s, "[“”]", "\"")
s = mw.ustring.gsub(s, "[–—−]", "-")
s = mw.ustring.gsub(s, "%s+", " ")
s = mw.ustring.lower(s)
s = mw.text.trim(s)
return s
end
-- Génère automatiquement une version sans tirets
local function alias_no_dash(a)
return mw.ustring.gsub(a, "[-–—]", "")
end
-- Construction de l’index multi‑clé
for _, modname in ipairs(sources) do
local ok, mod = pcall(require, modname)
if ok and mod.episodes then
for _, ep in ipairs(mod.episodes) do
for _, key in ipairs(ep.alias or {}) do
-- 1) alias original
local variants = { key }
-- 2) alias sans tirets (si différent)
local nd = alias_no_dash(key)
if nd ~= key then
table.insert(variants, nd)
end
-- Indexation de toutes les variantes
for _, raw in ipairs(variants) do
local nkey = normalize(raw)
if p.index[nkey] then
mw.log(string.format(
"[EpisodeIndex] Collision d'alias détectée : '%s' → %s et %s",
nkey,
p.index[nkey].id or "(sans id)",
ep.id or "(sans id)"
))
else
p.index[nkey] = ep
end
end
end
end
end
end
-- Fonction d'accès
function p.get(key)
local ep = p.index[normalize(key)]
if not ep then return nil end
return {
id = ep.id,
namespace = ep.namespace or "",
page_title = ep.page_title,
title_fr = ep.title_fr,
title_qc = ep.title_qc,
title_vo = ep.title_vo,
property = ep.property,
season = ep.season or "",
episode = ep.episode or "",
}
end
return p