Module:SectionNav: Difference between revisions

From Bodhicitta
(VSCode edit)
(VSCode edit)
Line 14: Line 14:
if tostring(#sectionsTb) == '1' then return '' end
if tostring(#sectionsTb) == '1' then return '' end


local output = ''
local output = '<div class="mb-4">'


     for index,section in ipairs(sectionsTb) do
     for index,section in ipairs(sectionsTb) do
Line 36: Line 36:
         end
         end
     end
     end
output = output .. '</div>'


return output
return output

Revision as of 13:54, 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">'

    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