Module:DateTitleList
此模块的文档可以在Module:DateTitleList/doc创建
local p = {}
local function format_date(date_str, title, year)
local year_in_date = string.sub(date_str, 1, 4)
local month_day = os.date("%m月%d日", os.time{year=tonumber(year_in_date), month=tonumber(string.sub(date_str, 5, 6)), day=tonumber(string.sub(date_str, 7, 8))})
local category_link
if year_in_date ~= year then
category_link = string.format("[[:Category:%s|%s{{ruby|%s|''%s年''}}]]", month_day, month_day, month_day, year_in_date)
else
category_link = string.format("[[:Category:%s|%s]]", month_day, month_day)
end
local page_link = string.format("[[直播记录/vedal987频道/%s年%s|%s]]", year_in_date, month_day, title)
return string.format("* '''%s''' %s", category_link, page_link)
end
local function compare_dates(a, b)
return a.date < b.date
end
function p.main(frame)
local args = frame:getParent().args
local year = args.year or os.date("%Y")
local entries = {}
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, compare_dates)
local result = {}
for _, entry in ipairs(entries) do
table.insert(result, format_date(entry.date, entry.title, year))
end
return table.concat(result, "\n")
end
return p