Module:NewsItem

From TwogPedia
Revision as of 02:38, 11 October 2022 by Couchor (talk | contribs)

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

local getArgs = require('Module:Arguments').getArgs
local Flags = require('Module:Flags')
local NewsItem = {}

function NewsItem.main(frame)
	local args = getArgs(frame)
	local container = mw.html.create('span'):addClass('newsItem')
	
	if args.date then
		local date = mw.html.create('span'):addClass('news-date'):wikitext(mw.text.split(args.date, ' ')[1])
		container:node(date)
	end
	
	if args.lang then
		container:node(Flags.icon(args.lang))
	else 
		container:node(Flags.icon('usuk'))
	end
	
	if args.url then
		if args.title and args.trans_title then
			container:wikitext('[' .. args.url .. ' ' .. args.title .. '] (' .. args.trans_title .. ')')
		elseif args.title then
			container:wikitext('[' .. args.url .. ' ' .. args.title .. ']')
		else
			container:wikitext('[' .. args.url .. ']')
		end
	end
	
	if args.author then
		container:wikitext(' by [[' ..args.author .. ']]')
	end
	
	if args.source then
		container:wikitext(' on [[' .. args.source .. ']]')
	end
	
	if args.event then
		container:wikitext(' at [[' .. args.event .. ']]')
	end
	
	if args.trans_lang then
		if args.translator then
			container:wikitext(' (translated into ' .. Flags.icon(args.trans_lang) .. 'by [[' .. args.translator .. ']])')	
		else
			container:wikitext(' (translated into ' .. Flags.icon(args.trans_lang) .. ')')	
		end
	end
	
	if args.note then
		container:node(mw.html.create('small'):wikitext(' (Note: ' .. args.note .. ')'))
	end
	
	return container
end

return NewsItem