Module:SidebarPeople: Difference between revisions
From Bodhicitta
((by SublimeText.Mediawiker)) |
((by SublimeText.Mediawiker)) Tag: Reverted |
||
| Line 39: | Line 39: | ||
for _, ptype in ipairs(typesIndexed) do | for _, ptype in ipairs(typesIndexed) do | ||
for person,roles in pairs(pplTbl) do | for person,roles in pairs(pplTbl) do | ||
if roles then return roles end | |||
if type(roles) == 'string' then | if type(roles) == 'string' then | ||
if ptype == roles then | if ptype == roles then | ||
Revision as of 11:39, 17 October 2025
Documentation for this module may be created at Module:SidebarPeople/doc
local p = {}
function p.main(frame)
local pargs = frame:getParent().args
local typesIndexed = {
[1] = 'sourceauthor',
[2] = 'authors',
[3] = 'translators',
[4] = 'contributors',
[5] = 'editors',
[6] = 'publisher',
[7] = 'creators',
[8] = 'performers',
[9] = 'producers'
}
local typeLabels = {
sourceauthor = "source author",
authors = "author",
translators = "translator",
contributors = "contributor",
editors = "editor",
publisher = "publisher",
creators = "creator",
performers = "performer",
producers = "producer"
}
local pplTbl = {}
local output = '<div class="d-flex justify-content-center flex-row flex-wrap">'
for role, people in pairs(pargs) do
for person in string.gmatch(people, "([^;]+)") do
if pplTbl[person] then else
pplTbl[person] = {}
end
table.insert(pplTbl[person], role)
end
end
for _, ptype in ipairs(typesIndexed) do
for person,roles in pairs(pplTbl) do
if roles then return roles end
if type(roles) == 'string' then
if ptype == roles then
output = output .. frame:expandTemplate{ title = 'PersonBadge', args = {
person ,
typeLabels[roles]
} }
pplTbl[person] = ''
end
elseif type(roles) == 'table' then
for _,role in ipairs(roles) do
if ptype == role then
output = output .. frame:expandTemplate{ title = 'PersonBadge', args = {
person ,
listRoles(roles, typeLabels, typesIndexed)
} }
pplTbl[person] = ''
end
end
end
end
end
output = output .. '</div>'
return output
end
function listRoles(roles, typeLabels, typesIndexed)
local uniqueRoles = {}
for _, role in pairs(roles) do
uniqueRoles[role] = true
end
local list = ''
local sep = ''
for role,_ in pairs(uniqueRoles) do
list = list .. sep .. typeLabels[role]
sep = ';'
end
return list
end
function makeTblUnique(indexedTable)
local uniqueTbl = {}
for _, value in ipairs(indexedTable) do
uniqueTbl[value] = true
end
indexedTable = {}
for value,_ in pairs(uniqueTbl) do
table.insert(indexedTable, value)
end
return indexedTable
end
return p