Documentation for this module may be created at Module:Chapterlist/doc
local p = {}
--[[
For use on books that use "Chapter #" as their chapter format.
* The first parameter is the title of the book's page.
* The second parameter is the number of chapters in the book (not counting the prologue, epilogue, or any other bonus chapters)
* The third parameter is optional, and should be "true" (case insensitive) if there is a prologue for the book. Any other value will be interpretted as "false".
*The fourth parameter is optional, and is for an additional chapter at the end of the book that doesn't follow the standard naming conventions (e.g. epilogue or bonus scene). The value should be the title of the chapter.
]]--
function p.num(frame)
return chapters(frame, "Chapter ")
end
--[[
Same as p.num, except the format is "Part #" instead of "Chapter #"
]]--
function p.part(frame)
return chapters(frame, "Part ")
end
--[[
Same as p.num, except it uses chapter numbers only, without "Chapter " at the beginning
]]--
function p.numOnly(frame)
return chapters(frame, "")
end
--[[
For use on books that do not follow the standard numbered chapter format, and instead use a unique name for each chapter.
* The first parameter is the title of the book's page.
* All the following parameters are the chapter titles. There can be an unlimited number of these added.
]]--
function p.name(frame)
local args = frame.args
local result = ""
for i, val in ipairs(args) do
if i > 1 then
local link = "[[" .. args[1] .. "/" .. val .. "|" .. val .. "]]"
if i > 2 then
result = result .. " • "
end
result = result .. link
end
end
return result
end
function chapters(frame, chaptertype)
local args = frame.args
local result = ""
local i = 1
local includesPrologue = "false"
local link = ""
if args[3] ~= nil then
includesPrologue = string.lower(args[3])
end
if includesPrologue == "true" then
result = "[[" .. args[1] .. "/Prologue|Prologue]]"
end
while i <= tonumber(args[2]) do
link = "[[" .. args[1] .. "/" .. chaptertype .. i .. "|" .. chaptertype .. i .. "]]"
if i > 1 or includesPrologue == "true" then
result = result .. " • "
end
result = result .. link
i = i + 1
end
if args[4] ~= nil then
link = "[[" .. args[1] .. "/" .. args[4] .. "|" .. args[4] .. "]]"
result = result .. " • " .. link
end
return result
end
return p