Jump to content

Module:Update history navbox

From Bconomy Wiki
Revision as of 22:01, 3 November 2026 by Wewert (talk | contribs) (Add shared presentation support for game update navigation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Update history navbox/doc

local p = {}

local months = {
    'January', 'February', 'March', 'April', 'May', 'June',
    'July', 'August', 'September', 'October', 'November', 'December'
}

local function collapsible(parent, label, open)
    local panel = parent:tag('div')
        :addClass('bc-release-group mw-collapsible')
    if not open then
        panel:addClass('mw-collapsed')
    end
    panel:tag('div'):addClass('bc-release-group-label'):wikitext(label)
    return panel:tag('div'):addClass('mw-collapsible-content')
end

function p.render()
    local index = mw.title.new('Version history'):getContent() or ''
    local region = index:match('<!%-%- bconomy:begin version%-index %-%->(.-)<!%-%- bconomy:end version%-index %-%->')
    if not region then
        return '[[Version history|Browse the chronological index]]'
    end

    local root = mw.html.create('div'):addClass('bc-release-groups')
    local latestYear, latestMonth, year, month, yearBody, list
    for y, m, link in region:gmatch('| data%-sort%-value="(%d%d%d%d)%-(%d%d)%-%d%d"[^\n]*\n| (%[%[[^\n]+%]%])\n') do
        if not latestYear then
            latestYear, latestMonth = y, m
        end
        if year ~= y then
            year, month = y, nil
            yearBody = collapsible(root, y, y == latestYear)
        end
        if month ~= m then
            month = m
            list = collapsible(yearBody, months[tonumber(m)] or m, y == latestYear and m == latestMonth)
                :tag('ul'):addClass('bc-release-links')
        end
        local target, label = link:match('^%[%[([^|%]]+)|?([^%]]*)%]%]$')
        if target then
            label = (label ~= '' and label or target):gsub('^V(%d)', 'v%1')
            list:tag('li'):wikitext('[[' .. target .. '|' .. label .. ']]')
        end
    end
    if not latestYear then
        return '[[Version history|Browse the chronological index]]'
    end
    return tostring(root)
end

return p