Module:DateTitleList:修订间差异

来自NeuroWiki
跳转到导航 跳转到搜索
无编辑摘要
无编辑摘要
第1行: 第1行:
local p = {}
local p = {}


-- 格式化日期和生成链接
local function format_date(date_str, title, year)
local function formatDate(date, title, year, baseYear)
     local year_in_date = string.sub(date_str, 1, 4)
     local dateYear = string.sub(date, 1, 4) -- 获取年份
     local month_day = os.date("%m月%d日", os.time{year=string.sub(date_str, 1, 4), month=string.sub(date_str, 5, 6), day=string.sub(date_str, 7, 8)})
     local monthDay = os.date("%m月%d日", os.time{
     local category_link = string.format("[[:Category:%s|%s]]", month_day, month_day)
        year = tonumber(dateYear),
        month = tonumber(string.sub(date, 5, 6)),
        day = tonumber(string.sub(date, 7, 8))
     })
      
      
    -- 构造分类链接
     if year_in_date ~= year then
    local categoryLink = '<span class="date-link">[[:Category:' .. monthDay .. '|' .. monthDay .. ']]</span>'
         category_link = string.format("[[:Category:%s|%s{{ruby|%s|''%s年''}}]]", month_day, month_day, year_in_date)
   
    -- 如果年份不同于baseYear,添加小号年份
     if dateYear ~= baseYear then
         categoryLink = '<span class="date-link">[[:Category:' .. monthDay .. '|{{ruby|' .. monthDay .. '|<span class="small-year">' .. dateYear .. '年</span>}}]]</span>'
     end
     end
      
      
    -- 构造页面链接
     local page_link = string.format("[[直播记录/vedal987频道/%s年%s|%s]]", year_in_date, month_day, title)
     local pageLink = "[[直播记录/vedal987频道/" .. dateYear .. "年" .. monthDay .. "|" .. title .. "]]"
     return string.format("* '''%s''' %s", category_link, page_link)
   
end
     return "* '''" .. categoryLink .. "''' " .. pageLink
 
local function compare_dates(a, b)
    return a.date < b.date
end
end


-- 主函数
function p.main(frame)
function p.render(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local year = args.year or os.date("%Y") -- 默认年份为当前年份
     local year = args.year or os.date("%Y")
     local entries = {}
     local entries = {}
   
 
    -- 收集date和title的对
     for i = 1, 7 do
     for i = 1, 7 do
         local date = args["date" .. i]
         local date = args["date" .. i]
第38行: 第30行:
         end
         end
     end
     end
   
 
    -- 按日期排序
     table.sort(entries, compare_dates)
     table.sort(entries, function(a, b) return a.date < b.date end)
 
   
     local result = {}
    -- 生成输出
     local output = {}
     for _, entry in ipairs(entries) do
     for _, entry in ipairs(entries) do
         table.insert(output, formatDate(entry.date, entry.title, year, year))
         table.insert(result, format_date(entry.date, entry.title, year))
     end
     end
   
 
     return table.concat(output, "\n")
     return table.concat(result, "\n")
end
end


return p
return p

2025年1月23日 (四) 00:40的版本

此模块的文档可以在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=string.sub(date_str, 1, 4), month=string.sub(date_str, 5, 6), day=string.sub(date_str, 7, 8)})
    local category_link = string.format("[[:Category:%s|%s]]", month_day, month_day)
    
    if year_in_date ~= year then
        category_link = string.format("[[:Category:%s|%s{{ruby|%s|''%s年''}}]]", month_day, month_day, year_in_date)
    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