« Module:Episode/Index » : différence entre les versions

De Marvel Cinematic Universe Wiki
Contenu supprimé Contenu ajouté
Page créée avec « 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 =... »
 
Aucun résumé des modifications
Ligne 5 : Ligne 5 :
}
}


p.index {}
p.index = {}


local function normalize(s)
local function normalize(s)

Version du 27 mai 2026 à 14:02

Documentation module[créer]
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