Module:SectionNav: Difference between revisions

From Bodhicitta
((by SublimeText.Mediawiker))
((by SublimeText.Mediawiker))
Line 19: Line 19:
        else
        else
        local prevSection = sectionsTb[index-1]
        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>'
        output = output .. '<span>[[' .. mw.title.getCurrentTitle().baseText .. '/' .. prevSection .. '|<i class="fa-duotone fa-angles-left"></i> Previous Section]]</span>'
        end
        end
    end
    end

Revision as of 10:13, 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>[[' .. mw.title.getCurrentTitle().baseText .. '/' .. prevSection .. '|<i class="fa-duotone fa-angles-left"></i> Previous Section]]</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>'
	        else
	        	local nextSection = sectionsTb[index+1]
	        	output = output .. '<span>[[' .. mw.title.getCurrentTitle().baseText .. '/' .. nextSection .. '|Next Section <i class="fa-duotone fa-angles-right"></i>]]</span>'
	        end
        end
    end

    output = output .. '</div>'

	return output

end

return p