Module:SidebarPeople: Difference between revisions
From Bodhicitta
((by SublimeText.Mediawiker)) |
((by SublimeText.Mediawiker)) Tag: Reverted |
||
| Line 5: | Line 5: | ||
local pargs = frame:getParent().args | local pargs = frame:getParent().args | ||
local typesIndexed = { | local typesIndexed = { | ||
[ | ['sourceauthor'] = '1', | ||
[ | ['authors'] = '2', | ||
[ | ['translators'] = '3', | ||
[ | ['contributors'] = '4', | ||
[ | ['editors'] = '5', | ||
[ | ['publisher'] = '6', | ||
[ | ['creators'] = '7', | ||
[ | ['performers'] = '8', | ||
[ | ['producers'] = '9' | ||
} | } | ||
local typeLabels = { | local typeLabels = { | ||
| Line 37: | Line 37: | ||
end | end | ||
end | end | ||
for _ | for ptype, _ in pairs(typesIndexed) do | ||
for person,roles in pairs(pplTbl) do | for person,roles in pairs(pplTbl) do | ||
if type(roles) == 'string' then | if type(roles) == 'string' then | ||
| Line 67: | Line 67: | ||
function sortRoles(roles, typesIndexed) | function sortRoles(roles, typesIndexed) | ||
local sortedRoles = {} | local sortedRoles = {} | ||
| Line 78: | Line 74: | ||
table.sort(sortedRoles, function(a, b) | table.sort(sortedRoles, function(a, b) | ||
return | return typesIndexed[a] < typesIndexed[b] | ||
end) | end) | ||
Revision as of 11:45, 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 = {
['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