Module:ChapterNavbox: Difference between revisions

From Candypedia
No edit summary
Adding list of obsolete chapters, fixing capitalisation
 
(8 intermediate revisions by 3 users not shown)
Line 8: Line 8:
         end_ = 46,
         end_ = 46,
         style = 'background:#707ebd;color:white;',
         style = 'background:#707ebd;color:white;',
        group = 'group1',
        list = 'list1',
     },
     },
     {
     {
Line 14: Line 16:
         end_ = 58,
         end_ = 58,
         style = 'background:#912f28;color:white;',
         style = 'background:#912f28;color:white;',
        group = 'group2',
        list = 'list2',
     },
     },
     {
     {
Line 20: Line 24:
         end_ = 69.1,
         end_ = 69.1,
         style = 'background:#2b8842;color:white;',
         style = 'background:#2b8842;color:white;',
        group = 'group3',
        list = 'list3',
     },
     },
     {
     {
Line 26: Line 32:
         end_ = 80,
         end_ = 80,
         style = 'background:#4589c8;color:white;',
         style = 'background:#4589c8;color:white;',
        group = 'group4',
        list = 'list4',
     },
     },
     {
     {
Line 32: Line 40:
         end_ = 88,
         end_ = 88,
         style = 'background:#aa715e;color:white;',
         style = 'background:#aa715e;color:white;',
        group = 'group5',
        list = 'list5',
     },
     },
     {
     {
Line 38: Line 48:
         end_ = 96.1,
         end_ = 96.1,
         style = 'background:#f27191;color:white;',
         style = 'background:#f27191;color:white;',
        group = 'group6',
        list = 'list6',
     },
     },
     {
     {
Line 44: Line 56:
         end_ = 110,
         end_ = 110,
         style = 'background:#efb63b;color:white;',
         style = 'background:#efb63b;color:white;',
        group = 'group7',
        list = 'list7',
     },
     },
}
-- Manually defined book-exclusive chapters
local bookExclusiveChapters = {
    {title = "Curtain Rising", link = "Curtain_Rising"},
    {title = "No Service", link = "No_Service"},
    {title = "Critical Eye", link = "Critical_Eye"},
    {title = "Payback", link = "Payback"},
    {title = "Fashion Disaster", link = "Fashion_Disaster"},
    {title = "There’s a Chance", link = "There’s_a_Chance"},
    {title = "Afterglow", link = "Afterglow"},
    {title = "Unpacking Day", link = "Unpacking_Day"},
    {title = "Good Egg", link = "Good_Egg"},
}
}


Line 53: Line 80:
end
end


function p.generateNavbox()
function p.generateNavbox(frame)
     local chaptersModule = require('Module:Chapters')
     local chaptersModule = require('Module:Chapters')
     local chapters = chaptersModule.getChaptersList()
     local chapters = chaptersModule.getChaptersList()


     local navbox = mw.html.create('table')
     local navboxParams = {
    navbox:addClass('navbox')
        bodyclass = 'hlist',
 
        name = 'Bittersweet Candy Bowl chapters',
    -- Add title row
         title = "[[Bittersweet Candy Bowl]] chapters",
    navbox:tag('tr')
        titlestyle = '',
         :tag('th')
        image = '',
            :attr('colspan', '2')
        above = '',
            :css('text-align', 'center')
        below = ''
            :css('background-color', '#707ebd')
    }
            :css('color', 'white')
            :wikitext("''[[Bittersweet Candy Bowl]]'' Chapters")
            :done()
        :done()


     -- Add chapters to the appropriate volume groups
     -- Add volume groups and lists
     for _, volume in ipairs(volumes) do
     for _, volume in ipairs(volumes) do
         navbox:tag('tr')
         navboxParams[volume.group .. 'style'] = volume.style
            :tag('th')
        navboxParams[volume.group] = volume.name
                :attr('colspan', '2')
                :css('background-color', volume.style:match('background:[^;]+'))
                :css('color', volume.style:match('color:[^;]+'))
                :wikitext(volume.name)
                :done()
            :done()


         local list = {}
         local list = {}
         for _, chapter in ipairs(chapters) do
         for _, chapter in ipairs(chapters) do
             if isChapterInVolume(chapter.number, volume.start, volume.end_) then
             if isChapterInVolume(chapter.number, volume.start, volume.end_) then
                 table.insert(list, '[[' .. chapter.title .. ']]')
                 table.insert(list, '* [[' .. chapter.title .. ']]')
             end
             end
         end
         end
         if #list > 0 then
         navboxParams[volume.list] = table.concat(list, '\n')
            navbox:tag('tr')
                :tag('td')
                    :attr('colspan', '2')
                    :css('text-align', 'left')
                    :wikitext('* ' .. table.concat(list, ' · '))
                    :done()
                :done()
        end
     end
     end


     -- Add group for chapters not in print
     -- Add group for chapters not in print without a style
     navbox:tag('tr')
     navboxParams['group8'] = 'Not yet in print'
        :tag('th')
            :attr('colspan', '2')
            :css('background-color', '#707ebd')
            :css('color', 'white')
            :wikitext('Chapters Not Yet in Print')
            :done()
        :done()


     local list_not_in_print = {}
     local list_not_in_print = {}
Line 121: Line 123:


         if not in_volume then
         if not in_volume then
             table.insert(list_not_in_print, '[[' .. chapter.title .. ']]')
             table.insert(list_not_in_print, '* [[' .. chapter.title .. ']]')
         end
         end
     end
     end
     if #list_not_in_print > 0 then
     navboxParams['list8'] = table.concat(list_not_in_print, '\n')
        navbox:tag('tr')
 
            :tag('td')
    -- Add manual group for book-exclusive chapters
                :attr('colspan', '2')
    navboxParams['group9'] = 'Book-exclusive'
                :css('text-align', 'left')
    local book_exclusive_list = {}
                :wikitext('* ' .. table.concat(list_not_in_print, ' · '))
    for _, chapter in ipairs(bookExclusiveChapters) do
                :done()
        table.insert(book_exclusive_list, '* [[' .. chapter.link .. '|' .. chapter.title .. ']]')
            :done()
     end
     end
    navboxParams['list9'] = table.concat(book_exclusive_list, '\n')
    -- Add "Obsolete" section
    navboxParams['group10'] = 'Obsolete'
    navboxParams['list10'] = '* [[List of obsolete chapters]]'


     return tostring(navbox)
     return frame:expandTemplate{ title = 'Navbox', args = navboxParams }
end
end


return p
return p

Latest revision as of 06:53, 20 November 2024

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

local p = {}

-- Define the volume ranges and styles
local volumes = {
    {
        name = 'Volume One',
        start = 1,
        end_ = 46,
        style = 'background:#707ebd;color:white;',
        group = 'group1',
        list = 'list1',
    },
    {
        name = 'Volume Two',
        start = 47,
        end_ = 58,
        style = 'background:#912f28;color:white;',
        group = 'group2',
        list = 'list2',
    },
    {
        name = 'Volume Three',
        start = 59,
        end_ = 69.1,
        style = 'background:#2b8842;color:white;',
        group = 'group3',
        list = 'list3',
    },
    {
        name = 'Volume Four',
        start = 70,
        end_ = 80,
        style = 'background:#4589c8;color:white;',
        group = 'group4',
        list = 'list4',
    },
    {
        name = 'Volume Five',
        start = 81,
        end_ = 88,
        style = 'background:#aa715e;color:white;',
        group = 'group5',
        list = 'list5',
    },
    {
        name = 'Volume Six',
        start = 89,
        end_ = 96.1,
        style = 'background:#f27191;color:white;',
        group = 'group6',
        list = 'list6',
    },
    {
        name = 'Volume Seven',
        start = 97,
        end_ = 110,
        style = 'background:#efb63b;color:white;',
        group = 'group7',
        list = 'list7',
    },
}

-- Manually defined book-exclusive chapters
local bookExclusiveChapters = {
    {title = "Curtain Rising", link = "Curtain_Rising"},
    {title = "No Service", link = "No_Service"},
    {title = "Critical Eye", link = "Critical_Eye"},
    {title = "Payback", link = "Payback"},
    {title = "Fashion Disaster", link = "Fashion_Disaster"},
    {title = "There’s a Chance", link = "There’s_a_Chance"},
    {title = "Afterglow", link = "Afterglow"},
    {title = "Unpacking Day", link = "Unpacking_Day"},
    {title = "Good Egg", link = "Good_Egg"},
}

-- Function to check if a chapter is within a volume range
local function isChapterInVolume(chapter_no, start, end_)
    local number = tonumber(chapter_no)
    return number and number >= start and number <= end_
end

function p.generateNavbox(frame)
    local chaptersModule = require('Module:Chapters')
    local chapters = chaptersModule.getChaptersList()

    local navboxParams = {
        bodyclass = 'hlist',
        name = 'Bittersweet Candy Bowl chapters',
        title = "[[Bittersweet Candy Bowl]] chapters",
        titlestyle = '',
        image = '',
        above = '',
        below = ''
    }

    -- Add volume groups and lists
    for _, volume in ipairs(volumes) do
        navboxParams[volume.group .. 'style'] = volume.style
        navboxParams[volume.group] = volume.name

        local list = {}
        for _, chapter in ipairs(chapters) do
            if isChapterInVolume(chapter.number, volume.start, volume.end_) then
                table.insert(list, '* [[' .. chapter.title .. ']]')
            end
        end
        navboxParams[volume.list] = table.concat(list, '\n')
    end

    -- Add group for chapters not in print without a style
    navboxParams['group8'] = 'Not yet in print'

    local list_not_in_print = {}
    for _, chapter in ipairs(chapters) do
        local number = tonumber(chapter.number)
        local in_volume = false
        for _, volume in ipairs(volumes) do
            if isChapterInVolume(chapter.number, volume.start, volume.end_) then
                in_volume = true
                break
            end
        end

        if not in_volume then
            table.insert(list_not_in_print, '* [[' .. chapter.title .. ']]')
        end
    end
    navboxParams['list8'] = table.concat(list_not_in_print, '\n')

    -- Add manual group for book-exclusive chapters
    navboxParams['group9'] = 'Book-exclusive'
    local book_exclusive_list = {}
    for _, chapter in ipairs(bookExclusiveChapters) do
        table.insert(book_exclusive_list, '* [[' .. chapter.link .. '|' .. chapter.title .. ']]')
    end
    navboxParams['list9'] = table.concat(book_exclusive_list, '\n')

    -- Add "Obsolete" section
    navboxParams['group10'] = 'Obsolete'
    navboxParams['list10'] = '* [[List of obsolete chapters]]'

    return frame:expandTemplate{ title = 'Navbox', args = navboxParams }
end

return p