Documentation for this module may be created at Module:StaffCard/doc
local p = {}
function p.main(frame)
local args = frame:getParent().args
-- Get parameters
local handle = args.handle or args[1] or ''
local ign = args.ign or args[2] or ''
local roles = args.roles or args[3] or ''
local bio = args.bio or args[4] or ''
local avatar = args.avatar or ''
local status = args.status or 'active'
local joined = args.joined or ''
local discord = args.discord or ''
local pronouns = args.pronouns or ''
local twitch = args.twitch or ''
-- Check if we're being called from the template page itself (no parameters)
-- This prevents errors when viewing the template page directly
local hasAnyArgs = false
for k, v in pairs(args) do
if v and v ~= '' then
hasAnyArgs = true
break
end
end
-- If no arguments provided (viewing template page), return empty string
if not hasAnyArgs then
return ''
end
-- Validate required fields for actual usage
if handle == '' then
return '<div class="error">Error: Handle is required for staff card</div>'
end
-- Build the card HTML
local html = mw.html.create('div')
:addClass('staff-card')
:attr('data-handle', handle)
-- Header section
local header = html:tag('div'):addClass('staff-card-header')
-- Avatar
local avatarDiv = header:tag('div'):addClass('staff-card-avatar')
if avatar ~= '' then
-- Use custom avatar if provided
avatarDiv:tag('img'):attr('src', avatar):attr('alt', handle .. ' avatar')
elseif ign ~= '' then
-- Use PlayerHead template if IGN is provided but no custom avatar
local playerHeadWikitext = frame:preprocess('{{PlayerHead|' .. ign .. '|60px}}')
avatarDiv:wikitext(playerHeadWikitext)
else
-- Use first letter of handle as fallback
avatarDiv:wikitext(mw.ustring.sub(handle, 1, 1))
end
-- Info section
local info = header:tag('div'):addClass('staff-card-info')
info:tag('h3'):wikitext(handle)
if ign ~= '' then
info:tag('div'):addClass('staff-card-ign'):wikitext('IGN: ' .. ign)
end
if pronouns ~= '' then
info:tag('div'):addClass('staff-card-pronouns'):wikitext('(' .. pronouns .. ')')
end
-- Roles section
if roles ~= '' then
local rolesDiv = html:tag('div'):addClass('staff-card-roles')
local roleList = mw.text.split(roles, ',')
for _, role in ipairs(roleList) do
role = mw.text.trim(role)
if role ~= '' then
rolesDiv:tag('span'):addClass('staff-card-role'):wikitext(role)
end
end
end
-- Bio section
if bio ~= '' then
html:tag('div'):addClass('staff-card-bio'):wikitext(bio)
end
-- Footer section (only show if we have details to display)
if status ~= '' or joined ~= '' or discord ~= '' or twitch ~= '' then
local footer = html:tag('div'):addClass('staff-card-footer')
-- Status and meta info
local meta = footer:tag('div'):addClass('staff-card-meta')
-- Status indicator
if status ~= '' then
local statusSpan = meta:tag('span')
:addClass('staff-card-status')
:addClass(status:lower())
:wikitext(status)
end
-- Additional details
if joined ~= '' or discord ~= '' or twitch ~= '' then
local details = footer:tag('div'):addClass('staff-card-details')
if joined ~= '' then
details:tag('span'):wikitext('Joined: '):tag('strong'):wikitext(joined)
end
if discord ~= '' then
details:tag('span'):wikitext('Discord: '):tag('strong'):wikitext(discord)
end
if twitch ~= '' then
local twitchSpan = details:tag('span'):wikitext('Twitch: ')
local socialDiv = twitchSpan:tag('span'):addClass('staff-card-social')
local twitchLink = socialDiv:tag('a')
:attr('href', 'https://twitch.tv/' .. twitch)
:attr('target', '_blank')
:attr('rel', 'noopener')
:attr('title', twitch .. ' on Twitch')
-- Add Twitch icon SVG
twitchLink:tag('svg')
:addClass('staff-card-twitch-icon')
:attr('viewBox', '0 0 24 24')
:attr('xmlns', 'http://www.w3.org/2000/svg')
:attr('fill', 'currentColor')
:tag('path')
:attr('d', 'M11.571 4.714h1.715v5.143H11.57zm4.715 0H18v5.143h-1.714zM6 0L1.714 4.286v15.428h5.143V24l4.286-4.286h3.428L22.286 12V0zm14.571 11.143l-3.428 3.428h-3.429l-3 3v-3H6.857V1.714h13.714Z')
end
end
end
return tostring(html)
end
return p