Module:SectionNav: Difference between revisions
From Bodhicitta
(VSCode edit) |
(VSCode edit) |
||
| (6 intermediate revisions by the same user not shown) | |||
| Line 4: | Line 4: | ||
local pArgs = frame:getParent().args | local pArgs = frame:getParent().args | ||
local sections = pArgs[ | local sections = pArgs[2] | ||
if sections == nil or sections == '' then return '' end | if sections == nil or sections == '' then return '' end | ||
local sectionsTb = {} | local sectionsTb = {} | ||
for section in string.gmatch(sections, "([^;]+)") do | for section in string.gmatch(sections, "([^;]+)") do | ||
table.insert(sectionsTb, section) | table.insert(sectionsTb, mw.text.trim(section)) | ||
end | end | ||
local output = '' | if tostring(#sectionsTb) == '1' then return '' end | ||
local output = '<div class="mb-4 text-center">' | |||
for index,section in ipairs(sectionsTb) do | for index,section in ipairs(sectionsTb) do | ||
| Line 34: | Line 36: | ||
end | end | ||
end | end | ||
output = output .. '</div>' | |||
return output | return output | ||
Latest revision as of 13:55, 18 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[2]
if sections == nil or sections == '' then return '' end
local sectionsTb = {}
for section in string.gmatch(sections, "([^;]+)") do
table.insert(sectionsTb, mw.text.trim(section))
end
if tostring(#sectionsTb) == '1' then return '' end
local output = '<div class="mb-4 text-center">'
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 my-1 text-110">First Section</div>'
else
local prevSection = sectionsTb[index-1]
output = output .. '<div class="my-1 text-110">[[' .. mw.title.getCurrentTitle().baseText .. '/' .. prevSection .. '|Previous Section <i class="fa-sharp-duotone fa-solid fa-arrow-u-turn-up-left"></i>]]</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 my-1 text-110">Last Section</div>'
else
local nextSection = sectionsTb[index+1]
output = output .. '<div class="my-1 text-110">[[' .. mw.title.getCurrentTitle().baseText .. '/' .. nextSection .. '|Next Section <i class="fa-sharp-duotone fa-solid fa-arrow-right-long"></i>]]</div>'
end
end
end
output = output .. '</div>'
return output
end
return p