Module:DateTitleList

来自NeuroWiki
Selfice留言 | 贡献2025年1月23日 (四) 00:35的版本
跳转到导航 跳转到搜索

此模块的文档可以在Module:DateTitleList/doc创建

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