More actions
No edit summary |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 13: | Line 13: | ||
local joined = args.joined or '' | local joined = args.joined or '' | ||
local discord = args.discord or '' | local discord = args.discord or '' | ||
local youtube = args.youtube or '' | |||
local github = args.github or '' | |||
local pronouns = args.pronouns or '' | local pronouns = args.pronouns or '' | ||
local twitch = args.twitch or '' | local twitch = args.twitch or '' | ||
Line 88: | Line 90: | ||
-- Footer section (only show if we have details to display) | -- Footer section (only show if we have details to display) | ||
if status ~= '' or joined ~= '' or discord ~= '' or twitch ~= '' then | if status ~= '' or joined ~= '' or discord ~= '' or twitch ~= '' or youtube ~= '' or github ~= '' then | ||
local footer = html:tag('div'):addClass('staff-card-footer') | local footer = html:tag('div'):addClass('staff-card-footer') | ||
Line 103: | Line 105: | ||
-- Additional details | -- Additional details | ||
if joined | if joined ~= '' then | ||
local details = footer:tag('div'):addClass('staff-card-details') | local details = footer:tag('div'):addClass('staff-card-details') | ||
Line 109: | Line 111: | ||
details:tag('span'):wikitext('Joined: '):tag('strong'):wikitext(joined) | details:tag('span'):wikitext('Joined: '):tag('strong'):wikitext(joined) | ||
end | end | ||
end | |||
if discord ~= '' or twitch ~= '' or youtube ~= '' or github ~= '' then | |||
local socialDiv = footer:tag('div'):addClass('staff-card-social-icons') | |||
if discord ~= '' then | if discord ~= '' then | ||
local discordWikitext = '[https://discord.com/users/' .. discord .. ' [[File:Discord-Symbol-White.svg|20px|alt=Discord|link=]]]' | |||
socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(discordWikitext) | |||
end | end | ||
if twitch ~= '' then | if twitch ~= '' then | ||
local twitchWikitext = '[https://twitch.tv/' .. twitch .. ' [[File:Twitch-icon.svg|20px|alt=Twitch|link=]]]' | |||
socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(twitchWikitext) | |||
end | |||
if youtube ~= '' then | |||
local youtubeWikitext = '[https://youtube.com/@' .. youtube .. ' [[File:Youtube.svg|20px|alt=YouTube|link=]]]' | |||
socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(youtubeWikitext) | |||
end | |||
if github ~= '' then | |||
local | local githubWikitext = '[https://github.com/' .. github .. ' [[File:Github-mark-white.svg|20px|alt=YouTube|link=]]]' | ||
socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(githubWikitext) | |||
end | end | ||
end | end |
Latest revision as of 23:35, 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 youtube = args.youtube or ''
local github = args.github 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 ~= '' or youtube ~= '' or github ~= '' 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 ~= '' then
local details = footer:tag('div'):addClass('staff-card-details')
if joined ~= '' then
details:tag('span'):wikitext('Joined: '):tag('strong'):wikitext(joined)
end
end
if discord ~= '' or twitch ~= '' or youtube ~= '' or github ~= '' then
local socialDiv = footer:tag('div'):addClass('staff-card-social-icons')
if discord ~= '' then
local discordWikitext = '[https://discord.com/users/' .. discord .. ' [[File:Discord-Symbol-White.svg|20px|alt=Discord|link=]]]'
socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(discordWikitext)
end
if twitch ~= '' then
local twitchWikitext = '[https://twitch.tv/' .. twitch .. ' [[File:Twitch-icon.svg|20px|alt=Twitch|link=]]]'
socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(twitchWikitext)
end
if youtube ~= '' then
local youtubeWikitext = '[https://youtube.com/@' .. youtube .. ' [[File:Youtube.svg|20px|alt=YouTube|link=]]]'
socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(youtubeWikitext)
end
if github ~= '' then
local githubWikitext = '[https://github.com/' .. github .. ' [[File:Github-mark-white.svg|20px|alt=YouTube|link=]]]'
socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(githubWikitext)
end
end
end
return tostring(html)
end
return p