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: Difference between revisions

From Wings of Fire Wiki
Create module for chapter infobox
 
Oops that function I commented actually needs to be uncommented
Line 108: Line 108:
end  
end  


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


-- if bookData then  
if bookData then  
-- local result = ''
local result = ''
-- local pre = ''
local pre = ''
-- --[[
--[[
-- Check if text prefix is required. If there is a text/number result  
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
then use this else check if the dataset has a defined prefix
-- if no defined prefix assume "Chapter"
if no defined prefix assume "Chapter"
-- ]]
]]
-- if prefix then
if prefix then
-- if prefix ~= true then
if prefix ~= true then
-- pre = prefix
pre = prefix
-- elseif bookData.prefix then
elseif bookData.prefix then
-- pre = bookData.prefix
pre = bookData.prefix
-- else
else
-- pre = "Chapter "
pre = "Chapter "
-- end
end
-- end
end
-- --[[
--[[
-- Define the subpage prefix. If there is a text/number result  
Define the subpage prefix. If there is a text/number result  
-- then use this else check if the dataset has a defined prefix
then use this else check if the dataset has a defined prefix
-- if no defined prefix assume "Chapter"
if no defined prefix assume "Chapter"
-- ]]
]]
-- bookPre = '/Chapter '
bookPre = '/Chapter '
-- if bookData.prefix then
if bookData.prefix then
-- bookPre = '/' .. bookData.prefix .. ' '
bookPre = '/' .. bookData.prefix .. ' '
-- end
end
--     if bookData.prologue then
     if bookData.prologue then
--         result = util.validLink( title .. '/Prologue', 'Prologue')
         result = '[[' .. title .. '/Prologue|Prologue]]'
--     end
     end
-- i = 1
i = 1
-- if bookData.chapterCount then
if bookData.chapterCount then
--     while i <= bookData.chapterCount do
     while i <= bookData.chapterCount do
--         link = util.validLink(title .. bookPre .. i, pre .. i)
         link = util.validLink(title .. bookPre .. i, pre .. i)
--         if result ~= '' then
        if result ~= '' then
--             result = result .. " • "
             result = result .. " • "
--         end
         end
--         result = result .. link
         result = result .. link
--         i = i + 1
         i = i + 1
--     end
     end
-- end
end
-- if bookData.chapters then
if bookData.chapters then
-- for k,v in ipairs(bookData.chapters) do
for k,v in ipairs(bookData.chapters) do
-- link = util.validLink(title .. '/' .. v, v)
link = '[[' .. title .. '/' .. v .. '|' .. v .. ']]'
--         if result ~= '' then
        if result ~= '' then
--             result = result .. " • "
             result = result .. " • "
--         end
         end
--         result = result .. link
         result = result .. link
-- end
end
-- end
end
--     if bookData.epilogue then
     if bookData.epilogue then
--         link = util.validLink(title ..  '/Epilogue', 'Epilogue')
         link = '[[' .. title ..  '/Epilogue|Epilogue]]'
--         result = result .. " • " .. link
         result = result .. " • " .. link
--     end
     end
-- if bookData.bonusChapter then
if bookData.bonusChapter then
-- link = util.validLink(title ..  '/' .. bookData.bonusChapter , bookData.bonusChapter)
link = '[[' .. title ..  '/' .. bookData.bonusChapter .. '|' .. bookData.bonusChapter ..']]'
--         result = result .. " • " .. link
         result = result .. " • " .. link
-- end
end
-- mw.log(result)
mw.log(result)
--     return result
     return result
-- end
end
-- return 'Not Applicable Yet'
return 'Not Applicable Yet'
-- end  
end  
   
   
return p
return p

Revision as of 06:49, 17 June 2025

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 = '[[' .. 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 = '[[' .. title .. '/' .. v .. '|' .. v .. ']]'
			
	        	if result ~= '' then
    	        	result = result .. " • "
        		end
			
        		result = result .. link
			end
		end
		
    	if bookData.epilogue then
        	link = '[[' .. title ..  '/Epilogue|Epilogue]]'
        	result = result .. " • " .. link
    	end
	
		if bookData.bonusChapter then
			link = '[[' .. 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.