Module:SidebarPeople: Difference between revisions
From Bodhicitta
((by SublimeText.Mediawiker)) |
(VSCode edit) |
||
| Line 28: | Line 28: | ||
local pplTbl = {} | local pplTbl = {} | ||
for role, people in pairs(pargs) do | for role, people in pairs(pargs) do | ||
for person in string.gmatch(people, "([^;]+)") do | for person in string.gmatch(people, "([^;]+)") do | ||
| Line 37: | Line 36: | ||
end | end | ||
end | end | ||
if next(pplTbl) == nil then | |||
return '' | |||
end | |||
local output = '<div class="row mx-0 justify-content-center">' | |||
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 | ||
Revision as of 13:20, 13 February 2026
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 = {}
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
if next(pplTbl) == nil then
return ''
end
local output = '<div class="row mx-0 justify-content-center">'
for _, ptype in ipairs(typesIndexed) do
for person,roles in pairs(pplTbl) do
if type(roles) == 'string' then
if ptype == roles then
output = output .. frame:expandTemplate{ title = 'SidebarPersonBadge', 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 = 'SidebarPersonBadge', args = {
person ,
listRoles(roles, typeLabels, typesIndexed)
} }
pplTbl[person] = ''
end
end
end
end
end
output = output .. '</div>'
return output
end
function sortRoles(roles, typesIndexed)
local typeIndices = {}
for i, role in ipairs(typesIndexed) do
typeIndices[role] = i
end
local sortedRoles = {}
for role, _ in pairs(roles) do
table.insert(sortedRoles, role)
end
table.sort(sortedRoles, function(a, b)
return typeIndices[a] < typeIndices[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