Module:SidebarPeople
From Bodhicitta
Documentation for this module may be created at Module:SidebarPeople/doc
local p = {}
function p.main(frame)
local pargs = frame:getParent().args
local typesIndexed = {
['sourceauthor'] = '1',
['authors'] = '2',
['translators'] = '3',
['contributors'] = '4',
['editors'] = '5',
['publisher'] = '6',
['creators'] = '7',
['performers'] = '8',
['producers'] = '9'
}
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 pairs(typesIndexed) do
for person,roles in pairs(pplTbl) do
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 sortRoles(roles, typesIndexed)
local sortedRoles = {}
for role, _ in pairs(roles) do
table.insert(sortedRoles, role)
end
table.sort(sortedRoles, function(a, b)
return typesIndexed[a] < typesIndexed[b]
end)
return sortedRoles
end
function listRoles(roles, typeLabels, typesIndexed)
local uniqueRoles = {}
for _, role in pairs(roles) do
uniqueRoles[role] = true
end
local sortedRoles = sortRoles(uniqueRoles, typesIndexed)
local list = {}
for _, role in ipairs(sortedRoles) do
table.insert(list, typeLabels[role])
end
return table.concat(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