Модуль:CharacterAppearance
Материал из проекта «Повелитель Тайн Вики»
Дополнительные действия
Module for {{Character appearance}}. Create a list of character appearances on Donghua episodes.
local p = {}
function p.main(frame)
local args = frame:getParent().args
local Helpers = require('Module:Helpers')
local disableCategory = Helpers.strToBool(frame.args.disable_category)
local listItems = {}
local cats = {}
local seen = {}
table.insert(listItems, '<ul>')
for _, val in ipairs(args) do
local name = mw.text.trim(val or "")
if name ~= "" then
-- detect no-link marker (! at start)
local nolink = false
if name:sub(1,1) == "!" then
nolink = true
name = mw.text.trim(name:sub(2))
end
-- Split into name and note by first colon
local cleanName, note = name:match("^(.-)%s*:%s*(.+)$")
if not cleanName then
cleanName = name
note = ""
end
cleanName = mw.text.trim(cleanName)
note = mw.text.trim(note)
-- Render list item
local noteText = note ~= "" and (" (" .. note .. ")") or ""
if nolink then
table.insert(listItems, string.format("<li>%s%s</li>", cleanName, noteText))
else
local ruName = require('Module:RuNames').lookup(cleanName)
table.insert(listItems, ruName and string.format("<li>[[%s|%s]]%s</li>", cleanName, ruName, noteText) or string.format("<li>[[%s]]%s</li>", cleanName, noteText))
-- Only add category if it's a linked character
if not disableCategory and not seen[cleanName] then
table.insert(cats, string.format("[[Категория:Эпизоды с участием: %s]]", ruName or cleanName))
seen[cleanName] = true
end
end
end
end
table.insert(listItems, "</ul>")
return table.concat(listItems, "\n") .. table.concat(cats, "")
end
return p