Jump to content

Module:ReportTOC

From ClimateKG
Revision as of 11:51, 20 May 2026 by Laura (talk | contribs)

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

-- Module:ReportTOC
local p = {}

function p.renderChapter(frame, chNum)
    local title = frame.args['ch' .. chNum .. 'title']
    if not title or title == '' then
        return ''
    end
    
    local subtitle = frame.args['ch' .. chNum .. 'subtitle'] or ''
    local url = frame.args['ch' .. chNum .. 'url'] or ''
    
    local subtitleHtml = ''
    if subtitle ~= '' then
        subtitleHtml = '<span class="rtoc-entry-subtitle">' .. subtitle .. '</span>'
    end
    
    return '<div class="rtoc-entry"><div class="rtoc-entry-text"><span class="rtoc-entry-title">' .. title .. '</span>' .. subtitleHtml .. '</div><span class="rtoc-read">[[' .. url .. '|Read]]</span></div>'
end

function p.main(frame)
    local html = '<onlyinclude><div class="rtoc-box"><div class="rtoc-header">Contents</div>'
    
    -- Front Matter
    html = html .. '<div class="s-fm"><div class="rtoc-section-title">Front Matter</div><div class="rtoc-oos">Content in this section is out of scope</div></div>'
    
    -- SPM
    local spmTitle = frame.args['spmtitle']
    if spmTitle and spmTitle ~= '' then
        local spmSubtitle = frame.args['spmsubtitle'] or ''
        local spmUrl = frame.args['spmurl'] or ''
        local spmSubtitleHtml = ''
        if spmSubtitle ~= '' then
            spmSubtitleHtml = '<span class="rtoc-entry-subtitle">' .. spmSubtitle .. '</span>'
        end
        html = html .. '<div class="s-spm"><div class="rtoc-section-title">SPM</div><div class="rtoc-entry"><div class="rtoc-entry-text"><span class="rtoc-entry-title">' .. spmTitle .. '</span>' .. spmSubtitleHtml .. '</div><span class="rtoc-read">[[' .. spmUrl .. '|Read]]</span></div></div>'
    end
    
    -- TS
    local tsTitle = frame.args['tstitle']
    if tsTitle and tsTitle ~= '' then
        local tsSubtitle = frame.args['tssubtitle'] or ''
        local tsUrl = frame.args['tsurl'] or ''
        local tsSubtitleHtml = ''
        if tsSubtitle ~= '' then
            tsSubtitleHtml = '<span class="rtoc-entry-subtitle">' .. tsSubtitle .. '</span>'
        end
        html = html .. '<div class="s-ts"><div class="rtoc-section-title">TS</div><div class="rtoc-entry"><div class="rtoc-entry-text"><span class="rtoc-entry-title">' .. tsTitle .. '</span>' .. tsSubtitleHtml .. '</div><span class="rtoc-read">[[' .. tsUrl .. '|Read]]</span></div></div>'
    end
    
    -- Chapters
    local chapters = ''
    for i = 1, 25 do
        chapters = chapters .. p.renderChapter(frame, i)
    end
    if chapters ~= '' then
        html = html .. '<div class="s-ch"><div class="rtoc-section-title">Chapters</div>' .. chapters .. '</div>'
    end
    
    -- Annexes
    html = html .. '<div class="s-an"><div class="rtoc-section-title">Annexes</div><div class="rtoc-oos">Content in this section is out of scope</div></div>'
    
    html = html .. '</div></onlyinclude>'
    
    return html
end

return p