« Module:Episode/index » : différence entre les versions
Apparence
Contenu supprimé Contenu ajouté
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 1 : | Ligne 1 : | ||
local p = {} |
local p = {} |
||
-- List of source modules |
|||
local sources = { |
local sources = { |
||
"Module:Episode/SG1Season1", |
"Module:Episode/SG1Season1", |
||
| Ligne 25 : | Ligne 26 : | ||
p.index = {} |
p.index = {} |
||
------------------------------------------------------------ |
|||
-- Normalization |
|||
------------------------------------------------------------ |
|||
local function normalize(s) |
local function normalize(s) |
||
-- Default to empty string |
|||
s = s or "" |
s = s or "" |
||
-- Trim leading/trailing whitespace |
|||
s = mw.text.trim(s) |
s = mw.text.trim(s) |
||
-- Convert to NFD form (decomposed Unicode) |
|||
-- This allows stripping accents by removing combining marks |
|||
s = mw.ustring.toNFD(s) |
s = mw.ustring.toNFD(s) |
||
-- Remove combining diacritics (U+0300–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 |
|||
s = mw.ustring.gsub(s, "[’‘´`]", "'") |
s = mw.ustring.gsub(s, "[’‘´`]", "'") |
||
-- Normalize curly 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 |
|||
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) |
||
s = mw.text.trim(s) |
|||
return s |
return mw.text.trim(s) |
||
end |
end |
||
------------------------------------------------------------ |
|||
-- Génère une version sans tirets |
|||
-- Alias variant generators |
|||
------------------------------------------------------------ |
|||
-- Remove all dash characters |
|||
local function alias_no_dash(a) |
local function alias_no_dash(a) |
||
return mw.ustring.gsub(a, "[-–—]", "") |
return mw.ustring.gsub(a, "[-–—]", "") |
||
end |
end |
||
-- Replace dash characters with spaces |
|||
-- Génère une version où les tirets deviennent des espaces |
|||
local function alias_dash_to_space(a) |
local function alias_dash_to_space(a) |
||
return mw.ustring.gsub(a, "[-–—]", " ") |
return mw.ustring.gsub(a, "[-–—]", " ") |
||
end |
end |
||
------------------------------------------------------------ |
|||
-- Construction de l’index multi‑clé |
|||
-- Build the multi‑key index |
|||
------------------------------------------------------------ |
|||
for _, modname in ipairs(sources) do |
for _, modname in ipairs(sources) do |
||
local ok, mod = pcall(require, modname) |
local ok, mod = pcall(require, modname) |
||
if ok and mod.episodes then |
if ok and mod.episodes then |
||
-- Detect if this module contains movies instead of episodes |
|||
local isMovieModule = modname:match("SGUMovies") |
local isMovieModule = modname:match("SGUMovies") |
||
for _, ep in ipairs(mod.episodes) do |
for _, ep in ipairs(mod.episodes) do |
||
-- |
-- Movie‑specific adjustments |
||
if isMovieModule then |
if isMovieModule then |
||
ep.namespace = ep.namespace or "" |
ep.namespace = ep.namespace or "" -- Movies are in main namespace |
||
ep.season = ep.season or "" |
ep.season = ep.season or "" -- No season number |
||
ep.episode = ep.episode or "" |
ep.episode = ep.episode or "" -- No episode number |
||
end |
end |
||
-- Generate alias variants |
|||
for _, key in ipairs(ep.alias or {}) do |
for _, key in ipairs(ep.alias or {}) do |
||
| ⚫ | |||
local variants = { key } |
local variants = { key } |
||
-- |
-- Variant: remove dashes |
||
local nd = alias_no_dash(key) |
local nd = alias_no_dash(key) |
||
if nd ~= key then |
if nd ~= key then table.insert(variants, nd) end |
||
table.insert(variants, nd) |
|||
end |
|||
-- |
-- Variant: replace dashes with spaces |
||
local sp = alias_dash_to_space(key) |
local sp = alias_dash_to_space(key) |
||
if sp ~= key then |
if sp ~= key then table.insert(variants, sp) end |
||
table.insert(variants, sp) |
|||
end |
|||
-- |
-- Index all variants |
||
for _, raw in ipairs(variants) do |
for _, raw in ipairs(variants) do |
||
local nkey = normalize(raw) |
local nkey = normalize(raw) |
||
if p.index[nkey] then |
if p.index[nkey] then |
||
| ⚫ | |||
mw.log(string.format( |
mw.log(string.format( |
||
"[EpisodeIndex] |
"[EpisodeIndex] Alias collision detected: '%s' → %s and %s", |
||
nkey, |
nkey, |
||
p.index[nkey].id or "( |
p.index[nkey].id or "(no id)", |
||
ep.id or "( |
ep.id or "(no id)" |
||
)) |
)) |
||
else |
else |
||
| Ligne 108 : | Ligne 133 : | ||
end |
end |
||
------------------------------------------------------------ |
|||
-- Fonction d'accès |
|||
-- Access function |
|||
------------------------------------------------------------ |
|||
function p.get(key) |
function p.get(key) |
||
local ep = p.index[normalize(key)] |
local ep = p.index[normalize(key)] |
||
if not ep then return nil end |
if not ep then return nil end |
||
return { |
return { |
||
id = ep.id, |
id = ep.id, |
||
Version du 28 mai 2026 à 13:48
| 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 = {}
-- List of source modules
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 = {}
------------------------------------------------------------
-- Normalization
------------------------------------------------------------
local function normalize(s)
-- Default to empty string
s = s or ""
-- Trim leading/trailing whitespace
s = mw.text.trim(s)
-- Convert to NFD form (decomposed Unicode)
-- This allows stripping accents by removing combining marks
s = mw.ustring.toNFD(s)
-- Remove combining diacritics (U+0300–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
s = mw.ustring.gsub(s, "[’‘´`]", "'")
-- Normalize curly quotes
s = mw.ustring.gsub(s, "[“”]", "\"")
-- Normalize all dash types to a simple hyphen
s = mw.ustring.gsub(s, "[–—−]", "-")
-- Collapse multiple spaces
s = mw.ustring.gsub(s, "%s+", " ")
-- Convert to lowercase
s = mw.ustring.lower(s)
return mw.text.trim(s)
end
------------------------------------------------------------
-- Alias variant generators
------------------------------------------------------------
-- Remove all dash characters
local function alias_no_dash(a)
return mw.ustring.gsub(a, "[-–—]", "")
end
-- Replace dash characters with spaces
local function alias_dash_to_space(a)
return mw.ustring.gsub(a, "[-–—]", " ")
end
------------------------------------------------------------
-- Build the multi‑key index
------------------------------------------------------------
for _, modname in ipairs(sources) do
local ok, mod = pcall(require, modname)
if ok and mod.episodes then
-- Detect if this module contains movies instead of episodes
local isMovieModule = modname:match("SGUMovies")
for _, ep in ipairs(mod.episodes) do
-- Movie‑specific adjustments
if isMovieModule then
ep.namespace = ep.namespace or "" -- Movies are in main namespace
ep.season = ep.season or "" -- No season number
ep.episode = ep.episode or "" -- No episode number
end
-- Generate alias variants
for _, key in ipairs(ep.alias or {}) do
local variants = { key }
-- Variant: remove dashes
local nd = alias_no_dash(key)
if nd ~= key then table.insert(variants, nd) end
-- Variant: replace dashes with spaces
local sp = alias_dash_to_space(key)
if sp ~= key then table.insert(variants, sp) end
-- Index all variants
for _, raw in ipairs(variants) do
local nkey = normalize(raw)
if p.index[nkey] then
-- Collision detection
mw.log(string.format(
"[EpisodeIndex] Alias collision detected: '%s' → %s and %s",
nkey,
p.index[nkey].id or "(no id)",
ep.id or "(no id)"
))
else
p.index[nkey] = ep
end
end
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,
property = ep.property,
season = ep.season,
episode = ep.episode,
}
end
return p