Module:Timeline: Difference between revisions

From aquila
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
local Calendar = require("Module:Calendar")
local p = {}
local p = {}
 
local dayLabels = {
local SEPARATOR = ";"
     "Early January", "January--February", "February--March", "March--April",  
local SPLIT_CHARACTERS = true
     "April--May", "May--June", "June", "June--July", "July--August",  
local LEGACY_MAX_EVENTS = 9
     "August--September", "September--October", "October--November",  
local EMPTY_ROW_TEXT = "No news"
     "November--December", "Late December"
local CARGO_TABLE = "NewsPosts"
local CARGO_FIELDS = "Page_Name,Title,Author,Publisher,RealDate,DayNum"
local CARGO_LIMIT = 1000
local DAY_LABELS = {}
for i, period in ipairs(Calendar.periods) do
    DAY_LABELS[i] = Calendar.pretty(period)
end
local DAYS_PER_YEAR = Calendar.daysPerYear
local SECTIONS = {
    Global    = "Global News",
     Domestic  = "Domestic News",
    Character = "Character News",
}
local TYPE_ALIASES = {
    ["global"]        = "Global News",
    ["global news"]    = "Global News",
    ["domestic"]      = "Domestic News",
     ["domestic news"]  = "Domestic News",
    ["character"]      = "Character News",
    ["character news"] = "Character News",
}
local COLUMNS = {
    { "In-universe date",   "24%" },
     { "Post",                "34%" },
    { "Character / nation", "24%" },
     { "Real-world date",     "18%" },
}
}
 
function p.renderTable(frame)
local SEP_PATTERN = (SEPARATOR:gsub("%p", "%%%0"))
     local year = tonumber(frame.args["Year"])
     local category = frame.args["Category"]
local function trim(s)
      
    return (tostring(s or ""):match("^%s*(.-)%s*$"))
end
local function errorText(message)
     return '<strong class="error">Timeline error: ' .. message .. "</strong>"
end
local function linkify(text)
    text = trim(text)
    if text == "" then return "" end
    if text:find("[[", 1, true) or text:find("^[%[<']") then
        return text
    end
    return "[[" .. text .. "]]"
end
local function linkifyCharacters(text)
    text = trim(text)
    if text == "" then return "" end
    if not SPLIT_CHARACTERS or text:find("[[", 1, true) or text:find("^[<']") then
        return linkify(text)
    end
     local parts = {}
    for part in (text .. ","):gmatch("(.-),") do
        part = trim(part)
        if part ~= "" then parts[#parts + 1] = linkify(part) end
    end
    return table.concat(parts, ", ")
end
local function normalizeTitle(name)
    name = trim((tostring(name or ""):gsub("_", " ")))
    return name:sub(1, 1):upper() .. name:sub(2)
end
local function linkTarget(wikitext)
    local target = tostring(wikitext or ""):match("^%[%[%s*:?([^%]|]+)")
     if target then
        return normalizeTitle(target)
    end
end
local function splitFields(line)
    line = line:gsub("(&#?%w+);", "%1\1")
    local fields = {}
    for field in (line .. SEPARATOR):gmatch("(.-)" .. SEP_PATTERN) do
        fields[#fields + 1] = trim((field:gsub("\1", ";")))
    end
    return fields
end
local function parseLine(line)
    line = trim(line)
    if line == "" then return nil end
    local f = splitFields(line)
    local post, char, date = f[1] or "", f[2] or "", f[3] or ""
    if post == "" and char == "" and date == "" then return nil end
    if post == "" then
        post = '<span class="error">(missing post title)</span>'
    else
        post = linkify(post)
    end
    if #f > 3 then
        post = post .. ' <span class="error">(too many “' .. SEPARATOR .. '” on this line)</span>'
    end
    return { post = post, char = linkifyCharacters(char), date = date }
end
local function collectManualEvents(getArg, day)
     local events = {}
     local events = {}
     for i = 1, 14 do events[i] = {} end
 
    local text = getArg("Day" .. day)
     -- Parse parameters, but ONLY keep them if they have actual text in them
    if text and trim(text) ~= "" then
     for k, v in pairs(frame.args) do
        for line in (text .. "\n"):gmatch("(.-)\r?\n") do
         local day, index, field = string.match(k, "^Day(%d+)_(%d+)_(%w+)$")
            local ev = parseLine(line)
         if day and index and field then
            if ev then events[#events + 1] = ev end
            day = tonumber(day)
        end
            index = tonumber(index)
    end
              
             if events[day][index] == nil then
     for n = 1, LEGACY_MAX_EVENTS do
                 events[day][index] = {}
        local prefix = "Day" .. day .. "_" .. n .. "_"
        local post = trim(getArg(prefix .. "Post"))
        if post ~= "" then
            events[#events + 1] = {
                post = linkify(post),
                char = linkifyCharacters(getArg(prefix .. "Char")),
                date = trim(getArg(prefix .. "Date")),
            }
        end
    end
     return events
end
local function cargoEvents(typeName, year)
    local byDay, names = {}, {}
     for day = 1, DAYS_PER_YEAR do byDay[day] = {} end
    if not (mw.ext and mw.ext.cargo) then
         return byDay, names, "the Cargo extension is not available to Lua"
    end
    local ok, rows = pcall(mw.ext.cargo.query, CARGO_TABLE, CARGO_FIELDS, {
        where = 'Type="' .. typeName .. '" AND YearNum=' .. string.format("%d", year),
        orderBy = "RealDate,_pageID",
        limit = CARGO_LIMIT,
    })
    if not ok then
        return byDay, names, tostring(rows)
    end
    for _, row in ipairs(rows) do
        local info = Calendar.info(row.RealDate)
         local day = tonumber(row.DayNum) or (info and info.day)
        local page = trim(row.Page_Name)
        if page ~= "" and day and day >= 1 and day <= DAYS_PER_YEAR then
             local title = trim(row.Title)
             if title == "" then
                 title = page:match("[^/]+$") or page
             end
             end
            events[day][index][field] = v
           
             local post
             -- If the Post is provided, consider this a valid event
             if title == page then
             if field == "Post" and v ~= "" then
                post = "[[" .. page .. "]]"
                 events[day][index].isValid = true
            else
                 post = "[[" .. page .. "|" .. title .. "]]"
             end
             end
        end
    end
            local char
 
             if trim(row.Author) ~= "" then
    -- Cleanup empty events and count valid ones
                 char = linkify(row.Author)
    local validCounts = {}
    for i = 1, 14 do
        validCounts[i] = 0
        for j = 1, 20 do
             if events[i][j] and events[i][j].isValid then
                 validCounts[i] = validCounts[i] + 1
             else
             else
                 events[i][j] = nil
                 char = linkifyCharacters(row.Publisher)
             end
             end
            names[normalizeTitle(page)] = true
            local list = byDay[day]
            list[#list + 1] = {
                post = post,
                char = char,
                date = info and info.iso or trim(row.RealDate),
            }
         end
         end
     end
     end
 
     local html = {}
     return byDay, names
     table.insert(html, '{| class="wikitable mw-collapsible" style="width: 100%; margin-top: 10px; font-size: 85%; line-height: 1.4; border-collapse: collapse;"')
end
     table.insert(html, '|+ Era Nova, Year ' .. year .. ' — ' .. category .. ' Timeline')
    table.insert(html, '! In-Universe Date')
local function cell(content, attrs)
     table.insert(html, '! Post')
     return "<td" .. (attrs or "") .. ">" .. content .. "</td>"
     table.insert(html, '! Character / Nation')
end
     table.insert(html, '! Real-World Date')
    table.insert(html, '|-')
local function rangeLabel(first, last, year)
     table.insert(html, '! colspan="4" style="background-color: #f1f5f9; color: #0b132b; text-align: center; font-weight: bold; padding: 6px;" | ' .. string.upper(category) .. ' NEWS')
     if first == last then
     table.insert(html, '|-')
        return DAY_LABELS[first] .. ", Year " .. year
 
    end
    -- This loop correctly handles grouping empty dates
    return DAY_LABELS[first] .. " to " .. DAY_LABELS[last] .. ", Year " .. year
     local i = 1
end
     while i <= 14 do
         if validCounts[i] == 0 then
local function renderSection(title, year, schedule)
             -- Find how many consecutive empty days there are
     local out = {}
             local emptySpan = 1
      
             for j = i + 1, 14 do
     -- Table Wrapper
                 if validCounts[j] == 0 then
     out[#out + 1] = '<div style="overflow-x:auto; border: 1px solid #d1d5db; border-radius: 12px; margin-bottom: 2em; box-shadow: 0 4px 12px rgba(0,0,0,0.05);">'
                    emptySpan = emptySpan + 1
    out[#out + 1] = '<table class="aquila-timeline-custom">'
                 else
                     break
    -- Section Title
    out[#out + 1] = '<tr><th colspan="4" class="tl-header">' .. title .. "</th></tr>"
    -- Column Headers
    local head = {}
    for _, col in ipairs(COLUMNS) do
        head[#head + 1] = '<th style="width:' .. col[2] .. ';">' .. col[1] .. "</th>"
    end
     out[#out + 1] = "<tr>" .. table.concat(head) .. "</tr>"
     local day = 1
     while day <= DAYS_PER_YEAR do
        local events = schedule[day]
        local count = #events
         if count > 0 then
            local default = Calendar.realDate(year, day)
            local dates, span = {}, {}
            for i, ev in ipairs(events) do
                dates[i] = (ev.date ~= "") and ev.date or default
             end
             local i = 1
             while i <= count do
                local j = i
                while j < count and dates[j + 1] == dates[i] do j = j + 1 end
                 span[i] = j - i + 1
                i = j + 1
            end
            for idx, ev in ipairs(events) do
                 local row = {}
                if idx == 1 then
                     row[#row + 1] = '<td class="tl-day"' .. (count > 1 and ' rowspan="' .. count .. '"' or "") .. '>' .. DAY_LABELS[day] .. ", Year " .. year .. '</td>'
                 end
                 end
                row[#row + 1] = cell(ev.post)
                row[#row + 1] = cell(ev.char)
                if span[idx] then
                    row[#row + 1] = '<td class="tl-date"' .. (span[idx] > 1 and ' rowspan="' .. span[idx] .. '"' or "") .. '>' .. dates[idx] .. '</td>'
                end
                out[#out + 1] = "<tr>" .. table.concat(row) .. "</tr>"
             end
             end
              
             day = day + 1
            local dateLabel = dayLabels[i]
            if emptySpan > 1 then
                dateLabel = dayLabels[i] .. " to<br>" .. dayLabels[i + emptySpan - 1]
            end
            dateLabel = dateLabel .. ", Year " .. year
           
            table.insert(html, '| ' .. dateLabel)
            table.insert(html, '| ')
            table.insert(html, '| ')
            table.insert(html, '| ')
            table.insert(html, '|-')
           
            -- Skip ahead by the number of empty days we just grouped
            i = i + emptySpan
         else
         else
             -- There are events on this day
             local first = day
             local rowspanAttr = ''
             while day <= DAYS_PER_YEAR and #schedule[day] == 0 do
            if validCounts[i] > 1 then
                 day = day + 1
                 rowspanAttr = ' rowspan="' .. validCounts[i] .. '" '
             end
             end
            local last = day - 1
            local startDate, endDate = Calendar.realDate(year, first), Calendar.realDate(year, last)
              
              
             table.insert(html, '|' .. rowspanAttr .. '| ' .. dayLabels[i] .. ', Year ' .. year)
             -- THIS IS THE FIX: Added <br> before the "to"
           
            local dateText = (first == last) and startDate or (startDate .. " to<br>" .. endDate)
            local rowPrinted = 0
            for j = 1, 20 do
            out[#out + 1] = "<tr>"
                local event = events[i][j]
                .. '<td class="tl-empty">' .. rangeLabel(first, last, year) .. '</td>'
                if event and event.isValid then
                .. '<td colspan="2" class="tl-empty-text">' .. EMPTY_ROW_TEXT .. '</td>'
                    if rowPrinted > 0 then
                .. '<td class="tl-date">' .. dateText .. '</td>'
                        table.insert(html, '|-')
                .. "</tr>"
                    end
        end
                   
    end
                    local postText = event.Post or ""
                    if postText ~= "" and not string.find(postText, "%[%[") then
    out[#out + 1] = "</table>"
                        postText = "[[" .. postText .. "]]"
    out[#out + 1] = "</div>"
                    end
    return table.concat(out, "\n")
                   
end
                    local charText = event.Char or ""
                    if charText ~= "" and not string.find(charText, "%[%[") then
function p.newsType(frame)
                        charText = "[[" .. charText .. "]]"
    local key = trim(frame.args[1]):lower()
                    end
    return TYPE_ALIASES[key] or SECTIONS.Character
 
end
                    local dateText = event.Date or ""
                    if dateText == "" then
function p.render(frame)
                        local daysOffset = ((year - 1) * 14) + (i - 1)
    local own = frame.args
                        local timestamp = os.time({year=2026, month=07, day=28, hour=12}) + (daysOffset * 86400)
    local parent = frame:getParent()
                        dateText = os.date("%Y-%m-%d", timestamp)
    local inherited = parent and parent.args or {}
                    end
 
    local function getArg(name)
                    table.insert(html, '| ' .. postText)
        local v = inherited[name]
                    table.insert(html, '| ' .. charText)
        if v == nil or trim(v) == "" then v = own[name] end
                    table.insert(html, '| ' .. dateText)
        return v
                    table.insert(html, '|-')
    end
                    rowPrinted = rowPrinted + 1
                end
    local key = trim(getArg("Category"))
    local title = SECTIONS[key]
    if not title then
        return errorText('unknown Category "' .. key .. '" (use Global, Domestic or Character).')
    end
    local year = tonumber(trim(getArg("Year")))
    if not year or year < 1 or year ~= math.floor(year) then
        return errorText("set <code>Year</code> to a whole number, 1 or higher.")
    end
    local auto, names, cargoError = {}, {}, nil
    if trim(getArg("Auto")):lower() ~= "no" then
        auto, names, cargoError = cargoEvents(title, year)
    end
    local schedule = {}
    for day = 1, DAYS_PER_YEAR do
        local events = {}
        for _, ev in ipairs(collectManualEvents(getArg, day)) do
            local target = linkTarget(ev.post)
            if not (target and names[target]) then
                events[#events + 1] = ev
             end
             end
            i = i + 1
         end
         end
        for _, ev in ipairs(auto[day] or {}) do
            events[#events + 1] = ev
        end
        schedule[day] = events
    end
    local html = renderSection(title, year, schedule)
    if cargoError then
        html = html .. '\n<div class="error">Could not read the Cargo table “' .. CARGO_TABLE
            .. "”: " .. cargoError .. "</div>"
     end
     end
 
     return html
    table.insert(html, '|}')
     return table.concat(html, "\n")
end
end
 
return p
return p

Latest revision as of 11:04, 24 October 2026

Documentation for this module may be created at Module:Timeline/doc

local Calendar = require("Module:Calendar")
 
local p = {}
 
local SEPARATOR = ";"
local SPLIT_CHARACTERS = true
local LEGACY_MAX_EVENTS = 9
local EMPTY_ROW_TEXT = "No news"
 
local CARGO_TABLE = "NewsPosts"
local CARGO_FIELDS = "Page_Name,Title,Author,Publisher,RealDate,DayNum"
local CARGO_LIMIT = 1000
 
local DAY_LABELS = {}
for i, period in ipairs(Calendar.periods) do
    DAY_LABELS[i] = Calendar.pretty(period)
end
local DAYS_PER_YEAR = Calendar.daysPerYear
 
local SECTIONS = {
    Global    = "Global News",
    Domestic  = "Domestic News",
    Character = "Character News",
}
 
local TYPE_ALIASES = {
    ["global"]         = "Global News",
    ["global news"]    = "Global News",
    ["domestic"]       = "Domestic News",
    ["domestic news"]  = "Domestic News",
    ["character"]      = "Character News",
    ["character news"] = "Character News",
}
 
local COLUMNS = {
    { "In-universe date",    "24%" },
    { "Post",                "34%" },
    { "Character / nation",  "24%" },
    { "Real-world date",     "18%" },
}
 
local SEP_PATTERN = (SEPARATOR:gsub("%p", "%%%0"))
 
local function trim(s)
    return (tostring(s or ""):match("^%s*(.-)%s*$"))
end
 
local function errorText(message)
    return '<strong class="error">Timeline error: ' .. message .. "</strong>"
end
 
local function linkify(text)
    text = trim(text)
    if text == "" then return "" end
    if text:find("[[", 1, true) or text:find("^[%[<']") then
        return text
    end
    return "[[" .. text .. "]]"
end
 
local function linkifyCharacters(text)
    text = trim(text)
    if text == "" then return "" end
    if not SPLIT_CHARACTERS or text:find("[[", 1, true) or text:find("^[<']") then
        return linkify(text)
    end
    local parts = {}
    for part in (text .. ","):gmatch("(.-),") do
        part = trim(part)
        if part ~= "" then parts[#parts + 1] = linkify(part) end
    end
    return table.concat(parts, ", ")
end
 
local function normalizeTitle(name)
    name = trim((tostring(name or ""):gsub("_", " ")))
    return name:sub(1, 1):upper() .. name:sub(2)
end
 
local function linkTarget(wikitext)
    local target = tostring(wikitext or ""):match("^%[%[%s*:?([^%]|]+)")
    if target then
        return normalizeTitle(target)
    end
end
 
local function splitFields(line)
    line = line:gsub("(&#?%w+);", "%1\1")
    local fields = {}
    for field in (line .. SEPARATOR):gmatch("(.-)" .. SEP_PATTERN) do
        fields[#fields + 1] = trim((field:gsub("\1", ";")))
    end
    return fields
end
 
local function parseLine(line)
    line = trim(line)
    if line == "" then return nil end
 
    local f = splitFields(line)
    local post, char, date = f[1] or "", f[2] or "", f[3] or ""
    if post == "" and char == "" and date == "" then return nil end
 
    if post == "" then
        post = '<span class="error">(missing post title)</span>'
    else
        post = linkify(post)
    end
    if #f > 3 then
        post = post .. ' <span class="error">(too many “' .. SEPARATOR .. '” on this line)</span>'
    end
    return { post = post, char = linkifyCharacters(char), date = date }
end
 
local function collectManualEvents(getArg, day)
    local events = {}
 
    local text = getArg("Day" .. day)
    if text and trim(text) ~= "" then
        for line in (text .. "\n"):gmatch("(.-)\r?\n") do
            local ev = parseLine(line)
            if ev then events[#events + 1] = ev end
        end
    end
 
    for n = 1, LEGACY_MAX_EVENTS do
        local prefix = "Day" .. day .. "_" .. n .. "_"
        local post = trim(getArg(prefix .. "Post"))
        if post ~= "" then
            events[#events + 1] = {
                post = linkify(post),
                char = linkifyCharacters(getArg(prefix .. "Char")),
                date = trim(getArg(prefix .. "Date")),
            }
        end
    end
 
    return events
end
 
local function cargoEvents(typeName, year)
    local byDay, names = {}, {}
    for day = 1, DAYS_PER_YEAR do byDay[day] = {} end
 
    if not (mw.ext and mw.ext.cargo) then
        return byDay, names, "the Cargo extension is not available to Lua"
    end
 
    local ok, rows = pcall(mw.ext.cargo.query, CARGO_TABLE, CARGO_FIELDS, {
        where = 'Type="' .. typeName .. '" AND YearNum=' .. string.format("%d", year),
        orderBy = "RealDate,_pageID",
        limit = CARGO_LIMIT,
    })
    if not ok then
        return byDay, names, tostring(rows)
    end
 
    for _, row in ipairs(rows) do
        local info = Calendar.info(row.RealDate)
        local day = tonumber(row.DayNum) or (info and info.day)
        local page = trim(row.Page_Name)
 
        if page ~= "" and day and day >= 1 and day <= DAYS_PER_YEAR then
            local title = trim(row.Title)
            if title == "" then
                title = page:match("[^/]+$") or page
            end
 
            local post
            if title == page then
                post = "[[" .. page .. "]]"
            else
                post = "[[" .. page .. "|" .. title .. "]]"
            end
 
            local char
            if trim(row.Author) ~= "" then
                char = linkify(row.Author)
            else
                char = linkifyCharacters(row.Publisher)
            end
 
            names[normalizeTitle(page)] = true
            local list = byDay[day]
            list[#list + 1] = {
                post = post,
                char = char,
                date = info and info.iso or trim(row.RealDate),
            }
        end
    end
 
    return byDay, names
end
 
local function cell(content, attrs)
    return "<td" .. (attrs or "") .. ">" .. content .. "</td>"
end
 
local function rangeLabel(first, last, year)
    if first == last then
        return DAY_LABELS[first] .. ", Year " .. year
    end
    return DAY_LABELS[first] .. " to " .. DAY_LABELS[last] .. ", Year " .. year
end
 
local function renderSection(title, year, schedule)
    local out = {}
    
    -- Table Wrapper
    out[#out + 1] = '<div style="overflow-x:auto; border: 1px solid #d1d5db; border-radius: 12px; margin-bottom: 2em; box-shadow: 0 4px 12px rgba(0,0,0,0.05);">'
    out[#out + 1] = '<table class="aquila-timeline-custom">'
 
    -- Section Title
    out[#out + 1] = '<tr><th colspan="4" class="tl-header">' .. title .. "</th></tr>"
 
    -- Column Headers
    local head = {}
    for _, col in ipairs(COLUMNS) do
        head[#head + 1] = '<th style="width:' .. col[2] .. ';">' .. col[1] .. "</th>"
    end
    out[#out + 1] = "<tr>" .. table.concat(head) .. "</tr>"
 
    local day = 1
    while day <= DAYS_PER_YEAR do
        local events = schedule[day]
        local count = #events
 
        if count > 0 then
            local default = Calendar.realDate(year, day)
            local dates, span = {}, {}
            for i, ev in ipairs(events) do
                dates[i] = (ev.date ~= "") and ev.date or default
            end
            local i = 1
            while i <= count do
                local j = i
                while j < count and dates[j + 1] == dates[i] do j = j + 1 end
                span[i] = j - i + 1
                i = j + 1
            end
 
            for idx, ev in ipairs(events) do
                local row = {}
                if idx == 1 then
                    row[#row + 1] = '<td class="tl-day"' .. (count > 1 and ' rowspan="' .. count .. '"' or "") .. '>' .. DAY_LABELS[day] .. ", Year " .. year .. '</td>'
                end
                row[#row + 1] = cell(ev.post)
                row[#row + 1] = cell(ev.char)
                if span[idx] then
                    row[#row + 1] = '<td class="tl-date"' .. (span[idx] > 1 and ' rowspan="' .. span[idx] .. '"' or "") .. '>' .. dates[idx] .. '</td>'
                end
                out[#out + 1] = "<tr>" .. table.concat(row) .. "</tr>"
            end
            day = day + 1
        else
            local first = day
            while day <= DAYS_PER_YEAR and #schedule[day] == 0 do
                day = day + 1
            end
            local last = day - 1
 
            local startDate, endDate = Calendar.realDate(year, first), Calendar.realDate(year, last)
            
            -- THIS IS THE FIX: Added <br> before the "to"
            local dateText = (first == last) and startDate or (startDate .. " to<br>" .. endDate)
 
            out[#out + 1] = "<tr>"
                .. '<td class="tl-empty">' .. rangeLabel(first, last, year) .. '</td>'
                .. '<td colspan="2" class="tl-empty-text">' .. EMPTY_ROW_TEXT .. '</td>'
                .. '<td class="tl-date">' .. dateText .. '</td>'
                .. "</tr>"
        end
    end
 
    out[#out + 1] = "</table>"
    out[#out + 1] = "</div>"
    return table.concat(out, "\n")
end
 
function p.newsType(frame)
    local key = trim(frame.args[1]):lower()
    return TYPE_ALIASES[key] or SECTIONS.Character
end
 
function p.render(frame)
    local own = frame.args
    local parent = frame:getParent()
    local inherited = parent and parent.args or {}
 
    local function getArg(name)
        local v = inherited[name]
        if v == nil or trim(v) == "" then v = own[name] end
        return v
    end
 
    local key = trim(getArg("Category"))
    local title = SECTIONS[key]
    if not title then
        return errorText('unknown Category "' .. key .. '" (use Global, Domestic or Character).')
    end
 
    local year = tonumber(trim(getArg("Year")))
    if not year or year < 1 or year ~= math.floor(year) then
        return errorText("set <code>Year</code> to a whole number, 1 or higher.")
    end
 
    local auto, names, cargoError = {}, {}, nil
    if trim(getArg("Auto")):lower() ~= "no" then
        auto, names, cargoError = cargoEvents(title, year)
    end
 
    local schedule = {}
    for day = 1, DAYS_PER_YEAR do
        local events = {}
        for _, ev in ipairs(collectManualEvents(getArg, day)) do
            local target = linkTarget(ev.post)
            if not (target and names[target]) then
                events[#events + 1] = ev
            end
        end
        for _, ev in ipairs(auto[day] or {}) do
            events[#events + 1] = ev
        end
        schedule[day] = events
    end
 
    local html = renderSection(title, year, schedule)
    if cargoError then
        html = html .. '\n<div class="error">Could not read the Cargo table “' .. CARGO_TABLE
            .. "”: " .. cargoError .. "</div>"
    end
    return html
end
 
return p