Module:DateTitleList:修订间差异
无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
local p = {} | |||
-- 格式化日期和生成链接 | |||
local function formatDate(date, title, year, baseYear) | local function formatDate(date, title, year, baseYear) | ||
local dateYear = string.sub(date, 1, 4) -- 获取年份 | local dateYear = string.sub(date, 1, 4) -- 获取年份 | ||
第20行: | 第23行: | ||
return "* '''" .. categoryLink .. "''' " .. pageLink | return "* '''" .. categoryLink .. "''' " .. pageLink | ||
end | end | ||
-- 主函数 | |||
function p.render(frame) | |||
local args = frame:getParent().args | |||
local year = args.year or os.date("%Y") -- 默认年份为当前年份 | |||
local entries = {} | |||
-- 收集date和title的对 | |||
for i = 1, 7 do | |||
local date = args["date" .. i] | |||
local title = args["title" .. i] | |||
if date and title then | |||
table.insert(entries, {date = date, title = title}) | |||
end | |||
end | |||
-- 按日期排序 | |||
table.sort(entries, function(a, b) return a.date < b.date end) | |||
-- 生成输出 | |||
local output = {} | |||
for _, entry in ipairs(entries) do | |||
table.insert(output, formatDate(entry.date, entry.title, year, year)) | |||
end | |||
return table.concat(output, "\n") | |||
end | |||
return p |