Content added Content deleted
(Created page with "local mod = {} ---@return string function mod.prev_chapter(frame) local args = frame.args local parent = frame:getParent() local pargs={} if parent then pargs=parent.args end local num = args[1] or pargs[1] or 0 if num - 1 <= 0 then return "N/A" else return frame:expandTemplate{title = "Which Chapter", args = {tostring(num - 1)}} end end ---@return string function mod.next_chapter(frame) local args = frame.args lo...") |
mNo edit summary |
||
Line 1: | Line 1: | ||
local wc = require("Module:Which_Chapter") |
|||
local mod = {} |
local mod = {} |
||
Line 11: | Line 13: | ||
return "N/A" |
return "N/A" |
||
else |
else |
||
frame.args[1] = num - 1 |
|||
return wc.where_chapter(frame) |
|||
end |
end |
||
end |
end |
||
Line 22: | Line 25: | ||
if parent then pargs=parent.args end |
if parent then pargs=parent.args end |
||
local num = args[1] or pargs[1] or 0 |
local num = args[1] or pargs[1] or 0 |
||
frame.args[1] = num + 1 |
|||
return wc.where_chapter(frame) |
|||
end |
end |
||
Revision as of 21:28, May 13, 2024
For Previous Chapter:
num must be the current chapter number, this removes the need for all the #expr
calls
{{#invoke:Chapter Infobox|prev_chapter|num}}
For Next Chapter:
num must be the current chapter number, this removes the need for all the #expr
calls
{{#invoke:Chapter Infobox|next_chapter|num}}
Code uses/calls Module:Which_Chapter
local wc = require("Module:Which_Chapter")
local mod = {}
---@return string
function mod.prev_chapter(frame)
local args = frame.args
local parent = frame:getParent()
local pargs={}
if parent then pargs=parent.args end
local num = args[1] or pargs[1] or 0
if num - 1 <= 0 then
return "N/A"
else
frame.args[1] = num - 1
return wc.where_chapter(frame)
end
end
---@return string
function mod.next_chapter(frame)
local args = frame.args
local parent = frame:getParent()
local pargs={}
if parent then pargs=parent.args end
local num = args[1] or pargs[1] or 0
frame.args[1] = num + 1
return wc.where_chapter(frame)
end
return mod