LLWiki正在建设中,欢迎加入我们

模块:首页/日期

来自LLWiki
Bhsd讨论 | 贡献2022年2月1日 (二) 11:14的版本 (创建页面,内容为“local p = {} local getArgs = require('module:arguments').getArgs function p.main(frame) local args = getArgs(frame) local n = #args if n % 5 >= 3 then table.in…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转到导航 跳转到搜索

可在模块:首页/日期/doc创建此模块的帮助文档

local p = {}
local getArgs = require('module:arguments').getArgs

function p.main(frame)
	local args = getArgs(frame)
	local n = #args
	if n % 5 >= 3 then
		table.insert(args, nil)
	end
	if n % 5 == 3 then
		table.insert(args, nil)
	end
	
	local text = '<div class="mainpage-news"><div class="mainpage-news-time">'
	local hasTime = false
	
	for i, v in ipairs(args) do
		if i % 5 == 1 then
			text = text..'<span class="mainpage-date"><span class="countdown-num">'..v..'</span>/'
		elseif i % 5 == 2 then
			text = text..'<span class="countdown-num">'..v..'</span>'
		elseif i % 5 == 3 then
			text = text..'('..v..')'
		elseif i % 5 == 4 and v ~= nil then
			hasTime = true
			text = text..' <span class="countdown-num">'..v..'</span>'
		elseif i % 5 == 0 then
			if hasTime then
				v = string.format(v or 0, '%02d')
				text = text..':<span class="countdown-num">'..v..'</span>'
				hasTime = false
			end
			text = text..'</span>'
		end
	end
	
	return text..'</div><div class="mainpage-news-content">'
end

return p