Module:Episode/Index
De Marvel Cinematic Universe Wiki
| Peut-être voulez-vous créer une page de documentation pour ce module Scribunto. Les éditeurs peuvent expérimenter dans les pages bac à sable (créer | miroir) et cas tests (créer) de ce module. Veuillez ajouter les catégories dans la sous-page /documentation. sous-pages de ce module. |
local p = {}
local sources = {
"Module:Episode/WandaVision",
}
p.index = {}
local function normalize(s)
-- Default to empty string if nil
s = s or ""
-- Trim leading and trailing whitespace
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)
-- Remove combining diacritical marks (U+0300 to U+036F)
local combining_start = mw.ustring.char(0x0300)
local combining_end = mw.ustring.char(0x036F)
s = mw.ustring.gsub(s, "[" .. combining_start .. "-" .. combining_end .. "]", "")
-- Normalize apostrophes to a single straight apostrophe
s = mw.ustring.gsub(s, "[’‘´`]", "'")
-- Normalize curly quotes to straight quotes
s = mw.ustring.gsub(s, "[“”]", "\"")
-- Normalize all dash types to a simple hyphen
s = mw.ustring.gsub(s, "[–—−]", "-")
-- Collapse multiple spaces into a single space
s = mw.ustring.gsub(s, "%s+", " ")
-- Convert to lowercase
s = mw.ustring.lower(s)
-- Final trim
s = mw.text.trim(s)
return s
end
-- Building the multi-key index
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
p.index[normalize(key)] = ep
end
end
end
end
-- Access function
function p.get(key)
local ep = p.index[normalize(key)]
if not ep then return nil end
return {
id = ep.id,
namespace = ep.namespace,
page_title = ep.page_title,
title_fr = ep.title_fr,
title_qc = ep.title_qc,
title_vo = ep.title_vo,
season = ep.season,
episode = ep.episode,
}
end
return p
