Module:Main

From SW420
Revision as of 18:15, 5 May 2022 by imported>OOM 224 (reverting to classic glass arrow since the new one is virtually impossible to see in dark mode)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Main/doc

-- This module implements [[Template:Main]].

local p = {}

function p._main(args)
	args[1] = args[1] or '{{{1}}}'
	local links = {}
	for i, v in ipairs(args) do
		links[i] = string.format(
			'[[%s|%s]]',
			v,
			args['l' .. i] or v:gsub("/Legends", "")
		)
	end
	local prefix
	if #links > 1 then
		prefix = 'Main articles'
	else
		prefix = 'Main article'
	end
	links = mw.text.listToText(links)
	return string.format(
		'<div class="noprint rellink">[[File:Blue_Glass_Arrow.svg|20px|link=]] %s: %s</div>',
		prefix, links
	)
end

function p.main(frame)
	local args = {}
	for k, v in pairs(frame:getParent().args) do
		v = v:match('^%s*(.-)%s*$') -- trim whitespace
		if v ~= '' then
			args[k] = v
		end
	end
	return p._main(args)
end

return p