Module:GetRels

From Bodhicitta
Revision as of 17:31, 3 July 2024 by Jeremi (talk | contribs) ((by SublimeText.Mediawiker))

Documentation for this module may be created at Module:GetRels/doc

local p = {}

function p.main(frame)

	local pagename = mw.title.getCurrentTitle().subpageText
    local pagenameEnc = mw.uri.anchorEncode( pagename )
	local pdata = mw.loadData('Module:GetData/relationships')
	local pargs = frame:getParent().args
	if not pdata then
		return 'No relationships!'
	else
		local output = '<h1>Relationships</h1><table class="smwtable-clean th-top-right th-nowrap border w-100">'

		if type(pdata) == "table" then
		    for _, data in ipairs( pdata ) do
		    	local relatedString = ''
		    	local wikipage = frame:preprocess( '{{PAGENAME:' .. data.wikipage .. '}}' )
		    	local wikipageEnc = mw.uri.anchorEncode( wikipage )

		    	if wikipageEnc == pagenameEnc then
					for relatedTo in string.gmatch(data.RelatedTo, "([^;]+)") do
						relatedString = relatedString .. '<div>[[' .. relatedTo .. ']]</div>'
					end
		    		output = output .. '<tr><td class="font-weight-bold text-right nowrap">' .. data.Relationship .. '</td><td><i class="fa-duotone fa-arrow-right" style="color: blue;"></i></td><td>' .. relatedString .. '</td></tr>'
		    	else
		    		output = output .. '<tr><td class="text-right nowrap"><b>' .. data.Relationship .. '</b> <i>this work</i></td><td><i class="fa-duotone fa-arrow-left" style="color: green;"></i></td><td>[[' .. wikipage .. ']]</td></tr>'
		    	end
		    end
		end

		output = output .. '</table>'

		return output
	end
end

return p