Module:ChapterNavbox: Difference between revisions
No edit summary |
No edit summary |
||
Line 67: | Line 67: | ||
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 | local navboxParams = { | ||
bodyclass = 'hlist', | |||
name = 'BCB chapters', | |||
title = "''[[Bittersweet Candy Bowl]]'' Chapters", | |||
titlestyle = '', | |||
image = '', | |||
above = '', | |||
' | below = '' | ||
} | } | ||
-- Add volume groups and lists | -- Add volume groups and lists | ||
for _, volume in ipairs(volumes) do | for _, volume in ipairs(volumes) do | ||
navboxParams[volume.group .. 'style'] = volume.style | |||
navboxParams[volume.group] = volume.name | |||
local list = {} | local list = {} | ||
Line 92: | Line 92: | ||
end | end | ||
end | end | ||
navboxParams[volume.list] = table.concat(list, '\n') | |||
end | end | ||
-- Add group for chapters not in print | -- Add group for chapters not in print | ||
navboxParams['group8style'] = 'background:#707ebd;color:white;' | |||
navboxParams['group8'] = 'Chapters Not Yet in Print' | |||
local list_not_in_print = {} | local list_not_in_print = {} | ||
Line 114: | Line 114: | ||
end | end | ||
end | end | ||
navboxParams['list8'] = table.concat(list_not_in_print, '\n') | |||
return frame:expandTemplate{ title = 'Navbox', args = navboxParams } | |||
end | end | ||
return p | return p |
Revision as of 10:34, 26 May 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',
},
}
-- 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 = 'BCB 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
navboxParams['group8style'] = 'background:#707ebd;color:white;'
navboxParams['group8'] = 'Chapters 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')
return frame:expandTemplate{ title = 'Navbox', args = navboxParams }
end
return p