Module:Navbox
Documentation for this module may be created at Module:Navbox/doc
-- <nowiki>
-- Written by [[User:KockaAdmiralac]]
local p = require('Module:PortableNavbox')
-- Specifically made for Heartbound Wiki
local data = require('Module:Navbox/Data')
local arg = 112
function find_chapter(chapter)
for k1, v1 in ipairs(data) do
for k2, v2 in ipairs(v1) do
if chapter == v2 then
return k1, k2
end
end
end
return 0, 0
end
function p.arg(frame)
local title = mw.title.getCurrentTitle()
if title.namespace ~= arg then
-- Not in ARG namespace
return ''
end
-- Generating left/right links
local left = ''
local lefttext = ''
local right = ''
local righttext = ''
local m1 = tonumber(title.text:match('^Phase (%d) Overview$'))
local m2 = tonumber(title.text:match('^Phase (%d) Summary$'))
if m1 then
-- Overview page
phase = m1
chapter = -2
if data[phase - 1] then
left = 'Phase ' .. (phase - 1) .. ' Overview'
lefttext = 'Previous Phase'
end
elseif m2 then
-- Summary page
phase = m2
chapter = -1
if data[phase + 1] then
right = 'Phase ' .. (phase + 1) .. ' Overview'
righttext = 'Next Phase'
end
else
-- Chapter page
phase, chapter = find_chapter(title.text)
if phase == 0 or chapter == 0 then
return ''
end
end
if left:len() == 0 then
left = 'Phase ' .. phase .. ' Overview'
lefttext = 'Overview'
end
if right:len() == 0 then
right = 'Phase ' .. phase .. ' Summary'
righttext = 'Summary'
end
-- Generating previous/next chapter links
local prev = data[phase][chapter - 1] or ''
local next = data[phase][chapter + 1] or ''
-- Generating header
local header = 'Phase ' .. phase
if data[phase - 1] then
header = '[[File:Heart asset left.png|link={{ns:' .. arg .. '}}:Phase ' .. (phase - 1) .. ' Overview]]' .. header
end
if data[phase + 1] then
header = header .. '[[File:Heart asset right.png|link={{ns:' .. arg .. '}}:Phase ' .. (phase + 1) .. ' Overview]]'
end
-- Generating categories
local categories = '[[Category:ARG:Phase' .. phase .. ']]'
if chapter < 0 then
categories = '[[Category:ARG]]' .. categories
end
return frame:expandTemplate{
title = 'Navbox ARG/base',
args = {
title = header,
left = left,
lefttext = lefttext,
right = right,
righttext = righttext,
next = next,
prev = prev
}
} .. categories
end
return p