Module:SectionNav: Difference between revisions
From Bodhicitta
((by SublimeText.Mediawiker)) |
((by SublimeText.Mediawiker)) |
||
| Line 14: | Line 14: | ||
for index,section in ipairs(sectionsTb) do | for index,section in ipairs(sectionsTb) do | ||
if section == mw.title.getCurrentTitle().subpageText then | |||
if index == 1 then | |||
output = output .. '<span class="muted font-style-italic">First Section</span>' | |||
else | |||
local prevSection = sectionsTb[index-1] | |||
output = output .. '<span><a href="/index.php/' .. mw.title.getCurrentTitle().baseText .. '/' .. prevSection .. '" title="' .. mw.title.getCurrentTitle().baseText .. '/' .. prevSection .. '"><i class="fa-duotone fa-angles-left"></i> Previous Section</a></span>' | |||
end | |||
end | |||
end | end | ||
output = output .. ' | ' | output = output .. ' | ' | ||
for index,section in ipairs(sectionsTb) do | for index,section in ipairs(sectionsTb) do | ||
if section == mw.title.getCurrentTitle().subpageText then | |||
if index == #sectionsTb then | |||
output = output .. '<span class="muted font-style-italic">Last Section</span>' | |||
elseif section == mw.title.getCurrentTitle().subpageText then | |||
local nextSection = sectionsTb[index+1] | |||
output = output .. '<span><a href="/index.php/' .. mw.title.getCurrentTitle().baseText .. '/' .. nextSection .. '" title="' .. mw.title.getCurrentTitle().baseText .. '/' .. nextSection .. '">Next Section <i class="fa-duotone fa-angles-right"></i></a></span>' | |||
end | |||
end | end | ||
end | end | ||
Revision as of 10:12, 7 December 2023
Documentation for this module may be created at Module:SectionNav/doc
local p = {}
function p.main(frame)
local pArgs = frame:getParent().args
local sections = pArgs[1]
local sectionsTb = {}
for section in string.gmatch(sections, "([^;]+)") do
table.insert(sectionsTb, section)
end
local output = '<div class="text-center">'
for index,section in ipairs(sectionsTb) do
if section == mw.title.getCurrentTitle().subpageText then
if index == 1 then
output = output .. '<span class="muted font-style-italic">First Section</span>'
else
local prevSection = sectionsTb[index-1]
output = output .. '<span><a href="/index.php/' .. mw.title.getCurrentTitle().baseText .. '/' .. prevSection .. '" title="' .. mw.title.getCurrentTitle().baseText .. '/' .. prevSection .. '"><i class="fa-duotone fa-angles-left"></i> Previous Section</a></span>'
end
end
end
output = output .. ' | '
for index,section in ipairs(sectionsTb) do
if section == mw.title.getCurrentTitle().subpageText then
if index == #sectionsTb then
output = output .. '<span class="muted font-style-italic">Last Section</span>'
elseif section == mw.title.getCurrentTitle().subpageText then
local nextSection = sectionsTb[index+1]
output = output .. '<span><a href="/index.php/' .. mw.title.getCurrentTitle().baseText .. '/' .. nextSection .. '" title="' .. mw.title.getCurrentTitle().baseText .. '/' .. nextSection .. '">Next Section <i class="fa-duotone fa-angles-right"></i></a></span>'
end
end
end
output = output .. '</div>'
return output
end
return p