Module:SectionNav: Difference between revisions
From Bodhicitta
(VSCode edit) |
(VSCode edit) |
||
| Line 12: | Line 12: | ||
end | end | ||
local output = ' | local output = '' | ||
for index,section in ipairs(sectionsTb) do | for index,section in ipairs(sectionsTb) do | ||
if section == mw.title.getCurrentTitle().subpageText then | if section == mw.title.getCurrentTitle().subpageText then | ||
if index == 1 then | if index == 1 then | ||
output = output .. '< | output = output .. '<div class="muted font-style-italic">First Section</div>' | ||
else | else | ||
local prevSection = sectionsTb[index-1] | local prevSection = sectionsTb[index-1] | ||
output = output .. '< | output = output .. '<div>[[' .. mw.title.getCurrentTitle().baseText .. '/' .. prevSection .. '|<i class="fa-duotone fa-angles-left"></i> Previous Section]]</div>' | ||
end | end | ||
end | end | ||
end | end | ||
for index,section in ipairs(sectionsTb) do | for index,section in ipairs(sectionsTb) do | ||
if section == mw.title.getCurrentTitle().subpageText then | if section == mw.title.getCurrentTitle().subpageText then | ||
if index == #sectionsTb then | if index == #sectionsTb then | ||
output = output .. '< | output = output .. '<div class="muted font-style-italic">Last Section</div>' | ||
else | else | ||
local nextSection = sectionsTb[index+1] | local nextSection = sectionsTb[index+1] | ||
output = output .. '< | output = output .. '<div>[[' .. mw.title.getCurrentTitle().baseText .. '/' .. nextSection .. '|Next Section <i class="fa-duotone fa-angles-right"></i>]]</div>' | ||
end | end | ||
end | end | ||
end | end | ||
return output | return output | ||
Revision as of 18:34, 6 March 2026
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]
if sections == nil or sections == '' then return '' end
local sectionsTb = {}
for section in string.gmatch(sections, "([^;]+)") do
table.insert(sectionsTb, section)
end
local output = ''
for index,section in ipairs(sectionsTb) do
if section == mw.title.getCurrentTitle().subpageText then
if index == 1 then
output = output .. '<div class="muted font-style-italic">First Section</div>'
else
local prevSection = sectionsTb[index-1]
output = output .. '<div>[[' .. mw.title.getCurrentTitle().baseText .. '/' .. prevSection .. '|<i class="fa-duotone fa-angles-left"></i> Previous Section]]</div>'
end
end
end
for index,section in ipairs(sectionsTb) do
if section == mw.title.getCurrentTitle().subpageText then
if index == #sectionsTb then
output = output .. '<div class="muted font-style-italic">Last Section</div>'
else
local nextSection = sectionsTb[index+1]
output = output .. '<div>[[' .. mw.title.getCurrentTitle().baseText .. '/' .. nextSection .. '|Next Section <i class="fa-duotone fa-angles-right"></i>]]</div>'
end
end
end
return output
end
return p