Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Chapterlist

From Wings of Fire Wiki
Revision as of 05:49, 17 June 2025 by Bog (talk | contribs) (Create module for chapter infobox)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}
local books = mw.loadData('Module:Chapterlist/data')
-- local util = require('Module:Utilities') -- does not exist
local a = require('Module:Arguments')

--[[
    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 should be "true" (case insensitive) if there is a prologue for the book. Any other value will be interpretted as "false".
    
    * The fifth 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. post-epilogue). The value should be the title of the chapter.
]]--
function p.num(frame)
	local args = a.getArgs(frame)
    return newChapters(true, args[1])
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()
    return newChapters()
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 includesEpilogue = "false"
    local link = ""
 
    if args[3] ~= nil then
        includesPrologue = string.lower(args[3])
    end
    
    if args[4] ~= nil then
        includesEpilogue = string.lower(args[4])
    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 includesPrologue == "true" then
    	link = "[[" .. args[1] .. "/Epilogue|Epilogue]]"
        result = result .. " • " .. link
    end
    
    if args[5] ~= nil then
        link = "[[" .. args[1] .. "/" .. args[5] .. "|" .. args[5] .. "]]"
    
            result = result .. " • " .. link
    end
 
    return result
end 

-- -- Sakaratte 26 Mar 2025: added parameter so if title is not provided fallback to pagename
-- function newChapters(prefix, title)
--     local link = ""
--     title = title or mw.title.getCurrentTitle().baseText
-- 	local bookData =books[title]

-- 	if bookData then 
-- 		local result = ''
-- 		local pre = ''
		
-- 		--[[
-- 			Check if text prefix is required. If there is a text/number result 
-- 			then use this else check if the dataset has a defined prefix
-- 			if no defined prefix assume "Chapter"
-- 		]]
-- 		if prefix then
-- 			if prefix ~= true then
-- 				pre = prefix
-- 			elseif bookData.prefix then
-- 				pre = bookData.prefix
-- 			else
-- 				pre = "Chapter "
-- 			end
-- 		end
		
-- 		--[[
-- 			Define the subpage prefix. If there is a text/number result 
-- 			then use this else check if the dataset has a defined prefix
-- 			if no defined prefix assume "Chapter"
-- 		]]
-- 		bookPre = '/Chapter '
-- 		if bookData.prefix then
-- 			bookPre = '/' .. bookData.prefix .. ' '
-- 		end
--     	if bookData.prologue then
--         	result = util.validLink( title .. '/Prologue', 'Prologue')
--     	end
		
-- 		i = 1
-- 		if bookData.chapterCount then
--     		while i <= bookData.chapterCount do
--         		link = util.validLink(title .. bookPre .. i, pre .. i)
			
-- 	        	if result ~= '' then
--     	        	result = result .. " • "
--         		end
			
--         		result = result .. link
--         		i = i + 1
--     		end
-- 		end
		
-- 		if bookData.chapters then
-- 			for k,v in ipairs(bookData.chapters) do
-- 				link = util.validLink(title .. '/' .. v, v)
			
-- 	        	if result ~= '' then
--     	        	result = result .. " • "
--         		end
			
--         		result = result .. link
-- 			end
-- 		end
		
--     	if bookData.epilogue then
--         	link = util.validLink(title ..  '/Epilogue', 'Epilogue')
--         	result = result .. " • " .. link
--     	end
	
-- 		if bookData.bonusChapter then
-- 			link = util.validLink(title ..  '/' .. bookData.bonusChapter , bookData.bonusChapter)
--         	result = result .. " • " .. link
-- 		end
-- 		mw.log(result)
--     	return result
-- 	end
-- 	return 'Not Applicable Yet'
-- end 
 
return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.