Module:DateTitleList: Difference between revisions

Created page with "local p = {} -- 英文月份映射表 local month_map = { ["01"] = {short = "Jan", full = "January"}, ["02"] = {short = "Feb", full = "February"}, ["03"] = {short = "Mar", full = "March"}, ["04"] = {short = "Apr", full = "April"}, ["05"] = {short = "May", full = "May"}, ["06"] = {short = "Jun", full = "June"}, ["07"] = {short = "Jul", full = "July"}, ["08"] = {short = "Aug", full = "August"}, ["09"] = {short = "Sep", full = "September..."
 
No edit summary
Line 18: Line 18:


-- 格式化日期
-- 格式化日期
local function format_date(frame, date_str, title, year)
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)
Line 47: Line 47:
     local page_link = string.format("[[Streaming_Records/vedal987_Channel/%s %s %d|%s]]", month_full, day, year_in_date, title)
     local page_link = string.format("[[Streaming_Records/vedal987_Channel/%s %s %d|%s]]", month_full, day, year_in_date, title)


     return string.format("* '''%s''' %s", category, page_link)
     -- 如果有 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


Line 61: Line 66:
     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
Line 76: Line 82:
     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