Module:DateTitleList:修订间差异

无编辑摘要
无编辑摘要
第1行: 第1行:
local p = {}
local p = {}


local function format_date(date_str, title, year)
local function format_date(frame, date_str, title, year)
    -- 提取年份、月份和日期
     local year_in_date = string.sub(date_str, 1, 4)
     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 month = tonumber(string.sub(date_str, 5, 6)) -- 去掉前导零
    local day = tonumber(string.sub(date_str, 7, 8)) -- 去掉前导零
 
    -- 格式化日期为 "X月X日"
    local month_day = string.format("%d月%d日", month, day)
 
    -- 构造分类链接和 ruby 模板
     local category_link
     local category_link
     if year_in_date ~= year then
     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)
        -- 使用 ruby 模板
         category_link = frame:expandTemplate{
            title = "ruby",
            args = { month_day, year_in_date .. "年" }
        }
     else
     else
         category_link = string.format("[[:Category:%s|%s]]", month_day, month_day)
         category_link = month_day
     end
     end


    -- 构造最终输出
    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", category_link, page_link)
 
     return string.format("* '''%s''' %s", category, page_link)
end
end


第25行: 第38行:
     local entries = {}
     local entries = {}


    -- 收集日期和标题
     for i = 1, 7 do
     for i = 1, 7 do
         local date = args["date" .. i]
         local date = args["date" .. i]
第33行: 第47行:
     end
     end


    -- 按日期排序
     table.sort(entries, compare_dates)
     table.sort(entries, compare_dates)


    -- 生成输出列表
     local result = {}
     local result = {}
     for _, entry in ipairs(entries) do
     for _, entry in ipairs(entries) do
         table.insert(result, format_date(entry.date, entry.title, year))
         table.insert(result, format_date(frame, entry.date, entry.title, year))
     end
     end


    -- 合并为字符串输出
     return table.concat(result, "\n")
     return table.concat(result, "\n")
end
end


return p
return p