No edit summary |
mNo edit summary |
||
(13 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local UtilLinks = require('Module:Links') | local UtilLinks = require('Module:Links') | ||
local Table = require('Module:Table') | local Table = require('Module:Table') | ||
local Links = {} | local Links = {} | ||
local _ICON_KEYS_TO_RENAME = { | local _ICON_KEYS_TO_RENAME = { | ||
Line 88: | Line 79: | ||
'twitter', | 'twitter', | ||
'vk', | 'vk', | ||
'weibo' | 'weibo', | ||
'email', | |||
'linkedin' | |||
}, | }, | ||
streams = { | streams = { | ||
Line 108: | Line 101: | ||
function Links.make(links, variant) | function Links.make(links, variant) | ||
if _isTableEmpty(links) then return nil end | |||
local infoboxLinks = mw.html.create('div') | local infoboxLinks = mw.html.create('div') | ||
infoboxLinks :addClass(' | infoboxLinks :addClass('ib-links') | ||
for _, group in Table.iter.spairs(_PRIORITY_GROUPS) do | for _, group in Table.iter.spairs(_PRIORITY_GROUPS) do | ||
for _, key in ipairs(group) do | for _, key in ipairs(group) do | ||
if links[key] ~= nil then | if links[key] ~= nil then | ||
infoboxLinks:wikitext(' ' .. _makeLink(key, links[key])) | infoboxLinks:wikitext(' ' .. _makeLink(key, links[key], variant)) | ||
-- Remove link from the collection | -- Remove link from the collection | ||
links[key] = nil | links[key] = nil | ||
Line 121: | Line 114: | ||
local index = 2 | local index = 2 | ||
while links[key .. index] ~= nil do | while links[key .. index] ~= nil do | ||
infoboxLinks:wikitext(' ' .. _makeLink(key, links[key .. index])) | infoboxLinks:wikitext(' ' .. _makeLink(key, links[key .. index], variant)) | ||
-- Remove link from the collection | -- Remove link from the collection | ||
links[key .. index] = nil | links[key .. index] = nil | ||
Line 133: | Line 126: | ||
infoboxLinks:wikitext(' ' .. _makeLink(key, value, variant)) | infoboxLinks:wikitext(' ' .. _makeLink(key, value, variant)) | ||
end | end | ||
return mw.html.create('div'):node(infoboxLinks) | |||
end | end | ||
function _makeLink(key, value, variant) | function _makeLink(key, value, variant) | ||
key = | key = _removeAppendedNumber(key) | ||
return '[[Image:' .. (_ICON_KEYS_TO_RENAME[key] or key) .. '.png|40px|link=' .. | local link = UtilLinks.makeFullLink(key, value, variant) | ||
return '[[Image:' .. (_ICON_KEYS_TO_RENAME[key] or key) .. '.png|40px|link=' .. link[1] .. | |||
'|' .. (link[2] or '' ) .. ']]' | |||
-- ' <i class="lp-icon lp-' .. (_ICON_KEYS_TO_RENAME[key] or key) .. '></i>]' | -- ' <i class="lp-icon lp-' .. (_ICON_KEYS_TO_RENAME[key] or key) .. '></i>]' | ||
Line 149: | Line 142: | ||
--remove appended number | --remove appended number | ||
--needed because the link icons require e.g. 'esl' instead of 'esl2' | --needed because the link icons require e.g. 'esl' instead of 'esl2' | ||
function | function _removeAppendedNumber(key) | ||
return string.gsub(key, '%d$', '') | return string.gsub(key, '%d$', '') | ||
end | |||
function _isTableEmpty(tbl) | |||
for key, value in pairs(tbl) do | |||
return false | |||
end | |||
return true | |||
end | end | ||
return Links | return Links |
Latest revision as of 15:41, 12 October 2023
Documentation for this module may be created at Module:Infobox/Widget/Links/doc
local UtilLinks = require('Module:Links')
local Table = require('Module:Table')
local Links = {}
local _ICON_KEYS_TO_RENAME = {
['bilibili-stream'] = 'bilibili',
daumcafe = 'cafe-daum',
['esea-d'] = 'esea-league',
['faceit-c'] = 'faceit',
['faceit-c2'] = 'faceit',
['faceit-hub'] = 'faceit',
['faceit-org'] = 'faceit',
matcherinolink = 'matcherino',
playlist = 'music',
privsteam = 'steam',
pubsteam = 'steam',
steamalternative = 'steam',
tlpdint = 'tlpd',
tlpdkr = 'tlpd-wol-korea',
tlpdsospa = 'tlpd-sospa',
}
local _PRIORITY_GROUPS = {
core = {
'home',
'site',
'website'
},
league = {
'5ewin',
'abiosgaming',
'aligulac',
'battlefy',
'b5csgo',
'challengermode',
'challonge',
'cybergamer',
'datdota',
'dotabuff',
'esea',
'esea-d',
'esl',
'esportal',
'faceit',
'faceit-c',
'faceit-hub',
'faceit-org',
'factor',
'gamersclub',
'halodatahive',
'letsplaylive',
'matcherino',
'matcherinolink',
'siege-gg',
'sk',
'smash-gg',
'sostronk',
'stratz',
'toornament',
'trackmania-io',
'vlr',
'bracket',
'rules',
'rulebook',
},
social = {
'discord',
'facebook',
'instagram',
'privsteam',
'pubsteam',
'reddit',
'snapchat',
'steam',
'steamalternative',
'telegram',
'tiktok',
'twitter',
'vk',
'weibo',
'email',
'linkedin'
},
streams = {
'twitch',
'youtube',
'stream',
'afreeca',
'dlive',
'facebook-gaming',
'vidio',
'booyah',
'douyu',
'huyatv',
'zhangyutv',
'bilibili-stream',
'kuaishou',
}
}
function Links.make(links, variant)
if _isTableEmpty(links) then return nil end
local infoboxLinks = mw.html.create('div')
infoboxLinks :addClass('ib-links')
for _, group in Table.iter.spairs(_PRIORITY_GROUPS) do
for _, key in ipairs(group) do
if links[key] ~= nil then
infoboxLinks:wikitext(' ' .. _makeLink(key, links[key], variant))
-- Remove link from the collection
links[key] = nil
local index = 2
while links[key .. index] ~= nil do
infoboxLinks:wikitext(' ' .. _makeLink(key, links[key .. index], variant))
-- Remove link from the collection
links[key .. index] = nil
index = index + 1
end
end
end
end
for key, value in Table.iter.spairs(links) do
infoboxLinks:wikitext(' ' .. _makeLink(key, value, variant))
end
return mw.html.create('div'):node(infoboxLinks)
end
function _makeLink(key, value, variant)
key = _removeAppendedNumber(key)
local link = UtilLinks.makeFullLink(key, value, variant)
return '[[Image:' .. (_ICON_KEYS_TO_RENAME[key] or key) .. '.png|40px|link=' .. link[1] ..
'|' .. (link[2] or '' ) .. ']]'
-- ' <i class="lp-icon lp-' .. (_ICON_KEYS_TO_RENAME[key] or key) .. '></i>]'
end
--remove appended number
--needed because the link icons require e.g. 'esl' instead of 'esl2'
function _removeAppendedNumber(key)
return string.gsub(key, '%d$', '')
end
function _isTableEmpty(tbl)
for key, value in pairs(tbl) do
return false
end
return true
end
return Links