Jump to content

Module:Social links

From Meta, a Wikimedia project coordination wiki
Module documentation

Usage

[edit]

This module is a sub-component of Template:Connect group. For more information, see Template:Connect group/doc.

local p = {}

function get_link(frame, label, link, file)
	return frame:expandTemplate{
		title = 'Link with icon',
		args = { label = label, link = link, file = file }
	} .. '\n\n'
end

function p.render(frame)
	-- "Humanized" names: basically template parameter names but with capital
	-- letters and/or spaces as needed. By default the module takes a parameter
	-- name, makes the first letter uppercase, and calls it a day. For names
	-- that require further transformations, define them below.
	humanized_name_map = {
		bitbucket = 'BitBucket',
		github = 'GitHub',
		googleplus = 'Google Plus',
		linkedin = 'LinkedIn',
		stumbleupon = 'StumbleUpon',
		tencentweibo = 'Tencent Weibo',
		vk = 'VK',
		wechat = 'WeChat',
		whatsapp = 'WhatsApp',
		youtube = 'YouTube'
	}
	content = ''
	for key, value in pairs(frame:getParent().args) do
		-- {{Link with icon|label=Facebook|link=https://facebook.com|file=Facebook font awesome.svg}}
		if key ~= 'icon' and key ~= 'introduction' then
			if humanized_name_map[key] ~= nil then
				-- Custom-defined transformations b/w parameter name and humanized name
				humanized_name = humanized_name_map[key]
			else
				-- Take lowercase name and make the first letter capital.
				-- facebook --> Facebook
				humanized_name = key:gsub("^%l", string.upper)
			end
			content = content .. get_link(frame, humanized_name, value, humanized_name .. ' font awesome.svg')
		end
	end
	return content
end
		
return p