モジュール:OnThisDay

提供: 2ちゃんねるウィキペディアスレまとめwiki
移動先: 案内検索

このモジュールについての説明文ページを モジュール:OnThisDay/doc に作成できます

local p = {}

function p.main(frame)
	local date = mw.language.new('en'):formatDate('Mj', '+9 hours')
	local month, day = date:match('(%a+)(%d+)')
	day = tonumber(day)
	local dday = day
	local data = mw.text.jsonDecode(frame:expandTemplate({title = ('OnThisDay/' ..  month .. '.json')}):gsub('="(.-)"', '=\'%1\''))
	local event, pic, trad
	local result = {event = '', pic = '', trad = ''}
	
	event = data.event[day]
	if event then
		result.event = '<ul><li>' .. table.concat(event, '<li>') .. '</ul>'
	else
		result.event = '今日もjawpは平和です'
	end
	
	repeat
		pic = data.pic[dday]
		dday = dday - 1
	until pic
	for i in ipairs(pic) do
		result.pic = result.pic .. '[[File:' .. pic[i] .. '|x200px]]'
	end
	
	dday = day
	repeat
		trad = data.trad[dday]
		dday = dday - 1
	until trad
	for i in ipairs(trad) do
		local tplW = {title = 'w', args = {trad[i]:match('^([^|]*)|?(.*)')}}
		if (tplW.args[2] == '') then tplW.args[2] = nil end
		tplW.args.nosub = 'yes'
		result.trad = result.trad .. '<li data-mark=" - ">' .. frame:expandTemplate(tplW)
	end
	result.trad = '<ul class="hlist" style="display:block">'.. result.trad .. '</ul>'
	
	return '<h3><span style="padding:.2em 5em .2em 1em">[[Template:OnThisDay/' .. month .. '.json|今日は何の日]]</span></h3>' .. result.event .. '<h3><span style="padding:.2em 8em .2em 1em">風物詩</span></h3>' .. result.pic .. result.trad
end

return p