Module:Top icons: Difference between revisions

From [N8]
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 4: Line 4:
local sites = {
local sites = {
gsm = {
gsm = {
format = 'You can find the Game here.',
format = ('https://geministation.com/ship'),
params = { 'gem', 'game', 'gs' },
params = { 'gem', 'game', 'gs', 'gsm' },
abbr = 'gs',
abbr = 'gs',
title = 'You can find the Game here.',
title = 'Return to ship.',
},
},
gsf = {
gsf = {
format = 'Visit the Gemini Station Forum.',
format = ('https://forum.geministation.com/'),
params = { 'gsf', 'gf' },
params = { 'gsf', 'gf' },
abbr = 'Forum',
abbr = 'Forum',
title = 'Visit the Gemini Station Forum.',
title = 'Visit the Gemini Station Forum',
},
},
wp = {  
wp = {  

Latest revision as of 16:39, 15 August 2020

Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [purge]

This module does not have any documentation. Please consider adding documentation at Module:Top icons/doc. [edit]


--<nowiki>
local p = {}

local sites = {
	gsm = {
		format = ('https://geministation.com/ship'),
		params = { 'gem', 'game', 'gs', 'gsm' },
		abbr = 'gs',
		title = 'Return to ship.',
		},
	gsf = {
		format = ('https://forum.geministation.com/'),
		params = { 'gsf', 'gf' },
		abbr = 'Forum',
		title = 'Visit the Gemini Station Forum',
		},
	wp = { 
		format = 'Wikipedia also has an article on: [[wikipedia:%s]]',
		params = { 'wikipedia', 'wp', 'w' },
		abbr = 'Wikipedia',
		title = 'Wikipedia also has an article on %s.',
		},
	}

local order = { 'gsm', 'gsf', 'wp' }

local allparams = {}

function p.main(frame)
	local args = frame:getParent().args
	local pagename = mw.title.getCurrentTitle().fullText
	local vals = {}
	-- create allparams
	for s,t in pairs(sites) do
		for _,v in ipairs(t.params) do
			allparams[v] = s
		end
	end
	
	-- loop named params
	for i,v in pairs(allparams) do
		if args[i] and not vals[v] then
			vals[v] = args[i]
		end
	end
	
	-- loop unnamed params
	local i = 1
	local v
	while args[i] do
		v = allparams[args[i]] 
		if v and not vals[v] then
			vals[v] = pagename
		end
		i = i + 1
	end
	
	local ret = mw.html.create('div')
	ret:addClass('gs-external-header-links'):css('display', 'none')
	for _,v in ipairs(order) do
		if vals[v] then
			local span = ret:tag('span')
			span:wikitext(string.format(sites[v].format, vals[v]))
				:addClass('gs-header-icon gs-header-icon-'..v)
				:attr({
						['data-title'] = string.format(sites[v].title, vals[v]),
						['data-site'] = v,
						['data-text'] = sites[v].abbr,
					})
		end
	end

	return tostring(ret)	
end

return p
--</nowiki>