Module:DateTitleList:修订间差异
跳转到导航
跳转到搜索
无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
local p = {} | local p = {} | ||
local function format_date(frame, date_str, title, year) | -- 格式化日期函数,增加对 CSS 类的支持 | ||
local function format_date(frame, date_str, title, year, css_class) | |||
-- 提取年份、月份和日期 | -- 提取年份、月份和日期 | ||
local year_in_date = string.sub(date_str, 1, 4) | local year_in_date = string.sub(date_str, 1, 4) | ||
第22行: | 第23行: | ||
end | end | ||
-- | -- 构造最终分类链接和页面链接 | ||
local category = string.format("[[:Category:%s|%s]]", month_day, category_link) | local category = string.format("[[:Category:%s|%s]]", month_day, category_link) | ||
local page_link = string.format("[[直播记录/vedal987频道/%s年%s|%s]]", year_in_date, month_day, title) | local page_link = string.format("[[直播记录/vedal987频道/%s年%s|%s]]", year_in_date, month_day, title) | ||
return string.format("* '''%s''' %s | -- 如果有 CSS 类,则将其应用到最外层 li | ||
if css_class then | |||
return string.format('<li class="%s">* \'\'\'%s\'\'\' %s</li>', css_class, category, page_link) | |||
else | |||
return string.format('<li>* \'\'\'%s\'\'\' %s</li>', category, page_link) | |||
end | |||
end | end | ||
-- 比较日期,用于排序 | |||
local function compare_dates(a, b) | local function compare_dates(a, b) | ||
return a.date < b.date | return a.date < b.date | ||
end | end | ||
-- 主函数 | |||
function p.main(frame) | function p.main(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
第38行: | 第46行: | ||
local entries = {} | local entries = {} | ||
-- | -- 收集日期、标题和样式 | ||
for i = 1, 7 do | for i = 1, 7 do | ||
local date = args["date" .. i] | local date = args["date" .. i] | ||
local title = args["title" .. i] | local title = args["title" .. i] | ||
local css_class = args["class" .. i] | |||
if date and title then | if date and title then | ||
table.insert(entries, {date = date, title = title}) | table.insert(entries, {date = date, title = title, css_class = css_class}) | ||
end | end | ||
end | end | ||
第53行: | 第62行: | ||
local result = {} | local result = {} | ||
for _, entry in ipairs(entries) do | for _, entry in ipairs(entries) do | ||
table.insert(result, format_date(frame, entry.date, entry.title, year)) | table.insert(result, format_date(frame, entry.date, entry.title, year, entry.css_class)) | ||
end | end | ||
-- | -- 包装在 <ul> 中,作为返回结果 | ||
return table.concat(result, "\n") | return '<ul class="date-title-list">' .. table.concat(result, "\n") .. '</ul>' | ||
end | end | ||
return p | return p |