More actions
No edit summary |
No edit summary |
||
Line 124: | Line 124: | ||
-- Add Twitch icon SVG | -- Add Twitch icon SVG | ||
local twitchIconWikitext = '[[File:Twitch-icon.svg|16px|class=staff-card-twitch-icon|alt=Twitch|link=]]' | |||
twitchLink:wikitext(twitchIconWikitext) | |||
end | end | ||
end | end |
Revision as of 22:27, 7 July 2025
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
local twitchIconWikitext = '[[File:Twitch-icon.svg|16px|class=staff-card-twitch-icon|alt=Twitch|link=]]'
twitchLink:wikitext(twitchIconWikitext)
end
end
end
return tostring(html)
end
return p