加帕里图书馆 - 兽娘动物园中文维基
动物朋友 けものフレンズ KemonoFriends百科
模块:历史上的今天
此模块的文档可以在模块:历史上的今天/doc创建
local p = {}
-- mw.loadData 是在缓存时加载的,这样数据只加载一次,性能好。
local data = mw.loadData('Module:历史上的今天/数据')
function p.show()
local output = {}
-- "n": 不带前导零的月份 (1-12)
-- "j": 不带前导零的日期 (1-31)
-- "Y": 4位年份
-- 获取当前的月和日,作为数据表的键 (例如 "3-16")
local month = mw.getContentLanguage():formatDate("n")
local day = mw.getContentLanguage():formatDate("j")
local key = month .. "-" .. day
local today_events = data[key]
-- 获取当前年份,用于计算“N年前”
local current_year_string = mw.getContentLanguage():formatDate("Y")
local current_year = tonumber(current_year_string)
if today_events and #today_events > 0 then
-- 循环处理当天的所有事件
for _, item in ipairs(today_events) do
local event_year = item.year
-- 计算多少年前
local years_ago = current_year - event_year
local event_desc = item.event
-- 使用 Wikitext 格式化输出
local line = string.format(
"* '''%d年''' (%d 年前): %s",
event_year,
years_ago,
event_desc
)
table.insert(output, line)
end
else
-- 没有事件记录
table.insert(output, "今日暂无历史事件记录")
end
-- 添加脚注/链接
table.insert(output, "\n<div style=\"text-align: right; margin-top: 5px; font-size: 85%;\">")
table.insert(output, "[[年表|查看完整年表]]")
table.insert(output, "</div>")
return table.concat(output, "\n")
end
return p