Módulo:Etiqueta
De MundoConan Wiki
Más acciones
La documentación para este módulo puede ser creada en Módulo:Etiqueta/doc
-- Módulo:Etiqueta — {{Etiqueta|tipo|número|título}}
-- Escribe «[[Página|<etiqueta>Episodio 523</etiqueta> Título]]» sin tener que repetir el título:
-- · episodio / capítulo: se busca la redirección «Episodio N» / «Capítulo N».
-- · el resto (película, OVA, opening, ending…): Módulo:Etiqueta/datos.
-- · si se pone el 3.er parámetro (título), se usa ese (p. ej. episodios de Magic Kaito).
local p = {}
local datos = mw.loadData('Módulo:Etiqueta/datos')
-- clave normalizada → { texto de la etiqueta, clase de color }
local TIPOS = {
episodio = { 'Episodio', 'episodio' },
ep = { 'Episodio', 'episodio' },
capitulo = { 'Capítulo', 'capitulo' },
cap = { 'Capítulo', 'capitulo' },
pelicula = { 'Película', 'pelicula' },
ova = { 'OVA', 'ova' },
opening = { 'Opening', 'opening' },
ending = { 'Ending', 'ending' },
especial = { 'Especial de TV', 'especial' },
especialtv = { 'Especial de TV', 'especial' },
especialdetv = { 'Especial de TV', 'especial' },
magicfile = { 'Magic File', 'especial' },
drama = { 'Drama', 'especial' },
cortos = { 'Cortos de Gosho', 'especial' },
cortosdegosho = { 'Cortos de Gosho', 'especial' },
conanvswooo = { 'Conan vs Wooo', 'especial' },
wooo = { 'Conan vs Wooo', 'especial' },
}
local ACENTOS = { ['á'] = 'a', ['é'] = 'e', ['í'] = 'i', ['ó'] = 'o', ['ú'] = 'u', ['ü'] = 'u' }
local function clave(s)
s = mw.ustring.lower(s)
s = mw.ustring.gsub(s, '[áéíóúü]', ACENTOS)
return (s:gsub('[%s%p]', ''))
end
local function trim(s)
return mw.text.trim(s or '')
end
-- Para tipos libres («Magic Kaito 1412 Opening»): color según la última palabra conocida.
local function claseLibre(k)
for _, w in ipairs({ 'opening', 'ending', 'episodio', 'capitulo', 'pelicula', 'ova' }) do
if k:find(w, 1, true) then
return w
end
end
return 'especial'
end
local function destinoPorRedireccion(etiqueta)
local t = mw.title.new(etiqueta)
local r = t and t.redirectTarget
return r and r.prefixedText or nil
end
function p.main(frame)
local a = frame:getParent().args
local tipo = trim(a[1] or a.tipo)
local num = trim(a[2] or a['número'] or a.numero)
local titulo = trim(a[3] or a['título'] or a.titulo)
local texto = trim(a.texto)
if tipo == '' then
return '<strong class="error">{{Etiqueta}}: falta el tipo (episodio, capítulo, película, ova, opening, ending…)</strong>'
end
local k = clave(tipo)
local t = TIPOS[k]
local nombre = t and t[1] or (mw.ustring.upper(mw.ustring.sub(tipo, 1, 1)) .. mw.ustring.sub(tipo, 2))
local clase = t and t[2] or claseLibre(k)
local etiqueta = num ~= '' and (nombre .. ' ' .. num) or nombre
local destino = titulo ~= '' and titulo or datos[etiqueta]
if not destino and (clase == 'episodio' or clase == 'capitulo') then
destino = destinoPorRedireccion(etiqueta)
end
local mostrar = texto
if mostrar == '' and destino then
-- Las películas se muestran sin «Detective Conan N: »
mostrar = mw.ustring.gsub(destino, '^Detective Conan %d+: ', '')
if mw.ustring.match(mostrar, '^Detective Conan %d+$') then
mostrar = ''
end
end
local span = '<span class="mc-etiqueta mc-etiqueta--' .. clase .. '">' .. etiqueta .. '</span>'
if destino then
return '[[' .. destino .. '|' .. span .. (mostrar ~= '' and (' ' .. mostrar) or '') .. ']]'
end
local salida = span .. (mostrar ~= '' and (' ' .. mostrar) or '')
if mw.title.getCurrentTitle().namespace == 0 then
salida = salida .. '[[Categoría:Páginas con etiquetas sin enlace]]'
end
return salida
end
return p