加帕里图书馆 - 兽娘动物园中文维基
动物朋友 けものフレンズ KemonoFriends百科
模块:历史上的今天:修订间差异
跳转到导航
跳转到搜索
无编辑摘要 |
无编辑摘要 |
||
| (未显示同一用户的4个中间版本) | |||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
local data = mw.loadData('Module:历史上的今天/数据') | local data = mw.loadData('Module:历史上的今天/数据') | ||
function p.show() | function p.show() | ||
local | -- 获取当前日期 | ||
local current_date = os.date("%m-%d") -- 格式为 "03-16" | |||
-- | -- 完全保留你的逻辑 | ||
local month = tonumber(mw.getContentLanguage():formatDate("n")) | |||
local day = tonumber(mw.getContentLanguage():formatDate("j")) | |||
local key = month .. "-" .. day | |||
local month = mw.getContentLanguage():formatDate("n") | |||
local day = mw.getContentLanguage():formatDate("j") | |||
local key = month .. "-" .. day | |||
local today_events = data[key] | local today_events = data[key] | ||
local output = {} | |||
-- | -- 获取当前年份 | ||
local | local current_year = tonumber(os.date("%Y")) | ||
if today_events | -- table.insert(output, "== 历史上的" .. mw.getContentLanguage():formatDate("Mj") .. " ==\n") | ||
if today_events then | |||
-- 循环处理当天的所有事件 | -- 循环处理当天的所有事件 | ||
for _, item in ipairs(today_events) do | for _, item in ipairs(today_events) do | ||
local event_year = item.year | local event_year = item.year | ||
local years_ago = current_year - event_year | local years_ago = current_year - event_year | ||
local event_desc = item.event | local event_desc = item.event | ||
local line = string.format( | local line = string.format( | ||
"* '''%d年''' (%d 年前): %s", | "* '''%d年''' (%d 年前): %s", | ||
| 第41行: | 第36行: | ||
else | else | ||
-- 没有事件记录 | -- 没有事件记录 | ||
table.insert(output, " | table.insert(output, "这一天目前还没有数据记录") | ||
end | end | ||
2025年12月12日 (五) 12:47的最新版本
此模块的文档可以在模块:历史上的今天/doc创建
local p = {}
local data = mw.loadData('Module:历史上的今天/数据')
function p.show()
-- 获取当前日期
local current_date = os.date("%m-%d") -- 格式为 "03-16"
-- 完全保留你的逻辑
local month = tonumber(mw.getContentLanguage():formatDate("n"))
local day = tonumber(mw.getContentLanguage():formatDate("j"))
local key = month .. "-" .. day
local today_events = data[key]
local output = {}
-- 获取当前年份
local current_year = tonumber(os.date("%Y"))
-- table.insert(output, "== 历史上的" .. mw.getContentLanguage():formatDate("Mj") .. " ==\n")
if today_events 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
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